4
4
5
5
from .const import CORE_COLUMNS
6
6
from .parquet import create_parquet
7
- from .util import load_parquet_data , load_parquet_schema , log , parse_metadata
7
+ from .util import load_parquet_data , load_parquet_schema , log , merge_schemas , parse_metadata , pick_schemas
8
8
from .version import fiboa_version
9
9
10
10
DEFAULT_CRS = "EPSG:4326"
@@ -20,22 +20,27 @@ def merge(datasets, out, crs = DEFAULT_CRS, includes = [], excludes = [], extens
20
20
21
21
# Load the datasets
22
22
all_gdf = []
23
+ custom_schemas = {}
23
24
for dataset in datasets :
24
25
# Load the dataset
25
26
schema = load_parquet_schema (dataset )
27
+ collection = parse_metadata (schema , b"fiboa" )
26
28
file_columns = list (set (columns ) & set (schema .names ))
27
29
gdf = load_parquet_data (dataset , columns = file_columns )
28
30
29
31
# Change the CRS if necessary
30
32
gdf .to_crs (crs = crs , inplace = True )
31
33
32
34
# Add collection column to each dataset
33
- collection = parse_metadata (schema , b"fiboa" )
34
35
if collection is not None and "id" in collection :
35
36
gdf ["collection" ] = collection ["id" ]
36
37
else :
37
38
gdf ["collection" ] = os .path .splitext (os .path .basename (dataset ))[0 ]
38
39
40
+ # Merge custom schemas
41
+ custom_schema = collection .get ("fiboa_custom_schemas" , {})
42
+ custom_schemas = merge_schemas (custom_schemas , custom_schema )
43
+
39
44
all_gdf .append (gdf )
40
45
41
46
merged = pd .concat (all_gdf , ignore_index = True )
@@ -51,6 +56,11 @@ def merge(datasets, out, crs = DEFAULT_CRS, includes = [], excludes = [], extens
51
56
"fiboa_extensions" : extensions ,
52
57
}
53
58
59
+ # Add custom schemas
60
+ custom_schemas = pick_schemas (custom_schemas , columns )
61
+ if len (custom_schemas ) > 0 :
62
+ collection ["fiboa_custom_schemas" ] = custom_schemas
63
+
54
64
# Write the merged dataset to the output file
55
65
create_parquet (merged , columns , collection , out , {}, compression = compression , geoparquet1 = geoparquet1 )
56
66
log (f"Merged data to { out } " , "success" )
0 commit comments