Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library to perform coordinate system transformations? [closed]

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:

  • transformations (cartesian, spherical, polar, ...)
  • translations
  • rotations?
like image 860
P3trus Avatar asked Feb 11 '23 04:02

P3trus


1 Answers

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)

like image 107
Tom-db Avatar answered Feb 13 '23 22:02

Tom-db