2

I have 2 geodataframes:

  • GDF1 is an area with overlapping polygons divided into 3 classes: (cleaning, infra and maintenance) (the black lines donates the overlapping polygons)
  • GDF2 consists of polygons describing the type of the area's surface, like gras, sand, buildings, water etc (the colors donate the type of area's surface)

I want to calculate: what kind of land_use_type (from GDF2) each polygon from GDF1 consists.

What i tried is :

GDF1 = gpd.GeoDataFrame.from_postgis('select class, geom_sm as geom 
                                        From geo.GDF1',
                                        con=engine, geom_col='geom')

GDF2 = gpd.GeoDataFrame.from_postgis('SELECT land_use_type,wkb_geometry_sm as geom 
                                      FROM geo.GDF2', 
                                      con=engine, geom_col='geom')

I calculated the area of each land_use_type polygons:

GDF2["area"] = GDF2['geom'].area

And after that i merged on GDF1

merged = gpd.sjoin(GDF1, GDF2, how='left', op='intersects')

I got a new column with areas but I am not sure if that's the right calculation.

enter image description here

0

I think you are looking for the overlay operation (see docs):

merged = geopandas.overlay(GDF1, GDF2, how='intersects')

This gives a GeoDataFrame with all intersections of all combinations of both layers. In this way, you will be able to calculate the area of the different surface types for each of the classes.

Your Answer

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

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