7

I'm attempting to export a PostGIS (1.5.3) database table as a File geodatabase using the new FileGDB OGR / GDAL 1.9.0 driver:

$ ogr2ogr -overwrite -sql "SELECT * from db_pts LIMIT 1" \
    -f "FileGDB" /tmp/test.gdb \
    PG:"host='HOST' dbname='DB'"

I get this error:

ERROR 1: Error (-1): FGDB layers cannot be created with a wkbUnknown layer geometry type.
ERROR 1: Terminating translation prematurely after failed translation from sql statement.

The geometry column in the table I'm exported is set up properly and is in the geometry_columns table. I think the problem has to do with the way the -sql option is returning the layer geometry type. For example, accessing the same database table with ogrinfo:

$ ogrinfo -ro -sql "SELECT * from db_allobs LIMIT 1" PG:"host=HOST dbname='DB'"
Layer name: sql_statement
Geometry: Unknown (any)
Feature Count: 1
...
OGRFeature(sql_statement):0
...
  POINT (-151.472835 69.635245)

It's as though the query doesn't look in geometry_columns when building the layer, but later, when exporting the rows it knows that the geometry being exported is a POINT (in this case).

When I use a similar command to produce a shapefile, all is well, including the layer geometry, which is set to point.

Anyone have any ideas?

  • 1
    Sorry for the bad form, but the answer is to add the -nlt option, which allows you to set the layer type when -sql is used. I found this at: trac.osgeo.org/gdal/ticket/4186 In other words: ogr2ogr -overwrite -sql "SELECT * from db_pts LIMIT 1" -f "FileGDB" /tmp/test.gdb PG:"host='HOST' dbname='DB'" -nlt POINT Sorry for the traffic. – cswingle Feb 1 '12 at 23:26
  • you should put this as an answer so I can vote it up. – Ragi Yaser Burhum Feb 2 '12 at 0:23
  • I agree with Ragi, and it means you can mark the question as answered. – MerseyViking Feb 2 '12 at 11:39
6

Sorry for the bad form, but the answer is to add the -nlt option, which allows you to set the layer type when -sql is used. I found this at http://trac.osgeo.org/gdal/ticket/4186.

In other words:

ogr2ogr -overwrite -sql "SELECT * from db_pts LIMIT 1" \
        -f "FileGDB" /tmp/test.gdb \
        PG:"host='HOST' dbname='DB'" -nlt POINT
2

I know this is an old question, but it may help someone else. I had an issue when converting the SRID. I was able to resolve this by casting the geometry column to the specific type. ie:

SELECT st_transform(g.geom, 998998)::geometry(Point,998998) AS wkb_geometry
  • Thanks for posting this, I was having problems with a view with no SRID nor GEOMETRY TYPE in my geometry_columns view. Defining the view the way you say, solved everything! – Germán Carrillo Nov 1 '16 at 16:51

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.