Advertisement
lmotta

Difference QGIS and GDAL

Jan 16th, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. from osgeo import ogr, osr
  2.  
  3. ogr.RegisterAll()
  4.  
  5. drvShape = ogr.GetDriverByName('ESRI Shapefile')
  6. def getGeom(pathName):
  7.   """
  8.  pathName is path and name of file with Geom (format 'ESRI Shapefile')
  9.  """
  10.   ds = drvShape.Open(pathName, 0)
  11.   lyr = ds.GetLayer(0)
  12.   feat = lyr.GetNextFeature()
  13.   # Geom
  14.   geom = feat.GetGeometryRef().Clone()
  15.   # Free
  16.   feat.Destroy()
  17.   ds.Destroy()
  18.   lyr = None
  19.   #
  20.   return geom
  21.  
  22. # Spatial Reference
  23. srWgs84 = osr.SpatialReference()
  24. srWgs84.ImportFromEPSG(4326)
  25.  
  26. srEpsg29191 = osr.SpatialReference()
  27. srEpsg29191.ImportFromEPSG(29191)
  28.  
  29. # Source Geometry
  30. pathName = '/home/lmotta/data/tutorial/footprint_shp/sad69_utm.shp'
  31. geomSrc = getGeom(pathName)
  32.  
  33. # Source Geometry set by Epsg 29191
  34. geomSrc29191 = geomSrc.Clone()
  35. geomSrc29191.AssignSpatialReference(srEpsg29191)
  36.  
  37. # Spatial Reference
  38. print '*** Spatial Reference'
  39. print '* geomSrc: %s' % geomSrc.GetSpatialReference().ExportToProj4()
  40. print '* geomSrc29191: %s' % geomSrc29191.GetSpatialReference().ExportToProj4()
  41.  
  42. # Transform Spatial Reference for Wgs 84
  43. geomSrc.TransformTo(srWgs84)
  44. geomSrc29191.TransformTo(srWgs84)
  45.  
  46. # WKT Shape
  47. print '*** WKT Transform WGS84'
  48. print '* geomSrc:\n%s' % geomSrc.ExportToWkt()
  49. print '* geomSrc29191:\n%s' % geomSrc29191.ExportToWkt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement