Is there a python library which handles coordinate system transformations? I'm working with numpy meshgrids, but sometimes it's useful to switch the coordinate systems. Since I don't want to reinvent the wheel, are there any libraries which handle:
You can use the shapely library: http://toblerity.org/shapely/manual.html
Affine transformation: http://toblerity.org/shapely/manual.html#affine-transformations
Coordinate transformation: http://toblerity.org/shapely/manual.html#other-transformations Sample code:
from shapely.geometry import Point
from functools import partial
import pyproj
from shapely.ops import transform
point1 = Point(9.0, 50.0)
print (point1)
project = partial(
pyproj.transform,
pyproj.Proj('epsg:4326'),
pyproj.Proj('epsg:32632'))
point2 = transform(project, point1)
print (point2)
You can also use the ogr library. i.e.
from osgeo import ogr
from osgeo import osr
source = osr.SpatialReference()
source.ImportFromEPSG(2927)
target = osr.SpatialReference()
target.ImportFromEPSG(4326)
transform = osr.CoordinateTransformation(source, target)
point = ogr.CreateGeometryFromWkt("POINT (1120351.57 741921.42)")
point.Transform(transform)
print (point.ExportToWkt())
(from http://pcjericks.github.io/py-gdalogr-cookbook/projection.html)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With