Upload GeoPackage (.gpkg) file to PostGIS
Last updated on August 20, 2022.
GeoPackage is a spatial data format compatible with SQLite. Lots of GIS data comes in GeoPackage formats, so it's important to be able to convert it to other file formats and upload it into your spatial database for processing, potentially in machine learning and data science workflows.
Lots of useful files come as
.gpkg files, including GADM administrative country maps. The GeoPackage file format was actually initially designed for mobile applications, and conveniently allows for opening GeoPackage files in SQLite.
Below, anyone can upload a GeoPackage file before downloading it as an .sql file. If you self-host your database, you could upload that .sql file via
psql or opt to host the database on Bunting GIS on the free trial.
GeoPackage Format Support:
- CRS automatically detected (WGS84 default)
Once the file is converted to PostGIS, you can either download the file as
.sql and upload to your database with
psql, or host the file with us for free. This file fits on our free plan, which is under 128MB of storage and shared compute time. Larger datasets can be stored for $2.50/GB/month.
Uploading to PostGIS (self-host)
To load your .psql file into your PostGIS instance (local, Amazon RDS, or other), you can use the
psql command line tool.
psql -U postgres -h localhost -d postgres -f downloaded_file.sql
Database Connection (managed)
If you choose Bunting as your host, connect to the PostGIS database with your username and password:
psql -W -U username --dbname data_gis \
Connection can also be made through GeoDjango or GeoPandas, like so:
from sqlalchemy import create_engine
db_connection_url = "postgresql://username:[email protected]:5432/data_gis"
con = create_engine(db_connection_url)
sql = "SELECT geom, highway FROM target_table"
gdf = geopandas.GeoDataFrame.from_postgis(sql, con)