OGR2OGR Spatialite – How to Rename OGR2OGR Tables on Export to Spatialite

exportogr2ogrspatialitesqlite

I'm exporting data from PostGIS to Spatialite using ogr2ogr. The export is working properly, except I need to be able to rename the tables that are being exported. Here's the command I'm using:

ogr2ogr -f "SQLite" testSQLite.sqlite -progress PG:"host=127.0.0.1 dbname=mydb user=admin password=myPassword active_schema=my_schema schemas=my_schema tables=building_shared,alarm_shared" -lco LAUNDER=yes -dsco SPATIALITE=yes -lco SPATIAL_INDEX=yes -overwrite

This exports a Spatialite database with two tables – building_shared and alarm_shared. I want the two tables to be named building and alarm. I tried adding the following SQL query to the end of the command, with no luck:

-sql "SELECT * FROM building_shared AS building"

How do I rename the tables on export?

Best Answer

From the ogr2ogr docs, use the -nln name option to assign an alternate name to the new layer.

Related Question