2

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.

3
  • 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)? Commented Aug 13, 2019 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
    Commented Aug 14, 2019 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) Commented Aug 14, 2019 at 14:19

2 Answers 2

3

In my case, the x/y variables were of type numpy.float32 (read out of an array) which caused this exact error. Changing the types to regular float worked.

2

This error is extremely confusing, but it is thrown when the in- or output projection is not set. Check your crs and crsGeo to check if they are not an empty.

If so, try updating pyproj, setting your PROJ_LIB correctly etc.

1
  • This helped me solve my problem, which was I had specified a very specific transformation using osr.CoordinateTransformationOptions.SetOperation that was inapplicable to the source/target CRS.
    – freespace
    Commented Jan 15, 2023 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.