Last active
December 21, 2017 20:56
-
-
Save amirouche/897a66bfe8c6f680830c398d66d509e0 to your computer and use it in GitHub Desktop.
Convert ShapeFile to WGS 84 using GDAL
This file contains 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
# 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