5

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?

1 Answer 1

11

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

3
  • 3
    I believe that for being able to use -nln you must convert one table at a time. For adding new tables into an existing Spatialite database add -append parameter and remove the -dsco one.
    – user30184
    Aug 28, 2014 at 4:42
  • 2
    Related to previous comment, not original question: For new tables in existing SpatiaLite DB use -update. Use -append to add rows to an existing table. Sep 29, 2015 at 16:03
  • I can confirm -nln works well when uploading ESRI FileGeodatabase feature classes to postgres
    – Theo F
    Aug 21, 2019 at 11:34

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.