-
Notifications
You must be signed in to change notification settings - Fork 50
Installing imposm using postgres.app and osm bright from mapbox
Up to Tutorials »
From: Nate Irwin and Mamata Akella, National Park Service
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
- 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',
)
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
- Download from Postgres.app (postgresapp.com)
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
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!"
- Download the necessary OSM files from download.geofabrik.de
- 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
- 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
- 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
- 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