I have to find if the point belongs to an area. Information is given by geojson file. I created DataFrame by:
choro = pd.concat([pd.DataFrame({'name':block['properties']['name'], 'area': shape(block['geometry'])}) for block in geojson['features']], ignore_index=True)
that code work with warning:
ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the
geoms
property to access the constituent parts of a multi-part geometry
but works! btw, if you know how to modify the code to switch off that warning - much appreaite!
the dataframe looks like:
Here is the code for checking if point belong to the area:
for index, area in choro.iterrows():
polygon = area['area']
if polygon.contains(point):
print('Point belongs to ',area['name'])
if I change my dataframe (exclude "shape" command) to get only coordinates (and no warning messages):
choro = pd.concat([pd.DataFrame({'name':block['properties']['name'], 'area': block['geometry']['coordinates']}) for block in geojson['features']], ignore_index=True)
I will have:
and obviously "shape" command for polygon:
polygon = shape(area['area'])
and:
polygon = MultiPolygon(area['area'])
are not working anymore.
The question is how I can get more clear code : to have polygons (or any other "working" structure) be stored in dataframe structure to work with shapely function to find if point is belong to the area and w/o any warnings or errors.