0

I am trying to create a Geotiff using gdal.Translate but I am getting the error:

return TranslateInternal(destName, srcDS, opts, callback, callback_data)

ValueError: Received a NULL pointer

dem = gdal.Translate("testdata.xyz", "testdata.tif", outputSRS='EPSG:4326')

the data x y z :

27.44357755706 70.88828891203 0.87817204
27.44507276823 70.88828891203 0.9693141
27.4465679794 70.88828891203 1.0749619
27.44208234589 70.88789537846 0.7483628
27.44357755706 70.88789537846 0.81988895
27.44507276823 70.88789537846 0.8975556
27.4465679794 70.88789537846 1.0749619
27.44806319057 70.88789537846 1.2012749
27.44955840174 70.88789537846 1.3572499
27.45105361291 70.88789537846 1.5525277
27.45254882408 70.88789537846 1.7776462
27.45404403524 70.88789537846 2.021481
27.45553924641 70.88789537846 2.2798731
27.45703445758 70.88789537846 2.8266306
27.45852966875 70.88789537846 3.0852618
27.43909192355 70.88710831133 0.5502324
27.44058713472 70.88710831133 0.590477
27.44208234589 70.88710831133 0.6383221
27.44357755706 70.88710831133 0.75451326

UPDATE:

Even after I changed the order to:

dem = gdal.Translate("testdata.tif", "testdata.xyz", outputSRS='EPSG:4326')

the same problem continues

EDIT: when I run:

print(gdal.Info("testdata.xyz"))

I get as result:

None

just to clarify that I created the .xyz file using the following:

df.to_csv('testdata.xyz', index=False, header=None, sep=" ")

where df is dataframe with the x, y and z values

7
  • @user2856 I posted the results
    – TheGame
    Commented Jan 14, 2023 at 14:34
  • propapbly the problem that .xyz misses details
    – TheGame
    Commented Jan 14, 2023 at 14:34
  • Yes, your .xyz is incomplete and can't be converted directly to raster. Have a look at gdal.Grid
    – user2856
    Commented Jan 14, 2023 at 22:28
  • @user2856 can you post an answer how to fix it ?
    – TheGame
    Commented Jan 15, 2023 at 17:24
  • Upgrade to gdal >=3.6.1 which now handles this.
    – user2856
    Commented Jan 15, 2023 at 21:18

1 Answer 1

1

You have your arguments in the wrong order. From the documentation:

gdal.Translate(destName, srcDS, **kwargs)

So use

dem = gdal.Translate("testdata.tif", "testdata.xyz", outputSRS='EPSG:4326')

Following your edit, it appears your .xyz is incomplete and can't be converted directly to raster with GDAL <=3.5.x Either:

  • use gdal.Grid; or
  • Upgrade to GDAL 3.6.1 or later.
1
  • I changed it and again the same
    – TheGame
    Commented Jan 13, 2023 at 19:16

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.