0

I would like to use ogrinfo.exe through a command line to query the SRID of a layer (e.g., polygon layer) inside an ESRI GDB. Similarly to SpatialReference.GetAuthorityCode() when using GDAL Python package.

I saw the GDAL documentation about OGR layer SQL functions here.

My understanding was that ogr_layer_SRID() function operates on a layer name, therefore I tried the following:

ogrinfo.exe file_name.gdb -dialect SQLite -sql "SELECT ogr_layer_SRID(Layer_Name) as SRID"

But I had the error below:

ERROR 1: In ExecuteSQL(): sqlite3_prepare_v2(SELECT ogr_layer_SRID(layer_name) as SRID): no such column: layer_name

I then tried the below query, which uses the "shape" column as the function argument, but it is trying to return the SRID for each record of the layer instead of the layer SRID:

ogrinfo.exe file_name.gdb -dialect SQLite -sql "SELECT ogr_layer_SRID(shape) as SRID FROM Layer_Name"

...returning the error below:

ERROR 1: VirtualOGR: OGR2SQLITE_ogr_layer_SRID(): Invalid argument type

and something like the below for each record:

OGRFeature(SELECT):3420 SRID (String) = (null)

4
  • does not ogrinfo return the CRS as part of it's standard output?
    – Ian Turton
    Feb 16, 2022 at 10:58
  • Hi Ian. Yes, it does return the CRS, but this needs to be parsed. Therefore, my understanding was that I could just query for the SRID (if any), like when using SpatialReference.GetAuthorityCode(), because I need to use the info to undertake further steps but I cannot use the Python package. This way the code would be cleaner, i.e., without the need for parsing the PROJCRS.
    – PhilpM
    Feb 16, 2022 at 11:08
  • 1
    Do not change the syntax from the documented one SELECT ogr_layer_SRID('poly'). 'poly' is not the same as poly, the first is a string, the latter a name of an attribute.
    – user30184
    Feb 16, 2022 at 11:54
  • It worked, it was a silly mistake. Thank you @user30184!
    – PhilpM
    Feb 16, 2022 at 14:21

1 Answer 1

1

The correct syntax is the following:

ogrinfo.exe file_name.gdb -dialect SQLite -sql "SELECT ogr_layer_SRID('Layer_Name') as SRID"

Where the ogr_layer_SRID argument is a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.