src.utils_flask_sqla_geo.utilsgeometry

Module Contents

Classes

FionaService

Abstract class to provide functions to create geofiles with Fiona

FionaGpkgService

Service to create gpkg from sqlalchemy models

FionaShapeService

Service to create shapefiles from sqlalchemy models

Functions

create_shapes_generic(view, srid, db_cols, data, ...)

Export data in shape files (separated bu geometry type)

create_gpkg_generic(view, srid, db_cols, data, ...)

Export data in gpkg file

export_geodata_as_file(view, srid, db_cols, data, ...)

Generic export data

convert_to_2d(geojson)

Convert a geojson 3d in 2d

remove_third_dimension(geom)

Attributes

FIONA_MAPPING

log

src.utils_flask_sqla_geo.utilsgeometry.FIONA_MAPPING[source]
src.utils_flask_sqla_geo.utilsgeometry.log[source]
class src.utils_flask_sqla_geo.utilsgeometry.FionaService[source]

Bases: abc.ABC

Abstract class to provide functions to create geofiles with Fiona Class who inherite of this class must implement the following abstract methods: - create_fiona_struct - create_features_generic - save-files - close-files

supported_type = ('shp', 'gpkg')[source]
classmethod create_fiona_properties(db_cols, srid, dir_path, file_name, col_mapping=None)[source]

Create three shapefiles (point, line, polygon) with the attributes give by db_cols Parameters:

db_cols (list): columns from a SQLA model (model.__mapper__.c) srid (int): epsg code dir_path (str): directory path file_name (str): file of the shapefiles col_mapping (dict): mapping between SQLA class

attributes and “beatifiul” columns name

Returns:

void

classmethod add_fiona_col_mapping(key, db_col)[source]
classmethod create_features_generic(view, data, geom_col, geojson_col=None)[source]

Create the features of the shapefiles by serializing the datas from a GenericTable (non mapped table)

Parameters:

view (GenericTable): the GenericTable object data (list): Array of SQLA model geom_col (str): name of the WKB geometry column of the SQLA Model geojson_col (str): name of the geojson column if present. If None create the geojson from geom_col with shapely

for performance reason its better to use geojson_col rather than geom_col

Returns:

void

classmethod build_feature(view, data, geo_colname, is_geojson)[source]

Fonction qui créer une feature au sens de fiona

Parameters:

view (GenericTable): the GenericTable object is_geojson (boolean): la geometrie est elle sous forme de geojson data (Model) : SQLA model geo_colname (string) : nom de la colonne contenant le geom

classmethod create_feature(data, geom, is_geojson=False)[source]

Create and write feature (a record of the file) for WKB data by serializing an SQLAlchemy object

Parameters:

data (dict): the SQLAlchemy model serialized as a dict geom (WKB): the geom as WKB

Returns:

void

abstract classmethod create_fiona_struct(db_cols, srid, dir_path, file_name, col_mapping=None)[source]
abstract classmethod write_a_feature(feature, geom_wkt)[source]
abstract classmethod save_files()[source]
abstract classmethod close_files()[source]
class src.utils_flask_sqla_geo.utilsgeometry.FionaGpkgService[source]

Bases: FionaService

Service to create gpkg from sqlalchemy models

How to use: FionaShapeService.create_shapes_struct(**args) FionaShapeService.create_features(**args) FionaShapeService.save_and_zip_shapefiles()

classmethod create_fiona_struct(db_cols, srid, dir_path, file_name, col_mapping=None)[source]
classmethod write_a_feature(feature, geom_wkt)[source]

write a feature by checking the type of the shape given

classmethod save_files()[source]

Save and zip the files Only zip files where there is at least on feature

Returns:

void

classmethod close_files()[source]

Save the files

class src.utils_flask_sqla_geo.utilsgeometry.FionaShapeService[source]

Bases: FionaService

Service to create shapefiles from sqlalchemy models

How to use: FionaShapeService.create_fiona_struct(**args) FionaShapeService.create_features(**args) FionaShapeService.save_files()

create_shapes_struct[source]
save_and_zip_shapefiles[source]
classmethod create_fiona_struct(db_cols, srid, dir_path, file_name, col_mapping=None, encoding='utf-8')[source]

Create three shapefiles (point, line, polygon) with the attributes give by db_cols Parameters:

db_cols (list): columns from a SQLA model (model.__mapper__.c) srid (int): epsg code dir_path (str): directory path file_name (str): file of the shapefiles col_mapping (dict): mapping between SQLA class attributes and “beatifiul” columns name encoding (str): define encoding of data to store in Shape. Default: utf-8.

Returns:

void

classmethod write_a_feature(feature, geom_wkt)[source]

write a feature by checking the type of the shape given

classmethod save_files()[source]

Save and zip the files Only zip files where there is at least on feature

Returns:

void

classmethod close_files()[source]
src.utils_flask_sqla_geo.utilsgeometry.create_shapes_generic(view, srid, db_cols, data, dir_path, file_name, geom_col, geojson_col)[source]

Export data in shape files (separated bu geometry type) Parameters:

srid (int): epsg code db_cols (list): columns from a SQLA model (model.__mapper__.c) data (list): Array of SQLA model dir_path (str): directory path file_name (str): file of the shapefiles geom_col (str): name of the WKB geometry column of the SQLA Model geojson_col (str): name of the geojson column if present. If None create the geojson from geom_col with shapely

for performance reason its better to use geojson_col rather than geom_col

src.utils_flask_sqla_geo.utilsgeometry.create_gpkg_generic(view, srid, db_cols, data, dir_path, file_name, geom_col, geojson_col)[source]

Export data in gpkg file Parameters:

srid (int): epsg code db_cols (list): columns from a SQLA model (model.__mapper__.c) data (list): Array of SQLA model dir_path (str): directory path file_name (str): file of the shapefiles geom_col (str): name of the WKB geometry column of the SQLA Model geojson_col (str): name of the geojson column if present. If None create the geojson from geom_col with shapely

for performance reason its better to use geojson_col rather than geom_col

src.utils_flask_sqla_geo.utilsgeometry.export_geodata_as_file(view, srid, db_cols, data, dir_path, file_name, geom_col, geojson_col, export_format='gpkg')[source]

Generic export data Parameters:

srid (int): epsg code db_cols (list): columns from a SQLA model (model.__mapper__.c) data (list): Array of SQLA model dir_path (str): directory path file_name (str): file of the shapefiles geom_col (str): name of the WKB geometry column of the SQLA Model geojson_col (str): name of the geojson column if present. If None create the geojson from geom_col with shapely

for performance reason its better to use geojson_col rather than geom_col

export_format (str) : name of the exported format

src.utils_flask_sqla_geo.utilsgeometry.convert_to_2d(geojson)[source]

Convert a geojson 3d in 2d

src.utils_flask_sqla_geo.utilsgeometry.remove_third_dimension(geom)[source]