0

I have data that I would like to create a GeoTIFF file with. I have the GDAL Python package installed. I also have 3 overlapping matrices with intensity values, latitudes, and longitudes. How can I create a GeoTIFF with that?

Edit: So this is what I am trying to do. Maybe there is a better way to do this. So I have a Geotiff file where the Geotransform is the default [0 1 0 0 0 1]. But there are tie grid points attached to the file. I preformed some segmentation on the image and I would like to replace the intensity values with the segmented image. To do this, the code I am using is :

driver = gdal.GetDriverByName("GTiff")
outdata = driver.Create(outFileName, rows, cols, 1, gdal.GDT_UInt16)

outdata.SetGeoTransform(ds.GetGeoTransform())
outdata.SetProjection(ds.GetProjection())
outdata.GetRasterBand(1).WriteArray(imgarray)
outdata.FlushCache()

outdata = None
band = None
ds = None

Where ds is the existing Geotiff file.

But the problem is this is creating a new Geotiff file where the tie grid points aren't being passed on. Therefore, when I save this new file, the geolocation information would be incorrect.

2
  • This will depend on the coordinates of your latitudes and longitudes. Can you please include an example of them? GeoTIFFs generally use Affine transforms and Coordinate Reference Systems, not arrays of coordinate values, so the trick will be converting between the different spatial representations. Dec 5, 2018 at 0:49
  • First find the minimum and maximum X and Y coordinates (extent), decide on a cell size which will determine the number of rows and columns (Xrange / CellSize = columns, Yrange / Cellsize = rows), create a driver with gdal.GetDriverByName, create from the driver like on gdal.org/gdal_tutorial.html then set the GeoTransform (origin and cell size - y is negative) mentioned on the same page, create or read the entire raster with band.ReadRaster. Iterate through your matrices locating the row/column matching and set that value in the data then band.WriteArray to update the raster. Dec 5, 2018 at 6:06

1 Answer 1

1

So you would like to copy GCPs?

First see this post for how to write GCPs:

In python gdal how to add Ground Control point to GeoTiff image by using gdal_translate

You can then get the GCPs in your source image with ds.GetGCPs

So all together with your example it would be:

outdata.SetGCPs(ds.GetGCPs(), ds.GetProjection())
1
  • Thats exactly what I was looking for. Thanks a lot! Dec 5, 2018 at 23:46

Your Answer

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

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