2

I am using CRS which has axis in left bottom corner. Code below produce Geotiff which is shown allright in QGIS but when I open it in other software it is upside down. Also gdal_calc takes it as upside down when calculating. Is there some easy way how to make sure this grid will be interpreted right as it is if I create it using gdal_translate from xyz?

geotransform=(min_x,min_cell_size,0,min_y,0,min_cell_size)
nrows,ncols = np.shape(zi)
output_raster = gdal.GetDriverByName('GTiff').Create(output_reaster,ncols, nrows, 1 ,gdal.GDT_Float32)
output_raster.SetGeoTransform(geotransform)
srs = osr.SpatialReference()
srs.ImportFromEPSG(28355)
output_raster.SetProjection(srs.ExportToWkt())
output_raster.GetRasterBand(1).WriteArray(zi)
5
  • The affine geotransform uses the upper left corner as the origin, this is typically minx, maxy. See: gdal.org/gdal_datamodel.html – user10353 Sep 24 '14 at 14:37
  • Not only that, but the last value in the geotransform tuple is usually negative because y decreases with increasing raster row. – sgillies Sep 24 '14 at 15:07
  • @sgillies Thank you, I tried ...max_y,0,-min_cell_size before but so far I have 3 issues with that - 1st I prefer to write it CRS independent because I also sometimes use other CRS which has axis in left top corner. 2nd do I also need to revert lines bottom to top in zi? 3rd when changed to max_y and -min_cell_size my raster is shown in slightly different spot in QGIS - need to double check this again... – Miro Sep 24 '14 at 23:02
  • Possible duplicate of gis.stackexchange.com/questions/24055/… – AndreJ Sep 26 '14 at 6:43
  • @AndreJoost it looks similar though probably because of different wording I was not able to find that one. Also this issue is bit different because in my case file was displayed well in QGIS. – Miro Sep 26 '14 at 7:07
3

I am not able to find some general solutions which would be CRS independent but for my case - axis in left bottom corner - the following changes works:

Start from max_y and use minus value for y cell size:

geotransform=(min_x,min_cell_size,0,max_y,0,-min_cell_size)

Revert the array lines from bottom to top:

zi = zi[::-1,:]

Will be glad if somebody come up with some CRS independent solution. Also when using this code I got often pop up window "python.exe has stopped working" on both my W7/64bit machines. The same happens when using gdal_calc. No idea why is that happening especially because it produces results and when the window is closed it continues without any issue...

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.