Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python(GDAL):从WGS84到NZTM2000的投影转换不正确_Python_Gdal - Fatal编程技术网

Python(GDAL):从WGS84到NZTM2000的投影转换不正确

Python(GDAL):从WGS84到NZTM2000的投影转换不正确,python,gdal,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 o

我是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

您需要交换轴顺序,以便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