I would like to be able to extend the vertices of one polygon to the edge of another polygon, how does the snapping between poligons using python.

The photo shows a representation of my problem.

enter image description here

I would like the orange polygon snap the red contour (the other polygon), as in the photo below.

enter image description here

I am using fiona as shown in this example (How to do snapping in Geopandas?), but I couldn't get the result.

from shapely.ops import snap
import geopandas as gpd

border_shp = gpd.read_file(...)
multipolygon = gpd.read_file(...)

for index, row in multipolygon.iterrows():
    closest_geom = list(border_shp ['geometry'])[1]
    snapped_geom = gpd.GeoDataFrame(snap(row['geometry'], closest_geom, 8))

I would be grateful for the help

  • 3
    what if buffer > clip ?
    – Taras
    May 7, 2021 at 9:08
  • 1
    I tried it but it also affects the polygons inside the polygon I am trying to extend, do you know any way around this behaviour?
    – vins_26
    May 7, 2021 at 9:18
  • Do you have one dataframe or two?
    – BERA
    May 7, 2021 at 9:23
  • I have two dataframe multipolygon
    – vins_26
    May 7, 2021 at 9:26
  • 3
    Can't you set the entire geometry of the orange feature to be the geometry of the red feature? Where do you not want the orange feature to relate to the red feature? Only where it is near already? Like a "snap" operation? Can you make a better example showing full polygons?
    – Spacedman
    May 7, 2021 at 9:35


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.