[Gdal-dev] Calculating Polyline lengths in a file

Rob McCulley RMcCulley at county24.com
Tue Nov 7 17:48:39 EST 2006


I needed to do this recently.  I wound up using python mapscript.  Here
is a snippet of the code that did it for me:

shpfile = mapscript.shapefileObj(gpsfilelocation)
totalLength = 0
for i in range(shpfile.numshapes):
    shp = shpfile.getShape(i)
    length = shp.getLength()
    totalLength = totalLength + length




-----Original Message-----
From: gdal-dev-bounces at lists.maptools.org
[mailto:gdal-dev-bounces at lists.maptools.org] On Behalf Of
matt.pettis at thomson.com
Sent: Tuesday, November 07, 2006 3:27 PM
To: gdal-dev at lists.maptools.org
Subject: [Gdal-dev] Calculating Polyline lengths in a file

Is there an easy way to calculate the lengths of polyline objects in a
shapefile (i have a shapefile of roads for a county, and want to find
the total length)?  Is there an OGR tool to do this, or does anybody
know of another tool?
 
I have done this halfway a hard way... I imported my file into
PostgreSQL/PostGIS, and applied length2d to it, and got a number.
However, I can't find documentation for what the units of the result are
in.  Does anybody know the answer to this question as well, as long as I
am here?
 
TIA,
Matt

_______________________________________________
Gdal-dev mailing list
Gdal-dev at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/gdal-dev

-- 
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.





More information about the Gdal-dev mailing list