RustProof Labs: blogging for education (logo)
My book Mastering PostGIS and OpenStreetMap is available!

Webinar: Load PostGIS with osm2pgsql (2/6)

By Ryan Lambert -- Published January 27, 2020

Below is the recording of my Load PostGIS with osm2pgsql webinar from January 14, 2020. This is the second in a series of six covering how I work with PostGIS and OpenStreetMap.

I had a great time presenting this session, I hope having this recording available is helpful. Below the video is a list the links showing throughout the slides.

Recording

Series complete

This webinar series is completed. See the intro page for the schedule and links to other videos in the series.

Links

Links from the slides in the order they appeared. Sorry for the lack of context in this list right now, I will try to come back to this and provide more context in the future.

Helper Bash Script

#!/bin/bash

########################################################
#
# Where CLI parameters are: <sub-region> <cache> <processes>
#
# Quickest to load, helpful for testing:
#       ./load_osm.sh colorado 1000 1 &> load_co_osm.log &
#
########################################################

SECONDS=0

echo "Start on `hostname` at `date`"
echo "Running Sub-Region:  $1"

echo "Creating pgosm DB..."
psql -d postgres -c "CREATE DATABASE IF NOT EXISTS pgosm;"

echo "Creating PostGIS and HSTORE extensions..."
psql -d pgosm -c "CREATE EXTENSION IF NOT EXISTS postgis; "
psql -d pgosm -c "CREATE EXTENSION IF NOT EXISTS hstore; "

echo "Ensuring ~/tmp exists..."
mkdir ~/tmp || true

echo "Downloading OSM file"
wget https://download.geofabrik.de/north-america/us/$1-latest.osm.pbf -O ~/tmp/$1-latest.osm.pbf

echo "Starting osm2pgsql for $1: `date`"
echo "cache: $2"
echo "Num processes: $3"
osm2pgsql --create --slim --drop \
  --cache $2 \
  --number-processes $3 \
  --hstore \
  --multi-geometry \
  -d pgosm ~/tmp/$1-latest.osm.pbf

echo "osm2pgsql completed for $1 on host `hostname` at: `date`"

duration=$SECONDS
echo "Total Duration:  $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."

Summary

Need help with your PostgreSQL servers or databases? Want a speaker on the technologies and data I am excited about? Contact us to start the conversation!

By Ryan Lambert
Published January 27, 2020
Last Updated June 17, 2020