8

The goal is to simplify the geometries of a shapefile containing multipolygons. However, when I use Shapely's simplify in geopandas, the result contains gaps between the polygons. I was hoping that preserve_topology would avoid this? How can I avoid or fix the issue?

gdf_simplified = gdf.copy()
gdf_simplified["geometry"] = gdf.geometry.simplify(tolerance=TOLERANCE,preserve_topology=True)

my geoDataFrame is in in {'init': 'epsg:4326'}and I use a tolerance of 360/43200 which corresponds to 30" degrees (appr. 1 km at the equator).

enter image description here

The old polygons are displayed using the black line. The new resulting polygons are depicted using colors.

For now, I was able to revert to MapShaper and get simplified shapes without the gaps. However, I would prefer a python based approach.

RutgerH
  • 3,285
  • 3
  • 27
  • 55
  • Maybe converting to TopoJSON might help but I've never used that before. – RutgerH Jun 13 '19 at 20:09
  • Preserverve topology does not do that for the whole layer https://gis.stackexchange.com/questions/20799/generalizing-polygon-file-while-maintaining-topology-in-qgis. You need some topology-aware tool for that. – user30184 Jun 13 '19 at 21:09

1 Answers1

8

As mentioned, you need a topology aware simplification algorithm. For this I use the topojson package:

gdf = <geopandas dataframe>

import topojson as tp

topo = tp.Topology(gdf.to_crs({'init':'epsg:3857'}), prequantize=False) simple = topo.toposimplify(1).to_gdf()

optional

simple.plot()

Damien
  • 103
  • 3
user2589273
  • 311
  • 3
  • 6