Skip to content

Instantly share code, notes, and snippets.

@amirouche
Last active December 21, 2017 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirouche/897a66bfe8c6f680830c398d66d509e0 to your computer and use it in GitHub Desktop.
Save amirouche/897a66bfe8c6f680830c398d66d509e0 to your computer and use it in GitHub Desktop.
Convert ShapeFile to WGS 84 using GDAL
# with gdal
import osgeo.ogr
w = osgeo.ogr.Open('BATI_INDIFFERENCIE.SHP')
layer = f.GetLayer(0)
# get source SRID
source = layer.GetSpatialRef()
# load generic SRID aka. WGS84 with 3 coordinates
target = osgeo.osr.SpatialReference()
WGS84_3D = 4979
target.ImportFromEPSG(WGS84_3D)
# create transformation to share between several transformations
transform = osgeo.osr.CoordinateTransformation(source, target)
# get a geometry
feature = layer.GetFeature(0)
geometry = layer.geometry()
# transform geometry
geometry.Transform(transform)
# or more easily
geometry.TransformTo(target)
feature.ExportToJson()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment