Reputation: 65
I am trying to convert lots of xyz file to raster, using gdal.Translate in Spyder. But I came across several problems.
I first try with convert only one xyz file. Code is like:
import os
from osgeo import gdal,osr
xyz = '1x1m_678494.xyz'
xyzraster = '1x1m_678494.tif'
translateoptions = gdal.TranslateOptions(projWin='EPSG:3879')
gdal.Translate(xyzraster,xyz,options=translateoptions)
the result is i can get a tif file, but without spatial reference. And there was no error or warning message. Then i thought it might relate to the gdal package. i found some similar issues here https://gis.stackexchange.com/questions/142215/gdal-translate-projection-errorhttps://github.com/conda/conda/issues/4050,I did set the GDAL_DATA to the path 'C:\Program Files\Anaconda3\Library\share\gdal'. This didn't solve my problem. checked my gdal version is 2.3.3 with python 3.7.3. I am trying to remove this gdal and install the newest version gdal 3.0.4 using conda. But there seems to be a incompatible issue.
In the same time, i found there is also independent install for GDAL, http://cartometric.com/blog/2011/10/17/install-gdal-on-windows/. This tutorial has one step to set the GDAL_DATA and GDAL_DRIVER_PATH, but the paths are different from the GDAL_DATA installed by conda. I am very confused. Will the independent installed gdal works different from the conda installed gdal? Or i just need one of them?
Then i leave the spatial reference issue behind, and tried convert multiple xyz to a geotiff. But got some other issues. code is like:
import os
import gdal
import glob
path = 'D:\\Data\\1m\\'
gdal.BuildVRT(path+'out.vrt',glob.glob(path+'\\*.xyz'))
gdal.Translate(path+'out.tif',path+'out.vrt')
The error is ValueError: Received a NULL pointer.
Can anyone help me out, please?
Upvotes: 1
Views: 1685
Reputation: 1
** gdal.TranslateOptions(projWin=(zip(ulx,uly,lrx,lry)),projWinSRS='EPSG:3879') Is where the first part went wrong.
Upvotes: 0