Reputation: 497
i have a dataframe which contains X and Y cordinates of the points
df=
80.4 30 17.11755
80.1 30 17.11755
80.7 30 17.11755
80.7 30.3 17.11755
80.4 30.3 17.11755
80.1 30.3 17.11755
81.3 30 17.11755
81 30 17.11755
81 30.3 17.11755
81.3 30.3 17.11755
81.6 30 17.11755
81.6 30.3 17.11755
81.9 30.3 17.11755
81.9 30 17.11755
82.2 29.7 17.11755
81 29.7 17.11755
81.3 29.7 17.11755
81.6 29.7 17.11755
81.9 29.7 17.11755
82.2 30 17.11755
82.2 30.3 17.11755
80.7 29.7 17.11755
80.4 29.7 17.11755
80.1 29.7 17.11755
which can be represented like given below
How to make a shapefile/polygon which corresponds to the rectangle in the picture(ie, outer boundary of the cluster of points) if such points are given?
NB: points do make random shapes
Any help?
Upvotes: 1
Views: 1400
Reputation: 523
To add to the correct answer above:
import geopandas as gpd
from shapely.geometry import MultiPoint, Polygon
pts = [[80.4, 30, 17.11755],
[80.1, 30, 17.11755],
[80.7, 29.7, 17.11755]]
mp = MultiPoint(pts)
conv_hull = mp.convex_hull
poly = Polygon(conv_hull)
df = gpd.GeoDataFrame({'geometry': gpd.GeoSeries(poly)})
df.crs = {'init': 'epsg:4326'} #Or whatever crs you want
df.to_file('poly.shp')
Upvotes: 3
Reputation: 113988
you can use the shapely library for this
from __future__ import print_function # py2
from shapely.geometry import MultiPoint
if __name__=="__main__":
pts = MultiPoint([(16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2), (12,10)])
print (pts.convex_hull)
(I just stole this from https://rosettacode.org/wiki/Convex_hull#Python )
Upvotes: 3