Skip to content

Installing imposm using postgres.app and osm bright from mapbox

nvkelso edited this page Nov 30, 2012 · 2 revisions

Up to Tutorials »

Installing Imposm Using Postgres.app and osm-bright from MapBox

From: Nate Irwin and Mamata Akella, National Park Service

Clone MapBox OSM-Bright GitHub project

We typically download items and run tools through a "Development" folder on our Hard Drive

cd /Development
git clone https://github.com/mapbox/osm-bright.git
  1. Once osm-bright is loaded open the osm-bright folder and change db_conf in imposm-mapping.py to:
db_conf = Options(
  db='osm',
  host='localhost',
  port=5432,
  user='YOUR USERNAME',
  password='YOUR PASSWORD',
  sslmode='allow',
  prefix='osm_new_',
  proj='epsg:900913',
)

Install imposm

Imposm has some dependencies that need to be installed before installing the tool

  • Install psycopg2: sudo easy_install psycopg2
  • Install tokyo-cabinet, geos, and protobuf: brew install tokyo-cabinet geos protobuf
  • Install imposm: sudo easy_install imposm

Install Postgres and PostGIS 2

  • Download from Postgres.app (postgresapp.com)

Update pg_hba.conf:

Put this text at the bottom of the /Applications/Postgres.app/Contents/MacOS/share/pg_hba.conf file, replacing the sample text that is already there:

# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records.  In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.

local all postgres trust

TYPE DATABASE USER ADDRESS METHOD

"local" is for Unix domain socket connections only

local all all trust

IPv4 local connections:

host all all 127.0.0.1/32 trust

IPv6 local connections:

host all all ::1/128 trust

Create DB

Run the following in Terminal, one line at a time (we tried this as a script, but it was failing so we tried one line at a time and it worked):

set -xe

createuser -U npmap --no-superuser --no-createrole --createdb osm

createdb -U npmap -E UTF8 -O osm osm

psql -d osm -f /Applications/Postgres.app/Contents/MacOS/share/contrib/postgis-2.0/postgis.sql

psql -d osm -f /Applications/Postgres.app/Contents/MacOS/share/contrib/postgis-2.0/spatial_ref_sys.sql

echo "ALTER TABLE geometry_columns OWNER TO osm; ALTER TABLE spatial_ref_sys OWNER TO osm;" | psql -d osm

echo "ALTER USER osm WITH PASSWORD 'osm';" | psql -d osm

echo "host osm osm 127.0.0.1/32 md5" >> /Applications/Postgres.app/Contents/MacOS/share/pg_hba.conf

set +x

echo "Done. Don't forget to restart postgresql!"

Load the data

  1. Download the necessary OSM files from download.geofabrik.de
  2. Change directory. We downloaded the osm-bright template from MapBox so our imposm-mapping.py lives there. We modified the script to extract the features we want: cd /Development/osm-bright
  3. To load multiple OSM downloads into one database, first read in the data (one download at a time changing the ~/Downloads path for each import): imposm -U npmap -d osm -m imposm-mapping.py --read --merge-cache ~/Downloads/us-midwest.osm.pbf
  4. Next, write the data stored in the cache to the OSM database: imposm -U npmap -d osm -m imposm-mapping.py --write --optimize --deploy-production-tables
  5. If you are only reading and writing in one download extract, you can combine commands: imposm -U npmap -d osm -m imposm-mapping.py --read --write --optimize --deploy-production-tables ~/Downloads/us-northeast.osm.pbf

References

Clone this wiki locally