0

Hello I am new to working with GeoTiff data and I am trying to grab lat/lon values from a tiff image. Here is my code:

import gdal
import matplotlib.pyplot as plt
import osr

# open the dataset and get the geo transform matrix
ds = gdal.Open(r'C:\Users\_______\Documents\Landsat8\LC08_L1GT_156120_20170207_20170216_01_T2_B5.tif') 
xoffset, px_w, rot1, yoffset, rot2, px_h = ds.GetGeoTransform()

x = 100
y = 100

# supposing x and y are your pixel coordinate this 
# is how to get the coordinate in space.
posX = px_w * x + rot1 * y + xoffset
posY = rot2 * x + px_h * y + yoffset

# shift to the center of the pixel
posX += px_w / 2.0
posY += px_h / 2.0

# get CRS from dataset 
crs = osr.SpatialReference()
crs.ImportFromWkt(ds.GetProjectionRef())
# create lat/long crs with WGS84 datum
crsGeo = osr.SpatialReference()
crsGeo.ImportFromEPSG(4326) # 4326 is the EPSG id of lat/long crs 
t = osr.CoordinateTransformation(crs, crsGeo)
(lat, long, z) = t.TransformPoint(posX, posY)

However, when I run this I keep receiving the following error:

NotImplementedError: Wrong number or type of arguments for overloaded 
function 'CoordinateTransformation_TransformPoint'.
Possible C/C++ prototypes are:
OSRCoordinateTransformationShadow::TransformPoint(double [3])
OSRCoordinateTransformationShadow::TransformPoint(double [4])
OSRCoordinateTransformationShadow::TransformPoint(double [3],double,double,double)
OSRCoordinateTransformationShadow::TransformPoint(double [4],double,double,double,double)

I have no idea what this means, I have looked up the error and found no useful information so I am hoping one of you have experienced this problem before.

  • Just a guess, but I can't see where the Z coord should come from when the input is XY. Any luck with (lat, long) = t.TransformPoint(posX, posY)? – Gabor Farkas Aug 13 at 21:04
  • Please include the full exception text, not just the last error message when asking questions on GIS-SE. You may not have your GDAL_DATA env var set. – user2856 Aug 14 at 0:00
  • Here is the full error: NotImplementedError: Wrong number or type of arguments for overloaded function 'CoordinateTransformation_TransformPoint'. Possible C/C++ prototypes are: OSRCoordinateTransformationShadow::TransformPoint(double [3]) OSRCoordinateTransformationShadow::TransformPoint(double [4]) OSRCoordinateTransformationShadow::TransformPoint(double [3],double,double,double) OSRCoordinateTransformationShadow::TransformPoint(double [4],double,double,double,double) – intern12345 Aug 14 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.