执行坐标系转换的库?

2024-05-13 07:11:08 发布

您现在位置:Python中文网/ 问答频道 /正文

是否有处理坐标系转换的python库? 我正在使用numpy网格,但有时切换坐标系很有用。 既然我不想重新发明轮子,有没有图书馆可以处理:

  • 变换(笛卡尔、球面、极坐标等)
  • 翻译
  • 旋转?

Tags: numpy网格图书馆轮子球面坐标系极坐标
2条回答

您可以使用shapely库: http://toblerity.org/shapely/manual.html

仿射变换:http://toblerity.org/shapely/manual.html#affine-transformations

坐标变换:http://toblerity.org/shapely/manual.html#other-transformations 示例代码:

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)

您也可以使用ogr库。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())

(来自http://pcjericks.github.io/py-gdalogr-cookbook/projection.html

关于变换和旋转,我发现transformations.py 克里斯托夫·高尔克写的非常有用。

相关问题 更多 >