3

I have a GeoDataFrame with fields: "Site","Group","Area", and "geometry" column with MultiPolygons. I try to unite rows based on the "Site" and "Group" columns using dissolve in this way:

gdf.dissolve(by=["Site","Group"],aggfunc={"Area":sum})

But I receive an error message:

GEOSException: TopologyException: side location conflict at 35.036441152893133 32.381401975779298. This can occur if the input geometry is invalid.

How can I locate the problematic Multipolygon / Polygon in GeoPandas?

0

1 Answer 1

3

Use .is_valid method:

import geopandas as gpd
import shapely

#Create a test dataframe
    #The first line is valid, the second is not, it starts and ends at the same point
wkts  = ["LINESTRING (30 10, 10 30, 40 40)", "LINESTRING (30 10, 30 10)"] 
geometries = [shapely.wkt.loads(x) for x in wkts] #Create shapely geometries
df = gpd.GeoDataFrame(geometry=geometries) #And a data frame

invalid = df.loc[~df.geometry.is_valid] #Select rows which are not (~) valid
#                                            geometry
#1  LINESTRING (30.00000 10.00000, 30.00000 10.00000)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.