Implement simplify (using geopandas)

Add preserve_geometry option
This commit is contained in:
phil 2024-01-07 18:30:25 +05:30
parent e3ed311390
commit c3caedea0e
6 changed files with 93 additions and 66 deletions

View file

@ -218,7 +218,8 @@ class SurveyModel(BaseSurveyModel):
'] #' + df.index.astype('U')
@classmethod
async def get_geojson(cls, registry=None, simplify_tolerance=0):
async def get_geojson(cls,
registry=None, simplify_tolerance=0, preserve_topology=False):
if registry is None:
from ..registry import registry
@ -489,8 +490,9 @@ class GeoModelNoStatus(Model):
shapely_geom = self.shapely_geom
if simplify_tolerance:
shapely_geom = shapely_geom.simplify(simplify_tolerance / conf.geo.simplify_geom_factor,
preserve_topology=False)
shapely_geom = shapely_geom.simplify(
simplify_tolerance / conf.geo.simplify_geom_factor,
preserve_topology=conf.geo.simplify_preserve_topology)
if shapely_geom.is_empty:
raise NoPoint
@ -744,11 +746,12 @@ class GeoModelNoStatus(Model):
# )
# if hasattr(cls, 'simplify') and cls.simplify:
# #shapely_geom = shapely_geom.simplify(simplify_tolerance / conf.geo.simplify_geom_factor,
# #preserve_topology=False)
# #shapely_geom = shapely_geom.simplify(
# simplify_tolerance / conf.geo.simplify_geom_factor,
# preserve_topology=conf.geo.simplify_preserve_topology)
# gdf['geometry'] = gdf['geometry'].simplify(
# float(cls.simplify) / conf.geo.simplify_geom_factor,
# preserve_topology=False)
# preserve_topology=conf.geo.simplify_preserve_topology)
# if reproject:
# gdf.to_crs(crs=conf.crs.for_proj, inplace=True)