Skip to content

Commit

Permalink
Clarify SETUP_DATABASE
Browse files Browse the repository at this point in the history
  • Loading branch information
codesoap committed Sep 28, 2020
1 parent a03defc commit e01c85b
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions SETUP_DATABASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,35 @@ osm2pgsql
# Setting up PostreSQL
```bash
initdb -D data

# Start the database server; leave this running and contiue in another
# terminal:
postgres -D data

createdb gis
psql -d gis -c 'CREATE EXTENSION postgis;'
```

# Transforming data
Schema reference: https://wiki.openstreetmap.org/wiki/Osm2pgsql/schema
# Filling the database with osm data
Use one of the following two code blocks to get started. When everything
worked out, you can start playing around with bigger `*.pbf` files,
like Sweden, the USA or even the whole planet. You can find those at
[download.geofabrik.de](https://download.geofabrik.de) and
[planet.osm.org](https://planet.osm.org).

Azores (nice and small; good for quick testing):
```bash
# Download the osm data:
wget 'https://download.geofabrik.de/europe/azores-latest.osm.pbf'
wget 'https://download.geofabrik.de/europe/serbia-latest.osm.pbf'

# Takes ~30s; turns the ~10MB into ~300MB:
# Takes ~30s; turns the ~10MB *.pbf file into a ~300MB database:
osm2pgsql --create --database gis azores-latest.osm.pbf
```

# Takes ~15min; turns the ~100MB into ~3.9GB:
Serbia (a little bigger, but still good for testing on a simple laptop):
```bash
wget 'https://download.geofabrik.de/europe/serbia-latest.osm.pbf'

# Takes ~15min; turns the ~100MB *.pbf file into a ~3.9GB database:
# --number-processes 1 seems to be necessary since max_connections in
# data/postgresql.conf is limited to 20 on OpenBSD.
osm2pgsql \
Expand All @@ -43,7 +55,12 @@ osm2pgsql \
serbia-latest.osm.pbf
```

# Example queries
# Example queries (you can skip this)
To make sure everything works, you can use queries like the following
ones. Enter these into a PostreSQL shell. Such a shell can be opened
with `psql -d gis`. Make sure the PostreSQL server is running
(`postgres -d data`).

Finding cinemas in Belgrade:
```sql
SELECT osm_id, name FROM planet_osm_point
Expand All @@ -57,3 +74,5 @@ SELECT osm_id, name, ST_AsText(ST_Transform(way, 4326)) FROM planet_osm_point
WHERE shop = 'bicycle'
AND way && ST_Transform(ST_GeomFromText('POLYGON((8.7968 53.1037, 8.8142 53.1037, 8.8142 53.0834, 8.7968 53.0834, 8.7968 53.1037))', 4326), 3857);
```

Schema reference: https://wiki.openstreetmap.org/wiki/Osm2pgsql/schema

0 comments on commit e01c85b

Please sign in to comment.