python – Library to perform coordinate system transformations?

python – Library to perform coordinate system transformations?

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(init=epsg:4326),
    pyproj.Proj(init=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)

Concerning transformation and rotation I found transformations.py
from Christoph Gohlke very useful.

python – Library to perform coordinate system transformations?

Leave a Reply

Your email address will not be published.