Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
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
add comment

1 Answer

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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