Created
March 31, 2014 20:41
-
-
Save bmcbride/9901745 to your computer and use it in GitHub Desktop.
Calculate the length of a GeoJSON linestring using the Python GDAL/OGR API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from osgeo import ogr | |
from osgeo import osr | |
source = osr.SpatialReference() | |
source.ImportFromEPSG(4326) | |
target = osr.SpatialReference() | |
target.ImportFromEPSG(3857) | |
transform = osr.CoordinateTransformation(source, target) | |
geojson = """{ "type": "LineString", "coordinates": [ [ -75.313585, 43.069271 ], [ -75.269426, 43.114027 ], [ -75.158731, 43.114325 ] ] }""" | |
geom = ogr.CreateGeometryFromJson(geojson) | |
geom.Transform(transform) | |
print "Length = %d" % geom.Length() + " meters" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the actual length formula it is using? It should be Sqrt(Abs(X1-X2)^2+Abs(Y1-Y2)^2)*111139 right?