Setting up PostgreSQL & PostGIS

I wanted to make a custom printed map to give it as a present. I quickly found that Mapbox Studio Classic is an good tool for that which is easy to learn.

For some reasons I was not completely satisfied with the map data that Mapbox provides. This is why I wanted to work with my own map data, hosted in a PostgreSQL/PostGIS database (PostGIS is an extension to PostgreSQL. In the following is how I set up my DB

I installed PostgreSQL and the PostGIS extension via homebrew (I am using a Mac. On Linux you could youse your packet manager).:

brew install postgresql postgis

Here I found out how to start the PostgreSQL server:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Then I could set up the database user and the database itself:

createuser --superuser gisuser
createdb -E UTF8 -O gisuser gis
psql --username=gisuser --dbname=gis -c "CREATE EXTENSION postgis;"
psql --username=gisuser --dbname=gis -c "CREATE EXTENSION postgis_topology;"

To test whether everything worked as expected one can connect to the db:

psql --username=gisuser --dbname=gis

and inside the db prompt one can list the extensions:

gis-# \dx
                                         List of installed extensions
       Name       | Version |   Schema   |                             Description                             
 plpgsql          | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis          | 2.1.7   | public     | PostGIS geometry, geography, and raster spatial types and functions
 postgis_topology | 2.1.7   | topology   | PostGIS topology spatial types and functions
(3 rows)

And finally the OSM data can be imported:

osm2pgsql -s -U gisuser -d gis ~/Downloads/rotterdam_netherlands.osm.pbf

This can take a while, and at this point I was glad that I only downloaded the map data of Rotterdam, and not of whole Netherlands, or the Planet.

Dieser Beitrag wurde unter Allgemein veröffentlicht. Setze ein Lesezeichen auf den Permalink.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

Du kommentierst mit Deinem Abmelden / Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s