First of all, I apologize to post this easy question. I need to compute a certain number of gemotrical attributes (area, perimeters, Roundess, major and minor axis, etc). I am using GDAL/OGR to read a shapefile format of my polygon. What i wish to ask is:
thanks in advance
import osgeo.gdal, ogr
poly="C:\\\myshape.shp"
shp = osgeo.ogr.Open(poly)
layer = shp.GetLayer()
# For every polygon
for index in xrange(len(allFID)):
feature = layer.GetFeature(index)
# get "FID" (Feature ID)
FID = str(feature.GetFID())
geometry = feature.GetGeometryRef()
# get the area
Area = geometry.GetArea()
ref_geometry = ref_feature.GetGeometryRef()
pts = ref_geometry.GetGeometryRef(0)
points = []
for p in xrange(pts.GetPointCount()):
points.append((pts.GetX(p), pts.GetY(p)))
def edges_index(points):
"""
compute edges index for a given 2D point set
1- The number of edges which form the polygon
2- Perimeter
3- The length of the longest edge in a polygon
4- The length of the shortest edge in a polygon
5- The average length of all of edges in a polygon
6- The lengths of edges deviate from their mean value
"""
Nedges = len(points)-1
length = []
for i in xrange(Nedges):
ax, ay = points[i]
bx, by = points[i+1]
length.append(math.hypot(bx-ax, by-ay))
edges_perimeter = numpy.sum(length)
edges_max = numpy.amax(length)
edges_min = numpy.amin(length)
edges_average = numpy.average(length)
edges_std = numpy.std(length)
return (Nedges,edges_perimeter,edges_max,edges_min,edges_average,edges_std)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With