Commit 4eedffb2 authored by Sarah Abrishami's avatar Sarah Abrishami

updated file

parent e0cc029e
import json
import geopandas as gpd
from shapely.geometry import Polygon, MultiPolygon, Point
import fiona
def find_center(mlp):
......@@ -8,9 +9,9 @@ def find_center(mlp):
area = 0
for p in mlp.geoms:
if p.area > area:
center = Point(p.centroid.x, p.centroid.y)
center = json.dumps([p.centroid.x, p.centroid.y])
elif isinstance(mlp, Polygon):
center = Point(mlp.centroid.x, mlp.centroid.y)
center = json.dumps([mlp.centroid.x, mlp.centroid.y])
else:
raise TypeError('object not polygon nor multipolygon')
return center
......@@ -25,4 +26,4 @@ for climate in df['clmd_id'].unique():
gdf = gdf.append(a, ignore_index=True)
gdf['center'] = gdf['geometry'].apply(find_center)
# gdf.to_file()
\ No newline at end of file
gdf.to_file('output.json', driver='GeoJSON')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment