ERROR 4: `OSM_lines.gmt' not recognized as a supported file format

Hi all,
When reading an input data file using the following grdmath input command:

gmt grdmath OSM_lines.gmt -R-180/180/-89/89 -A0/0/4 -I30m LDIST = dist.nc

I get an error message:

ERROR 4: `OSM_lines.gmt’ not recognized as a supported file format.
grdmath (api_import_grid): Not a supported grid format [OSM_lines.gmt]
[Session gmt (0)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)
[Session gmt (0)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)

The file was originally a shapefile converted to GMT format using ogr2ogr and looks like this, (note line numbers in first column not part of file):

Trying to read the original shapefile through GDAL using command:

gmt grdmath lines.shp=gd -R-180/180/-89/89 -A10/0/4 -I30m LDIST = dist.nc

also gives error message:

ERROR 4: `lines.shp’ not recognized as a supported file format.
grdmath [ERROR]: Unable to open lines.shp.
grdmath [ERROR]: ERROR reading file (metadata) with gdalread.
grdmath (api_import_grid): Could not open file [lines.shp=gd]
[Session gmt (0)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)
[Session gmt (0)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)

From the documentation I cannot see why the ASCII file (.gmt) cannot be recognized by grdmath, but are there any suggestions to other formats I rather should use?

Looks like we failed to add -a to grdmath. Workaround will be

gmt convert OSM_lines.gmt > tmp.txt

and then use tmp.txt instead. I will open an issue to get -a added.

Actually should work since you are not using the aspatial data. But I think you need to move the OSM_lines.gmt file to be the argument before LDIST, not before all the -R options.

Thanks Paul, that seems to solve the case!

Not tested but in Julia this should have worked

using GMT
D = gmtread("path/to/the_file.shp");
gmt("grdmath -R-180/180/-89/89 -A10/0/4 -I30m ? LDIST = dist.nc", D)

Repo has been updated to be more tolerant of operator-operand splitting as in the example below, plus added -a to read shape files directly.

Hi Joaquim, is the gmtread command part of the documentation (I cannot find it there)?

Anyhow I tried your suggested input which unfortunately produced error message:

julia> D = gmtread(“lines.shp”);
julia> gmt(“grdmath -R-180/180/-89/89 -A10/0/4 -I30m ? LDIST = dist.nc”, D)
Error happens in Julia.
grd_init: input (Array{GMT.GMTdataset,1}) is not a GRID container type
Stacktrace:
[1] grid_init(::Ptr{Nothing}, ::Bool, ::Array{GMT.GMTdataset,1}, ::UInt32) at /home/fg/.julia/packages/GMT/IialV/src/gmt_main.jl:847
[2] GMTJL_Set_Object(::Ptr{Nothing}, ::GMT.GMT_RESOURCE, ::Array{GMT.GMTdataset,1}) at /home/fg/.julia/packages/GMT/IialV/src/gmt_main.jl:770
[3] gmt(::String, ::Array{GMT.GMTdataset,1}) at /home/fg/.julia/packages/GMT/IialV/src/gmt_main.jl:231
[4] top-level scope at none:0
[5] eval(::Module, ::Any) at ./boot.jl:328
[6] eval_string(::String) at /home/fg/R/x86_64-pc-linux-gnu-library/3.6/JuliaCall/julia/setup.jl:195
[7] docall(::Ptr{Nothing}) at /home/fg/R/x86_64-pc-linux-gnu-library/3.6/JuliaCall/julia/setup.jl:168

No, gmtread is a julia goody (and Matlab MEX too), Not in command line GMT. It happens that the version in Julia knows how to read shapefiles directly.

But the error you got is, sorry forgot about that, normal. In 6.0.0 grdmath can only read grids from externals (like the Julia wrapper). That is already fixed but needs the GMT dev version.

Ok, but I think I already got a late dev. version: Version 6.1.0_88fbed1_2020.03.06. Is it not implemented in this one?

Probably not (for very few days). See https://github.com/GenericMappingTools/gmt/pull/2859