Skip to main content
added 354 characters in body
Source Link
gene
  • 55.4k
  • 3
  • 113
  • 191

Use GeoPandas Overlay

# areaareas of buildings
building['area_buil'] =building.geometry.apply(lambda x: x.area)
# first row
print(building.head(1))
   id               geometry                                area_buil
0   1  POLYGON ((682.0664490861618 -56.9528720626632,...  14234.471441
# areaareas of cadastre parcels
cadastre['area_cad'] =cadastre.geometry.apply(lambda x: x.area)
# first row
cadastre.head()
    id            geometry                                 area_cad
0   1  POLYGON ((522.2243230638396 -72.21015374517569...  859.121096

Intersection of the two GeoDataFrames

inter = gpd.overlay(building, cadastre, how='intersection')
# areaareas of intersection polygons
inter['area_int'] =inter.geometry.apply(lambda x: x.area)
# first row
inter.head(1)
    id   area_buil    id_2   area_cad   geometry    area_int
0   1  14234.471441     3  2569.372692    POLYGON ((686.3676624325899 -106.6574169572678   2569.372692 

Now you can compute crit1 and crit2

inter['crit1'] =inter.apply(lambda row: row.area_int/row.area_buil,axis=1)
inter['crit2'] =inter.apply(lambda row: row.area_int/row.area_cad,axis=1)

The result is a GeoDataFrame with everything you need.

  inter[['area_int','area_buil','crit1','area_cad','crit2']]
       area_int     area_buil     crit1     area_cad     crit2
  0  2569.372692  14234.471441  0.180504  2569.372692  1.000000
  1   776.791694    913.700570  0.850160  1791.819989  0.433521
  2   247.790095    545.270793  0.454435   859.121096  0.288423
  .....

Use GeoPandas Overlay

# area of buildings
building['area_buil'] =building.geometry.apply(lambda x: x.area)
# first row
print(building.head(1))
   id               geometry                                area_buil
0   1  POLYGON ((682.0664490861618 -56.9528720626632,...  14234.471441
# area of cadastre parcels
cadastre['area_cad'] =cadastre.geometry.apply(lambda x: x.area)
# first row
cadastre.head()
    id            geometry                                 area_cad
0   1  POLYGON ((522.2243230638396 -72.21015374517569...  859.121096

Intersection of the two GeoDataFrames

inter = gpd.overlay(building, cadastre, how='intersection')
# area of intersection polygons
inter['area_int'] =inter.geometry.apply(lambda x: x.area)
# first row
inter.head(1)
    id   area_buil    id_2   area_cad   geometry    area_int
0   1  14234.471441     3  2569.372692    POLYGON ((686.3676624325899 -106.6574169572678   2569.372692 

Now you can compute crit1 and crit2

inter['crit1'] =inter.apply(lambda row: row.area_int/row.area_buil,axis=1)
inter['crit2'] =inter.apply(lambda row: row.area_int/row.area_cad,axis=1)

The result is a GeoDataFrame with everything you need.

Use GeoPandas Overlay

# areas of buildings
building['area_buil'] =building.geometry.apply(lambda x: x.area)
# first row
print(building.head(1))
   id               geometry                                area_buil
0   1  POLYGON ((682.0664490861618 -56.9528720626632,...  14234.471441
# areas of cadastre parcels
cadastre['area_cad'] =cadastre.geometry.apply(lambda x: x.area)
# first row
cadastre.head()
    id            geometry                                 area_cad
0   1  POLYGON ((522.2243230638396 -72.21015374517569...  859.121096

Intersection of the two GeoDataFrames

inter = gpd.overlay(building, cadastre, how='intersection')
# areas of intersection polygons
inter['area_int'] =inter.geometry.apply(lambda x: x.area)
# first row
inter.head(1)
    id   area_buil    id_2   area_cad   geometry    area_int
0   1  14234.471441     3  2569.372692    POLYGON ((686.3676624325899 -106.6574169572678   2569.372692 

Now you can compute crit1 and crit2

inter['crit1'] =inter.apply(lambda row: row.area_int/row.area_buil,axis=1)
inter['crit2'] =inter.apply(lambda row: row.area_int/row.area_cad,axis=1)

The result is a GeoDataFrame with everything you need.

  inter[['area_int','area_buil','crit1','area_cad','crit2']]
       area_int     area_buil     crit1     area_cad     crit2
  0  2569.372692  14234.471441  0.180504  2569.372692  1.000000
  1   776.791694    913.700570  0.850160  1791.819989  0.433521
  2   247.790095    545.270793  0.454435   859.121096  0.288423
  .....
Source Link
gene
  • 55.4k
  • 3
  • 113
  • 191

Use GeoPandas Overlay

# area of buildings
building['area_buil'] =building.geometry.apply(lambda x: x.area)
# first row
print(building.head(1))
   id               geometry                                area_buil
0   1  POLYGON ((682.0664490861618 -56.9528720626632,...  14234.471441
# area of cadastre parcels
cadastre['area_cad'] =cadastre.geometry.apply(lambda x: x.area)
# first row
cadastre.head()
    id            geometry                                 area_cad
0   1  POLYGON ((522.2243230638396 -72.21015374517569...  859.121096

Intersection of the two GeoDataFrames

inter = gpd.overlay(building, cadastre, how='intersection')
# area of intersection polygons
inter['area_int'] =inter.geometry.apply(lambda x: x.area)
# first row
inter.head(1)
    id   area_buil    id_2   area_cad   geometry    area_int
0   1  14234.471441     3  2569.372692    POLYGON ((686.3676624325899 -106.6574169572678   2569.372692 

Now you can compute crit1 and crit2

inter['crit1'] =inter.apply(lambda row: row.area_int/row.area_buil,axis=1)
inter['crit2'] =inter.apply(lambda row: row.area_int/row.area_cad,axis=1)

The result is a GeoDataFrame with everything you need.