2

The Ogr2Ogr doc says:

GetLayerDefinition a_layer_name” and “GetLayerMetadata a_layer_name” can be used as special SQL requests to get respectively the definition and metadata of a FileGDB table as XML content (only available in Geodatabases created with ArcGIS 10 or above)

I'm able to connect, since this works:

ogrinfo -so -q -nogeomtype /path/to/myfile.gdb

However when I try this:

ogr2ogr -dialect OpenFileGDB -sql "SELECT GetLayerMetadata(myfeatureclass)" /path/to/myfile.gdb

It says: FAILURE: no source datasource provided

With ArcGIS Pro, I can see the metadata for the featureclass.

Are there any examples for this somewhere?

9
  • Try ogrinfo -sql "SELECT GetLayerMetadata myfeatureclass" /path/to/myfile.gdb. Does that throw an error? – user30184 May 5 at 14:59
  • Thanks, but still fails. – Kirk Kuykendall May 5 at 15:06
  • 2
    Sorry, we both need to concentrate. There is nothing in the documentation about (), nor about select. This works for me ogrinfo -sql "GetLayerMetadata counties" TemplateData.gdb. Usage example can be found from the GDAL autotests github.com/OSGeo/gdal/blob/master/autotest/ogr/…. – user30184 May 5 at 15:20
  • 1
    That works, removing the SELECT statement is key. Not sure why they call it SQL. Please add your comment as an answer and I'll mark as answered. Thanks! – Kirk Kuykendall May 5 at 15:26
  • 1
    Not all SQL begins with SELECT. Think about CREATE TABLE etc. – user30184 May 5 at 15:28
2

There are couple of issues in the original command.

  1. The ogr2ogr utility converts vector data from source format into target format. It is possible to use ogr2ogr but then both datasource and target must be defined. However, ogrinfo might be better tool for making the metadata query.
  2. The syntax of the two "SQL requests" which are special for the OpenFileGDB driver must be read literally https://gdal.org/drivers/vector/openfilegdb.html#special-sql-requests. The documentation should probably call those as "SQL statements" to make it more clear that they are used as they stand, not together with the SELECT statement like many functions. In the syntax of the statements the layer name is separated from the SQL statement by a space, not enclosed between brackets.

Special SQL requests

GetLayerDefinition a_layer_name” and “GetLayerMetadata a_layer_name” can be used as special SQL requests to get respectively the definition and metadata of a FileGDB table as XML content (only available in Geodatabases created with ArcGIS 10 or above)

A correct syntax for ogrinfo:

ogrinfo -sql "GetLayerMetadata counties" TemplateData.gdb

A correct syntax for ogr2ogr:

ogr2ogr -f gml -sql "GetLayerMetadata counties" metadata.gml TemplateData.gdb

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.