Export#

Since the profile and trench_depth_profile are list of tuples, they cannot be exported to a shapefile or GeoPackage directly using the native GeoPandas function (to_file). This module contains functions to convert the list of tuples to JSON strings, which can then be exported to a shapefile or GeoPackage. The option saving the data as a parquet file is added.

pysewer.export.map_dtype_to_fiona(dtype)[source]#

Map pandas data type to Fiona/OGR data type.

pysewer.export.is_list_of_tuples(column)[source]#

Check if a pandas Series contains lists of tuples.

pysewer.export.is_list(column)[source]#

Check if a pandas Series contains lists.

pysewer.export.tuple_list_to_json(tuple_list)[source]#

Serialize a list of tuples to a JSON string.

pysewer.export.generate_schema(gdf: GeoDataFrame)[source]#

Generate a schema based on the GeoDataFrame.

Parameters:

gdf (gpd.GeoDataFrame) – The GeoDataFrame to generate the schema from.

Returns:

The schema dictionary.

Return type:

dict

pysewer.export.write_gdf_to_gpkg(gdf: GeoDataFrame, filepath: str, layer: str | None = None, crs: CRS | None = None)[source]#

Write a GeoDataFrame to a GeoPackage (GPKG) file using Fiona, converting lists of tuples to JSON strings.

Parameters:
  • gdf (gpd.GeoDataFrame) – The GeoDataFrame to be written to the GPKG file.

  • filepath (str) – The file path to the GPKG file.

  • layer (str (optional)) – The layer name inside the GPKG file. If no layer name is specified the file name is used.

  • crs (CRS (optional)) – The layer CRS

Return type:

None

Notes

This function converts any columns with list of tuples to JSON strings before writing to the GPKG file.

pysewer.export.write_gdf_to_shp(gdf: GeoDataFrame, filepath: str)[source]#

Write a GeoDataFrame to an ESRI Shapefile (SHP) file using Fiona, converting lists of tuples to JSON strings.

Parameters:
  • gdf (gpd.GeoDataFrame) – The GeoDataFrame to be written to the SHP file.

  • filepath (str) – The file path to save the SHP file.

Return type:

None

Notes

This function converts any columns in the GeoDataFrame that contain lists of tuples to JSON strings before writing to the SHP file.

pysewer.export.export_sewer_network(gdf: GeoDataFrame, filepath: str, file_format: str | None = None)[source]#

Export a sewer network GeoDataFrame to a file.

Parameters:
  • gdf (gpd.GeoDataFrame) – A GeoDataFrame containing the sewer network.

  • filepath (str) – The path to the file to which the sewer network should be exported.

  • file_format (str) – The file format to which the sewer network should be exported. Default is ‘gpkg’ (GeoPackage). Currently supported formats are ‘gpkg’ (GeoPackage), ‘shp’ (ESRI Shapefile) and Geoparquet ‘parquet’.

Raises:

ValueError – If the file format is not supported.

Return type:

None