-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCIRCLE.py
31 lines (22 loc) · 896 Bytes
/
CIRCLE.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'''
THE GOAL OF THIS PYTHON SCRIPT IS TO EXTRACT A CIRCLE OUT OF AN INPUT POLYGON SHAPEFILE
'''
import geopandas as gpd
from shapely.geometry import Point, Polygon
from smallestenclosingcircle import make_circle
# Load the shapefile
gdf = gpd.read_file("pincodebndry.shp")
# Combine all the polygons into a single MultiPolygon
multipolygon = gdf.unary_union
# Get the coordinates of the multipolygon
coords = list(multipolygon.exterior.coords)
# Calculate the smallest enclosing circle
center_x, center_y, radius = make_circle(coords)
# Create a circle around the center with the calculated radius
circle = Point(center_x, center_y).buffer(radius)
# Create a new GeoDataFrame to save the circle
circle_gdf = gpd.GeoDataFrame(geometry = [circle])
# Save the circle to a new shapefile
circle_gdf.to_file("BOUNDING/CIRCLE_2.shp")
# End of Python Script
print("TASK COMPLETED SUCCESSFULLY")