@@ -17,6 +17,7 @@ def register_layers(parquet_file_path: str, project_number: str, gisbase: str):
1717 layers = con .read_parquet (parquet_file_path )
1818
1919 resources = (
20+ # 1. Remove the GISBASE from the file path, trim also eventual " or / from the file string # noqa: E501
2021 layers .select (
2122 * [
2223 duckdb .StarExpression (),
@@ -36,6 +37,7 @@ def register_layers(parquet_file_path: str, project_number: str, gisbase: str):
3637 ).alias ("cleaned_file" ),
3738 ]
3839 )
40+ # 2. extract location, mapset, type and resource from the cleaned filepath
3941 .select (
4042 * [
4143 duckdb .StarExpression (),
@@ -65,6 +67,7 @@ def register_layers(parquet_file_path: str, project_number: str, gisbase: str):
6567 ).alias ("resource" ),
6668 ]
6769 )
70+ # 3. produce something that can be used as dataset_id
6871 .select (
6972 * [
7073 duckdb .StarExpression (),
@@ -84,6 +87,8 @@ def register_layers(parquet_file_path: str, project_number: str, gisbase: str):
8487 )
8588 log .info (datasets )
8689
90+ # version will be based on the date of execution
91+ # since this script cannot be executed in a cron job
8792 version = datetime .datetime .now ().strftime ("%Y%m%d" )
8893
8994 for d in datasets .to_arrow_table ().to_pylist ():
@@ -102,7 +107,13 @@ def register_layers(parquet_file_path: str, project_number: str, gisbase: str):
102107 )
103108
104109 for d in resources .to_arrow_table ().to_pylist ():
110+ # DMS requires a resource URI, but Grass GIS doesn't provide anything like that
111+ # the only valid reference is Grass is mapname@mapset
112+ # the prefix grass: is not a standard
113+ # the query parameters GISBASE and LOCATION_NAME are actually valid env variables for grass gis # noqa: E501
114+ # type is an additional query param to add differentiate between raster and vectors # noqa: E501
105115 uri = f"grass:{ d .get ('resource' )} @{ d .get ('mapset' )} ?GISBASE={ gisbase } &LOCATION_NAME={ d .get ('location' )} &type={ d .get ('type' )} " # noqa: E501
116+ # NOTE: it's necessary to add a type, some resources otherwise have the same name between rasters and vectors # noqa: E501
106117 resource_id = f"{ d .get ('dataset_id' )} -{ d .get ('resource' )} -{ d .get ('type' )} "
107118 metadata = json .loads (d .get ("metadata" ))
108119 dms .upsert_dms_element (
0 commit comments