-
-
Save dgreyling/85eb74040d1f3f0f04837138f8502d16 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