1

I am currently using GDAL 2.1.0 in a Python script to reproject a geotiff with a given pixel size into an other geotiff with the same projection, but with a different pixel size. To do so, I use the following GDAL function:

     gdal.ReprojectImage(in_dataset, out_dataset, in_srs.ExportToWkt(),    
                         out_srs.ExportToWkt(), gdalconst.GRA_Average)

Is there any way I can control how the resampling option provided by gdalconst deals with the edges of my image?

In this case, I end up with the new image that has the 2 first rows, the last row, the first column and the last column with a value of 0 (i.e. around the edge of my reprojected image). And this can be more depending on the resampling method. Below, the first picture is the original image on a Google Map in a GIS and the second is the reprojected image showing the border.

enter image description hereReprojected

For the moment, I convert the edge pixels to NaNs through indexing:

myarray = np.pad(myarray[2:-2, 2:-2], ((2,2),(2,2)), mode='constant',
                 constant_values=(np.nan,))

but I feel this isn't the best way to deal with it and am hoping there is an in-built solution (as it is the case for other libraries such as astropy's convolute).

Maxim L
  • 497
  • 4
  • 15
  • What GDAL version? – user30184 May 30 '18 at 16:58
  • Added the version in the text: 2.1.0 – Maxim L May 30 '18 at 17:06
  • Can it be that the original image has nodata value set? If so QGIS handles nodata as transparency by default, so the black border is not seen on the first image – dr_times May 31 '18 at 13:11
  • Maybe look at this : https://gis.stackexchange.com/questions/271226/up-sampling-increasing-resolution-raster-image-using-gdal?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Baptiste Cautain May 31 '18 at 14:05
  • Or look at the Gdal Wrap tool (http://www.gdal.org/gdalwarp.html) – Baptiste Cautain May 31 '18 at 14:12
  • Its a bit difficult for me to see what your problem is. Your two maps are not of the same extent, so I am unsure if the 0 values are meant to have any values at all?. Nevertheless, I am using GDAL 2.2.3 and it is possible to specify what re-sampling technique you want to use (i.e. gdal.ReprojectImage(inData, outData, from_coord.ExportToWkt(), to_coord.ExportToWkt(), gdal.GRA_NearestNeighbour) for the nearest neighbour technique). You can also consult http://gdal.org/python/osgeo.gdalconst-module.html for more options on re-sampling techniques – Jascha Muller May 31 '18 at 20:28

0 Answers0