deseasion.backend.services.geo_data_loading_service module
- deseasion.backend.services.geo_data_loading_service.convert_to_polygon(geom: BaseGeometry) Polygon
Try converting geometry to a polygon.
- Parameters:
geom –
- Raises:
TypeError – if geom cannot be converted to a
shapely.Polygon
- Returns:
result as a polygon
- deseasion.backend.services.geo_data_loading_service.create_extent_filter(extent_filter: BaseGeometry = None)
Create a filter function which returns True if a geometry is filtered out.
- Parameters:
extent_filter – geometry used to filter in geometries, defaults to None
- Returns:
filter boolean function
- deseasion.backend.services.geo_data_loading_service.create_global_data(name, properties: dict[str, Any], **kwargs) GlobalData
Create a global data object.
- Parameters:
name –
properties – set of properties organized by attribute
- Returns:
created global data object
- deseasion.backend.services.geo_data_loading_service.create_value_classes(start: float, stop: float, step: float) list[list[float]]
Create value classes from range.
This is to be used to discretize raster geodata values so to create larger vector features sharing a same value class. Each class is a list with [start_value, stop_value, class_value] (i.e values between start_value and stop_value are replaced by class_value).
- Parameters:
start –
stop –
step –
- Returns:
value classes
- deseasion.backend.services.geo_data_loading_service.get_geo_data_download(data, working_dir, file_ext=None)
Write the geo data to a file-like object.
- deseasion.backend.services.geo_data_loading_service.get_temporary_directory()
Return a TemporaryDirectory object.
If the ‘TEMP_DIR’ defined in the application configuration exists, the TemporaryDirectory object will use this location. Otherwise, use the system temporary directory.
- Returns:
A file object directory which can be used in a context manager and will be deleted on completion of the context.
- deseasion.backend.services.geo_data_loading_service.load_from_geotiff(path, classes, start: float = None, step: float = None, stop: float = None, smooth=False, extent_filter: BaseGeometry = None)
Create a new geo-data from a GeoTiff file.
- Args:
path (str): The path of the GeoTIFF file. classes (list):
The classes of the vector features, a list of (min, max, value).
- start (float):
The starting value for classes creation (if classes not provided).
- step (float):
The step value for classes creation (if classes not provided).
stop (float): The stop value for classes (if classes not provided). smooth (bool):
Whether to smooth the raster using a percentile_filter. Default: False.
- extent_filter (shapely.BaseGeometry):
Geometry filtering in features to keep. Default: None (no filter).
- deseasion.backend.services.geo_data_loading_service.load_from_wfs(wfs_stream: WFSGeoData, old_attributes: list[DataAttribute] = None) list[GeoFeature]
Create and return a GeoData object created from a WFS stream.
Tries to reproject the geometries to EPSG:4326.
- Parameters:
wfs_stream –
- Returns:
geo data version of the wfs_stream stream
- deseasion.backend.services.geo_data_loading_service.load_from_wms(wms_stream: WMSGeoData, classes: list = None, start: float = None, step: float = None, stop: float = None, smooth: bool = False, resolution: float = None, old_attribute: DataAttribute = None) list[GeoFeature]
Create a new geo-data from a WMS url.
- Parameters:
wms_stream – The WMS stream.
classes – The classes of the vector features, a list of (min, max, value).
start – The starting value for classes creation (if classes not provided).
step – The step value for classes creation (if classes not provided).
stop – The stop value for classes (if classes not provided).
smooth – Whether to smooth the raster using a percentile_filter. Default: False.
- deseasion.backend.services.geo_data_loading_service.load_raster_from_files(files, classes: list = None, start: float = None, step: float = None, stop: float = None, extent_filter: BaseGeometry = None)
Create a new vectorized GeoData from a raster file.
- deseasion.backend.services.geo_data_loading_service.load_vector_file(path, extent_filter: BaseGeometry = None)
Create and return a GeoData object created from a vector file.
Tries to reproject the geometries to EPSG:4326.
- deseasion.backend.services.geo_data_loading_service.load_vector_from_files(files, extent_filter: BaseGeometry = None)
Create a new GeoData from a list of files.
Saves the files in a temporary directory and load them as a new GeoData object.
- deseasion.backend.services.geo_data_loading_service.load_wfs(wfs_stream: WFSGeoData) WFSGeoData
Create and return a StreamGeoData object created from a WFS URL.
- Parameters:
wfs_stream – WFS stream to load (can be partial as long as it contains at least the server URL and feature type)
- Raises:
KeyError – if wfs_stream.feature_type is not found on WFS server
- Returns:
Note
WFS object is not persisted!
- deseasion.backend.services.geo_data_loading_service.load_wms(wms_stream: WMSGeoData) WMSGeoData
Create and return a StreamGeoData object created from a WFS URL.
- Parameters:
wms_stream – WMS stream to load (can be partial as long as it contains at least the server URL and layer)
- Raises:
KeyError – if wms_stream.layer is not found on WMS server
- Returns:
Note
WMS object is not persisted!
- deseasion.backend.services.geo_data_loading_service.normalize_geometry(df: GeoDataFrame) GeoDataFrame
Normalize geopandas dataframe geometry type.
If geometry column has more than 1 type, then it is converted to polygons. Otherwise it is not changed.
- Parameters:
df – geopandas dataframe
- Returns:
normalized geopandas dataframe
Warning
Dataframe is modified in place! It is also returned for chainability of methods or functions.
- deseasion.backend.services.geo_data_loading_service.ogr2ogr_reproject(file_in, dir_out)
Reproject the file in WGS84 using ogr2ogr and return the name of the new file.
- Args:
file_in (str): Path of the input shapefile. dir_out (str): Directory to save the reprojected file.
- Returns:
The path of the reprojected file, or None if there was an error.
- deseasion.backend.services.geo_data_loading_service.post_load_normalization(data: BaseGeoData)
Split multi-geometry features of persisted base geo data.
The resulting features are then persisted back to the database.
- Parameters:
data – persisted base geo data object
Warning
This is intended to be used immedialetly after data features creation. Only values and input features are preserved, output features are not!
- deseasion.backend.services.geo_data_loading_service.reclassify(array, classes=None, start=None, step=None, stop=None)
Reclassify the raster values.
- deseasion.backend.services.geo_data_loading_service.save_geo_data(geo_data: BaseGeoData, directory, file_ext=None)
Save a geo data to the directory.
It also adds following metadata as geo data fields: * explainability: feature explainability if any
- Returns:
The name of the new directory.
- deseasion.backend.services.geo_data_loading_service.save_global_data(global_data: GlobalData, directory, file_ext=None)
- deseasion.backend.services.geo_data_loading_service.split_multi_geometry(geom: BaseGeometry) Generator[BaseGeometry, None, None]
Return list of connex geometries forming the geometry.
- Parameters:
geom – a geometry
- Returns:
- deseasion.backend.services.geo_data_loading_service.validate_shp_filenames(filenames)
Validate the file names.
A shapefile data must have at least 3 files with the extensions .shp, .shx and .dbf.
- Raises:
- UploadError:
if a required file (shp, dbf or shx) is missing, or if more than one file is found