简体   繁体   中英

convert utm coordinate to coordinate in reference to neighboring zone

I have tens of thousands of rasters in NAD83 UTM 13N. I'm trying to extract data by points using arcpy.GetCellValue_management(raster.tif, point), but the very western side of the data is in the UTM 12N zone. Is there a way to get a coordinate from 12N but referenced to 13N? A project requirement is that all data be in UTM 13N even though its a statewide project. I know its silly.

This can be accomplished with GDAL. Save your dataPoints.shp in the UTM grid you desire (ie, UTM 13N), then use GDAL to load the points layer, get field, get geometry, get bounding coordinates, geotransform, raster band, point coordinates (in UTM 13N)and read the raster as array. Build a loop over all rasters, and it works very fast. Thanks to Luke for giving the details here .

from osgeo import gdal, ogr
shp_filename = 'C:\\Path\\dataPoints_UTM13.shp'
ds = ogr.Open(shp_filename)
lyr = ds.GetLayer()
for feat in lyr:
    point_id_obj = feat.GetField("Sample")
    name = feat.GetField("Location_D")
    geom = feat.GetGeometryRef()
    mx, my = geom.GetX(), geom.GetY()
    path = 'C:\\RasterPath'
    raster = 'myraster'
    ras_open = gdal.Open('{a}\\{b}.tif'.format(a=path, b=raster))
    gt = aws_open.GetGeoTransform()
    rb = aws_open.GetRasterBand(1)
    px = abs(int((mx - gt[0]) / gt[1]))
    py = int((my - gt[3]) / gt[5])
    ras_obj = rb.ReadAsArray(px, py, 1, 1)
    print point_id_obj
    print name
    print mx, my

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM