0

I use the gdal_grid interpolation command. When I work in the terminal everything works perfectly. However, when I try to run the command in the bash script from cron then it does not work.

Bash script (/root/interpolation/interpolation.sh):

#!/bin/bash

gdal_grid -ot Float64 -of GTiff -outsize 750 750 -a invdist:power=2.0:smoothing=0.0:radius1=0.08:radius2=0.08:angle=0.0:max_points=0:min_points=0 /root/interpolation/today.vrt /root/interpolation/out/today.tif

I also tried the path to gdal_grid

#!/bin/bash

/usr/bin/gdal_grid -ot Float64 -of GTiff -outsize 750 750 -a invdist:power=2.0:smoothing=0.0:radius1=0.08:radius2=0.08:angle=0.0:max_points=0:min_points=0 /root/interpolation/today.vrt /root/interpolation/out/today.tif

Virtual file (/root/interpolation/today.vrt)

<OGRVRTDataSource>
<OGRVRTLayer name="today">
    <SrcDataSource>/root/interpolation/today.csv</SrcDataSource>
    <GeometryType>wkbPoint</GeometryType>
<LayerSRS>WGS84</LayerSRS>
    <GeometryField encoding="PointFromColumns" x="X" y="Y" z="eto"/>
</OGRVRTLayer>

CSV (/root/interpolation/today.csv)

id,X,Y,eto
1,17.11400986,43.59461212,5.284
2,16.01515388,44.38002777,5.636
3,19.3653698,44.19543839,6.823
4,17.25690269,44.1989975,6.041
5,18.53639221,43.60323715,6.452
6,16.9213295,45.12902069,6.95
...

CRON

PATH='/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin'

39 10 * * * /root/interpolation/interpolation.sh 

Error

Usage: gdal_grid [--help-general] [--formats]
[-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/
      CInt16/CInt32/CFloat32/CFloat64}]
[-of format] [-co "NAME=VALUE"]
[-zfield field_name]
[-a_srs srs_def] [-spat xmin ymin xmax ymax]
[-clipsrc <xmin ymin xmax ymax>|WKT|datasource|spat_extent]
[-clipsrcsql sql_statement] [-clipsrclayer layer]
[-clipsrcwhere expression]
[-l layername]* [-where expression] [-sql select_statement]
[-txe xmin xmax] [-tye ymin ymax] [-outsize xsize ysize]
[-a algorithm[:parameter1=value1]*]    [-q]
<src_datasource> <dst_filename>

Available algorithms and parameters with their's defaults:
Inverse distance to a power (default)
    invdist:power=2.0:smoothing=0.0:radius1=0.0:radius2=0.0:angle=0.0:max_points=0:min_points=0:nodata=0.0
Moving average
    average:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=0.0
Nearest neighbor
    nearest:radius1=0.0:radius2=0.0:angle=0.0:nodata=0.0
Various data metrics
    <metric name>:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=0.0
    possible metrics are:
        minimum
        maximum
        range
        count
        average_distance
        average_distance_pts

FAILURE: Neither -sql nor -l are specified

Note that it works in the terminal but it does not work in cron. Does anyone know what the problem is?

  • 1
    it is correct you haven't specified a -l or -sql - if it works on the command line it may be a version issue - try gdal_grid --version in both places – Ian Turton Jun 4 at 10:05
  • Yes! The problem was in two versions of gdal. The gdal environment on the terminal is set to a newer version, while CRON launches the old version. I solved the problem so that I added the path to new versions gdal in bash script. Tnx ian Turton – kamfulebu Jun 4 at 13:39
  • please add this as an answer for future readers – Ian Turton Jun 4 at 13:40
0

I solved, @Ian Turton answer helped me to solve the problem. The problem was in two versions of gdal. In the terminal, the environment is set to a newer version of gdal 2.1.3 (/root/miniconda2/bin). CRON runs an older version of gdal 1.10.1 (/usr/bin). I solved this problem by setting up a path to the new version of gdal in the bash script.

#!/bin/bash

/root/miniconda2/bin/gdal_grid -ot Float64 -of GTiff -outsize 750 750 -a invdist:power=2.0:smoothing=0.0:radius1=0.08:radius2=0.08:angle=0.0:max_points=0:min_points=0 /root/interpolation/today.vrt /root/interpolation/out/today.tif

Thank you Ian

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.