Advertisement
lmotta

OGR/GDAL Create Shapefile lost some parameter Spatial Refer

Jan 17th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. from osgeo import ogr, osr
  5.  
  6. ogr.RegisterAll()
  7.  
  8. # Shapefile lost parameter +towgs84
  9. pathFile = '/home/lmotta/data/script_gis_dev/data/test_utm_sad69.shp'
  10. strDrive= 'ESRI Shapefile'
  11.  
  12. # GML use all parameters
  13. #pathFile = '/home/lmotta/data/script_gis_dev/data/test_utm_sad69.gml'
  14. #strDrive= 'GML'
  15.  
  16. proj4Sr = '+proj=utm +zone=21 +south +ellps=aust_SA +towgs84=-57,1,-41,0,0,0,0 +units=m +no_defs'
  17. sr = osr.SpatialReference()
  18. sr.ImportFromProj4( proj4Sr  )
  19.  
  20. # Create Shapefile with SpatialReference (delete if exist)
  21. drv = ogr.GetDriverByName(strDrive)
  22. ds = drv.CreateDataSource(pathFile)
  23. lyr = ds.CreateLayer(pathFile, sr, ogr.wkbPolygon)
  24.  
  25. print 'proj4Sr: %s' % proj4Sr
  26. print 'Layer  : %s' % lyr.GetSpatialRef().ExportToProj4()
  27.  
  28. # Free
  29. ds.Destroy()
  30. ds = None
  31. lyr = None
  32. if strDrive == 'GML':
  33.   os.remove(pathFile)
  34.   os.remove(pathFile.replace('.gml', '.xsd'))
  35. else:
  36.   drv.DeleteDataSource(pathFile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement