[Gdal-dev] Get Line Length
RMcCulley at county24.com
Thu Oct 26 11:43:12 EDT 2006
I'm trying to write a script that will calculate the total length of a
polyline shapefile using ogr in python. I see in the ogr documentation
that both the OGRCurve and OGRLineString class support the method
get_Length(). The problem I'm having is that I can't figure out how to
get a linestring or curve object. Here is what I have so far:
shp = ogr.Open(gpsfilelocation)
lyr = shp.GetLayer()
totalLength = 0
for i in range(lyr.GetFeatureCount()):
ftr = lyr.GetFeature(i)
geom = lyr.GetGeometryRef()
length = ?
totalLength = totalLength + length
At this point I could iterate through the points of the geometry and
calculate the length of each segment, but using a get_Length() function
seems much more elegant.
How do I access the curve or linestring class to calculate the length?
County of Vermilion River No. 24
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Gdal-dev