Wednesday, 17 July 2019

gdal - How do I convert affine coordinates to lat/lng?



I am extremely new to GIS.


I'm using gdal to read in a landuse/landcover map and I need to pick out the lat/lng of certain land cover types to index into a different dataset which is expressed only in lat/lng. Unfortuantely, I don't understand the form of the x and y coordinates given to me from the geotransform, specifically the originX and originY below:


geotransform = dataset.GetGeoTransform()
originX = geotransform[0]
originY = geotransform[3]

Printing these values gives me coordinates like (447466.693808, 4952570.40529). How do these relate to the original latitude and longitude?


Edit:


Here's a simple python example that got me what I was looking for:


srs = osr.SpatialReference()

srs.ImportFromWkt(dataset.GetProjection())

srsLatLong = srs.CloneGeogCS()
ct = osr.CoordinateTransformation(srs,srsLatLong)
print ct.TransformPoint(originX,originY)

Stolen from: tolatlong.py



Answer



gdal_translate will reproject your data from whatever projection it is in to any other (in this case you want EPSG:4326) using:


gdal_translate -a_srs epsg:4326 srcfile new_file 


or you could use gdaltrasform to convert the points (and I'm sure you can access that from Python(?) too)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...