[gdal-dev] Stuck with python gdal.Grid throwing an error

Stephen Woodbridge stephenwoodbridge37 at gmail.com
Fri Jun 14 18:22:10 PDT 2019


Hi,

I can't figure out what I'm doing wrong but gdal.Grid() keeps throwing 
an error and I've run out of things to try and work around the issue.

On Ubuntu using these packages:
gdal-bin:amd64/xenial 2.2.2+dfsg-1~xenial1 uptodate
gdal-data:all/xenial 2.2.2+dfsg-1~xenial1 uptodate
libgdal1i:amd64/xenial 1.11.3+dfsg-3build2 uptodate
libgdal20:amd64/xenial 2.2.2+dfsg-1~xenial1 uptodate
python-gdal:amd64/xenial 2.2.2+dfsg-1~xenial1 uptodate

Error message is:

Traceback (most recent call last):
   File "./process-jason3-ssha.py", line 322, in <module>
     Main()
   File "./process-jason3-ssha.py", line 316, in Main
     processFiles(mf, urlList)
   File "./process-jason3-ssha.py", line 242, in processFiles
     err = gdal.Grid(dataset, ds, options=opts)
   File "/usr/lib/python2.7/dist-packages/osgeo/gdal.py", line 968, in Grid
     return GridInternal(destName, srcDS, opts, callback, callback_data)
   File "/usr/lib/python2.7/dist-packages/osgeo/gdal.py", line 3229, in 
GridInternal
     return _gdal.GridInternal(*args)
RuntimeError: not a string

Code looks like (edited out not esentials):

         track = Dataset(fn, "r")
         track.set_auto_mask(False)

         lat = track.variables['lat']
         lon = track.variables['lon']
         ssh = track.variables['ssha']

         cnt = lat.shape[0]

         ds = ogr.GetDriverByName('Memory').CreateDataSource('wrk')
         lyr = ds.CreateLayer('track', srs=SRS)

         opts = 
gdal.GridOptions(algorithm='linear:radius=50:nodata=32767', \
                 layers='track')

         # QUESTION: should I create point features for NoData track 
points??

         for n in range(cnt):
             wkt = "POINT({} {} {})".format(lon[n]-180., lat[n], ssh[n])
             feat = ogr.Feature(lyr.GetLayerDefn())
             feat.SetGeometryDirectly(ogr.Geometry(wkt=wkt))
             lyr.CreateFeature(feat)

         # dataset is a gtiff opened with GA_Update

         # also tried this
         #err = gdal.Grid(dataset, lyr, options=opts)

         err = gdal.Grid(dataset, ds, options=opts)
         if err != 0:
             print 'gdalGrid error: ', err
             return

The above code is basically the same as what I use for 
gdal.RasterizeLayer() and that worked fine.

-Steve

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the gdal-dev mailing list