Report this

What is the reason for this report?

How to import Geopackages into Postgres/Postgis database?

Posted on December 16, 2019

Hi everyone,

I would like to know how to import a Geopackage file containing raster into a Postgis database. I tried with gdal library “ogr2ogr”.

This is the command line I used:

ogr2ogr -f PostgreSQL PG:"dbname='databasename' host='addr' port='5432' user='x' password='y'" path_name\geopackage_name.gpkg

I use a server Ubuntu 18.04 LAMP with postgres/postgis and I would like to import geopackage from my PC (Ubuntu 19.10 + Qgis + Postgresql 10 + gdal library installed).

Greeting, Giuseppe



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

I think that your firewall might be blocking your connections on port 5432, so I would suggest running the command locally from your Droplet.

What you should usually do is:

  • SSH to your Droplet

  • Download data for the whole world or by country. You can download it from here:

https://gadm.org/download_world.html

To download the package you could run:

wget https://biogeo.ucdavis.edu/data/gadm3.6/gadm36_levels_gpkg.zip
unzip gadm36_levels_gpkg.zip

Note: the URL might change so it is best to go to the gadam.org website and get the latest version from there.

  • Create a PostgreSQL database if you don’t already have one.

  • Install the PostGIS extension:

CREATE EXTENSION postgis;
  • Import the data with ogr2ogr with the command that you’ve provided:
ogr2ogr -f PostgreSQL PG:"dbname='databasename' host='addr' port='5432' user='x' password='y'" path_name\geopackage_name.gpkg

Note: You might have to install the ogr2org command if you don’t have it installed already:

npm install ogr2ogr

Hope that this helps!

Regards, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.