0

I am relatively new to Python generally and GIS specifically and wondered if I could get some advice on the best package to use to calculate the overlap of two polygons I have calculated and stored in GeoJson format.

Basically, I have two lists, one is a few large polygons and the other is a lot of small polygons. I would like to know for each of the large polygons which of the smaller ones are wholly or partially within the large one, storing the percentage of the smaller polygon contained in each case.

From an Udemy course I have completed, I think that GeoPandas might be suitable but would it be better to just use Shapely, given I have the GeoJson of the two polygons I wish to check, or is there a better package?

Thanks in advance.

  • I'd go with Shapely, but seeking library recommendations is out of scope for SO. – AKX Jan 10 '23 at 16:11

1 Answers1

1

if you have your data in geojsons or geopandas dataframes, this is the easiest way to do it:

import geopandas as gp
import matplotlib.pyplot as plt

gdf1 = gp.read_file(jsonfile) #one set of polygons
gdf2 = gp.read_file(otherjsonfile) #another set of polygons
gdf3 = gdf1.intersection(gdf2) #this calculates the intersection between all shapes in gdf1 and gdf2

gdf1.plot(ax=ax, color='r', alpha=0.5):

enter image description here

gdf2.plot(ax=ax, color='b', alpha=0.5):

enter image description here

and now, the intersection..

gdf3.plot(ax=ax, color='g', alpha=0.5)

enter image description here

Derek Eden
  • 4,403
  • 3
  • 18
  • 31