[Python] Incorrect leftover point when subtracting overlap between two polygons

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I am identifying polygons that intersect, then computing their intersection and removing it from the first polygon. I get a weird left-over point. If I just take the difference between the polygons this doesn't happen. Why?

    import pandas as pd
    import geopandas as gpd
    import shapely

    test = pd.DataFrame({"geo_uuid": ["a", "b"], "geometry": [shapely.from_wkt("POLYGON ((-85.489530540446 40.72197039620563, -85.54038813980434 40.686016211216575, -85.42963027177998 40.682309666676865, -85.489530540446 40.72197039620563))"),
    shapely.from_wkt("POLYGON ((-85.52717584228726 40.732495186799525, -85.49542480146151 40.693215026642285, -85.44637022730953 40.73203119983377, -85.52717584228726 40.732495186799525))")]})

    test = gpd.GeoDataFrame(test).set_geometry("geometry").set_crs(epsg=4326)

    geo_1 = test.geometry.values[0]
    geo_2 = test.geometry.values[1]

    overlap = geo_1.intersection(geo_2)
    geo_1_overlap_removed = geo_1.difference(overlap) # this will have an extra point contained in geo_2

    geo_1_minus_geo_2 = geo_1.difference(geo_2) # this is good



    Why does this happen? What am I doing wrong?

    Continue reading...

Compartilhe esta Página