Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy
- def ConvertCoords ( x, y, z):
- from osgeo import osr
- # Set up spatial reference systems
- # using EPSG 28992
- proj = osr.SpatialReference()
- proj.ImportFromEPSG(28992)
- proj.SetTOWGS84(565.237, 50.0087, 465.658, -0.406857, 0.350733, -1.87035, 4.0812 )
- # lat/lon WGS84
- latlong = osr.SpatialReference()
- latlong.ImportFromProj4('+proj=latlong +datum=WGS84')
- #Define transform, from EPSG28992 to LatLon/WGS84
- transform = osr.CoordinateTransformation( proj, latlong )
- (lon, lat,z) = transform.TransformPoint( x, y, z)
- return (lon,lat, z)
- if __name__=="__main__":
- from osgeo import osr
- # Set up spatial reference systems
- # using EPSG 28992
- proj = osr.SpatialReference()
- proj.ImportFromEPSG(28992)
- proj.SetTOWGS84(565.237, 50.0087, 465.658, -0.406857, 0.350733, -1.87035, 4.0812 )
- # lat/lon WGS84
- latlong = osr.SpatialReference()
- latlong.ImportFromProj4('+proj=latlong +datum=WGS84')
- from osgeo import ogr
- polygon =numpy.array ([[132817.006604435708141, 550302.852720651309937, 0.],\
- [131182.28895997320069, 558340.214472591876984, 0.],\
- [132578.61028128489852, 558748.893883707583882, 0.],\
- [136631.347774848196423, 553436.061539204441942, 0.],\
- [136631.347774848196423, 553436.061539204441942, 0.],\
- [132817.006604435708141, 550302.852720651309937, 0.]])
- @@ # We can use two methods: convert individual points, or create an OGR feature and convert that
- @@ # Method 1: Use convert individual points
- result = [ConvertCoords ( polygon[i, 0], polygon[i, 1], polygon[i,2] ) for i in xrange(polygon.shape[0])]
- print result
- # Method 2: Convert whole polygon...
- wkt = "POLYGON(("
- edges = ["%f %f %f,"%( polygon[i,0], polygon[i,1], polygon[i,2]) for i in xrange(polygon.shape[0])]
- wkt = wkt+"".join (edges[:-1])+edges[-1].replace(",", "")+"))"
- geom = ogr.CreateGeometryFromWkt ( wkt )
- geom.AssignSpatialReference ( proj )
- geom.TransformTo ( latlong)
- print geom.ExportToWkt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement