1

While writing some data to a GeoPackage, I set the wrong Coordinate System.

The Actual Coordinates are in a Particular UTM System, but the Table has been set as having data in EPSG:4326.

How do I now change the SRID of the data, without transforming the Coordinates?

I want to do the same thing as Changing SRID of existing data in PostGIS? but for a GeoPackage.

2

You can fix it using ogrinfo or sqlite3 by running the following for ogrinfo. You will need to replace ocurences of 3857 by your own SRID code and my_table_name ocurences with your own table name too

# Work well because only one geometry column for table name
ogrinfo my.gpkg \
       -sql "UPDATE gpkg_geometry_columns SET srs_id = 3857 WHERE table_name = 'my_table_name'" \
       --config OGR_GPKG_FOREIGN_KEY_CHECK OFF
# Dialect SQLite to get the SetSRID function available
ogrinfo my.gpkg -dialect SQlite -sql "UPDATE my_table_name set geom = SetSRID(geom, 3857)"

and with sqlite3 command line:

sqlite3 my.gpkg "UPDATE gpkg_geometry_columns SET srs_id = 2154 WHERE table_name = 'my_table_name'"
sqlite3 my.gpkg "select load_extension('mod_spatialite');UPDATE my_table_name set geom = SetSRID(geom, 3857);"
1

Note: Back up your data beforehand.

In QGIS open the Processing Toolbox and go to Vector General > Assign projection.

Select that layer and assign the correct projection.

Leave the output as [Create temporary layer].

Run the tool and make sure the output is correct.

Remove the original layer and overwrite it with the output (only if you have made a backup), or else save the output as a new layer in the geopackage.

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.