Python(GDAL): projection conversion from WGS84 to NZTM2000 is not correct

标签 python gdal

我是 Python 和 GDAL 的新手。我正在将以下文件转换为 NZTM2000 坐标转换器。我将文件导入为 csv,然后使用 Lat/Long 将其转换为 XY 输出。但是,结果对我来说并不正确。我不明白输出单位/比例。我期待的是 6 位数字。

脚本:

"reads a CSV file and converts its coordinates"
import os
import csv
from osgeo import gdal
from osgeo import osr
from osgeo import ogr

# Coordinate Reference System (CRS)
SourceEPSG = 4326  
TargetEPSG = 2193

source = osr.SpatialReference()
source.ImportFromEPSG(SourceEPSG)

target = osr.SpatialReference()
target.ImportFromEPSG(TargetEPSG)


# Input file details
fullpath = os.path.abspath("\ew0001\NavigationsCMP")

def CRSTransform(Lat, Long):
    transform = osr.CoordinateTransformation(source, target)
    point = ogr.CreateGeometryFromWkt("POINT ("+Lat+" "+Long+")")
    point.Transform(transform)
    print point.GetX(), "   ", point.GetY()


print "Reading CSV"
inCSV = csv.DictReader(open(fullpath+".csv"))
for row in inCSV:
    lat = row['Lat']
    long = row['Long']
    CRSTransform(lat, long)

输入:

Lat Long    CMP Year    Month   Day Hours   Mins    Sec XXX Line    Vintage
-44.419134  172.243651  264 2000    1   23  6   11  10  180 10  EW0001
-44.419176  172.243706  265 2000    1   23  6   11  12  681 10  EW0001
-44.419214  172.243759  266 2000    1   23  6   11  15  181 10  EW0001
-44.419259  172.24382   267 2000    1   23  6   11  17  711 10  EW0001

输出:

-44.419134     172.243651
-44.419176     172.243706
-44.419214     172.243759
-44.419259     172.24382

最佳答案

GDAL 的原始答案<3

您需要交换轴顺序,以便 X = 经度,Y = 纬度。

def CRSTransform(Lat, Long):
    transform = osr.CoordinateTransformation(source, target)
    point = ogr.Geometry(ogr.wkbPoint)
    point.SetPoint_2D(0, float(Long), float(Lat))
    point.Transform(transform)
    print point.GetX(), "   ", point.GetY()

CRSTransform(-44.419134, 172.243651)  # 1539788.868     5081294.99354

更新了 GDAL 3+ 的答案

轴顺序已从 GDAL 3.0 更改(例如,参见 GDAL's OSR API tutorial )。默认顺序是“符合权威”,例如纬度/经度。要获取 X/Y 的“传统轴顺序”,请使用:

source.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
target.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)

如果您想保留的纬度/经度,则它将是默认值或指定的:

source.SetAxisMappingStrategy(osr.OAMS_AUTHORITY_COMPLIANT)

请注意,EPSG:2193 具有默认权限北距/东距(或 Y/X)。

关于Python(GDAL): projection conversion from WGS84 to NZTM2000 is not correct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35945437/

相关文章:

c++ - 如果您有 GeoTiff,是否可以使用 GeoTransform 将纬度/经度点转换为 X、Y?

c++ - 如何针对自定义 CUDA 安装使用 OpenCL 构建 GDAL?

shell - 将灰度图像转换为渐进式黑色加透明度?

python - 如何在浏览器 URL 中显示 django ImageField

python - 是否有类似反向 eval() 函数的东西?

python - 如何添加要求整型变量属于数组的约束?

java - 适用于 Windows 7(x32) 的 Gdal

python - 如何在databricks上运行python3?

python - 使用 Pandas 将文本数据从请求对象转换为数据框

python - 在 Ubuntu 中安装 GDAL Python 绑定(bind)以用作独立模块