Loading GeoPackage into a database
Last updated
Last updated
The following page provides instructions on how to load GeoPackage datasets into PostgreSQL.
Requirements:
A development platform for PostgreSQL (for example, pgAdmin or dBeaver)
A PostgreSQL database
PostGIS extension
GDAL
Access to a Command Prompt or similar
A GeoPackage dataset
There are various ways of loading a GeoPackage into PostgreSQL. The following step-by-step instructions run through using GDAL / Command Prompt to do this.
Open your chosen development platform, for example, dBeaver (this can be found by going to Windows Start Menu > PostGreSQL).
Either connect to an existing database or create a new database. It is recommended that the encoding is set to UTF-8. We will return to the PostgreSQL development platform later.
Open the Command Prompt by clicking the Start button in the bottom left-hand side of the screen and typing cmd into the search bar.
The Command Prompt will appear.
Change the directory of the Command Prompt app if necessary. The directory needs to point to the folder where the GeoPackage is stored. For this example, the GeoPackage to be loaded into PostgreSQL is stored in a C:\Temp folder.
In the Command Prompt, type cd followed by the directory of the location of the GeoPackage. Press Enter on the keyboard. This will change the directory.
Enter the command:
username, password, database and host can all be found within the subsequent database.
coordinate_system is the EPSG of the data to be loaded, for example, to load into British National Grid, the EPSG is 27700.
data_name is the name of the GeoPackage to be loaded. Example:
Open your chosen development platform (for example, dBeaver) by going to Start > dBeaver.
Under Database Navigator, move to the database you loaded data into and expand the schema. Using the code above, the GeoPackage should be in your default schema (shown in bold).
The GeoPackage will now appear as new tables / a new table in the schema nominated as default. Nominate a schema by adding the following text to the command noted in step 7: active schema=<schema>
schema can be found within the subsequent database.
Once loaded, you may want to add Primary and Foreign Keys to the data. These can only be added on columns where the data values are unique. Where there are no unique data values, an index may be added, which will aid searching.