Commit e0cc029e authored by Sarah Abrishami's avatar Sarah Abrishami

Initial Commit

parents
Pipeline #228 failed with stages
This source diff could not be displayed because it is too large. You can view the blob instead.
import json
import geopandas as gpd
from shapely.geometry import Polygon, MultiPolygon, Point
def find_center(mlp):
if isinstance(mlp, MultiPolygon):
area = 0
for p in mlp.geoms:
if p.area > area:
center = Point(p.centroid.x, p.centroid.y)
elif isinstance(mlp, Polygon):
center = Point(mlp.centroid.x, mlp.centroid.y)
else:
raise TypeError('object not polygon nor multipolygon')
return center
df = gpd.read_file('Iran-Districts-Test.json')
df = df.loc[df['geometry'].notna()]
gdf = gpd.GeoDataFrame(columns=['geometry', 'clmd_id', 'center'])
for climate in df['clmd_id'].unique():
a = {'geometry': MultiPolygon(), 'clmd_id': climate}
df.loc[df['clmd_id'] == climate, 'geometry'].apply(lambda x: a.update({'geometry': a['geometry'].union(x)}))
gdf = gdf.append(a, ignore_index=True)
gdf['center'] = gdf['geometry'].apply(find_center)
# gdf.to_file()
\ No newline at end of file
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