OpenStreetMap: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
mNo edit summary
Brian Wilson (talk | contribs)
mNo edit summary
Line 3: Line 3:
Let the data just seep into PostGIS through a semipermeable membrane with osmosis, or use the command line tool of the same name.
Let the data just seep into PostGIS through a semipermeable membrane with osmosis, or use the command line tool of the same name.


Get the data for the western United States
=== Get the tool ===
wget http://download.geofabrik.de/north-america/us-west-latest.osm.pbf
 
Get the tool


  wget http://bretth.dev.openstreetmap.org/osmosis-build/osmosis-latest.zip
  wget http://bretth.dev.openstreetmap.org/osmosis-build/osmosis-latest.zip
Line 14: Line 11:


No build required, that's the Java JAR advantage! (You knew there was an advantage.)
No build required, that's the Java JAR advantage! (You knew there was an advantage.)
=== Set up the database ===
createdb osmosis_us_west
echo "CREATE EXTENSION hstore; CREATE EXTENSION postgis;" | psql -U postgres
echo "ALTER TABLE osmosis_us_west OWNER TO osm" | psql -U postgres
cd script
psql -U postgres osmosis_us_west -f pgsimple_schema_0.6.sql
=== Get the data ===
Get the data for the western United States
wget http://download.geofabrik.de/north-america/us-west-latest.osm.pbf


Run osmosis to load the PBF file into your PostGIS server. I do it thusly
Run osmosis to load the PBF file into your PostGIS server. I do it thusly

Revision as of 03:13, 10 October 2013

Use osmosis

Let the data just seep into PostGIS through a semipermeable membrane with osmosis, or use the command line tool of the same name.

Get the tool

wget http://bretth.dev.openstreetmap.org/osmosis-build/osmosis-latest.zip
mkdir osmosis
cd osmosis
unzip ../osmosis-latest.zip

No build required, that's the Java JAR advantage! (You knew there was an advantage.)

Set up the database

createdb osmosis_us_west
echo "CREATE EXTENSION hstore; CREATE EXTENSION postgis;" | psql -U postgres
echo "ALTER TABLE osmosis_us_west OWNER TO osm" | psql -U postgres
cd script
psql -U postgres osmosis_us_west -f pgsimple_schema_0.6.sql 

Get the data

Get the data for the western United States

wget http://download.geofabrik.de/north-america/us-west-latest.osm.pbf

Run osmosis to load the PBF file into your PostGIS server. I do it thusly

createdb osmosis_us_west
echo "ALTER TABLE osmosis_us_west OWNER TO osm_reader" | psql -U postgres
# Put TEMP files somewhere with lots of space
mkdir tmp
JAVACMD_OPTIONS="-Djava.io.tmpdir=tmp" \
./osmosis -v --read-pbf us-west-latest.osm.pbf --write-pgsql user=osm_reader database=osmosis_us_west

Or use the osm2pgsql tool

Using excellent instructions from http://bostongis.com/ In particular, the Almost idiot's guide...

First, get the data from CloudMade for California and Oregon, or if you have LOTS of time and space get the whole planet.

mkdir /green/GISData/OSM && cd /green/GISData/OSM
wget http://downloads.cloudmade.com/americas/northern_america/united_states/california/california.osm.bz2
wget http://downloads.cloudmade.com/americas/northern_america/united_states/oregon/oregon.osm.bz2

Create a lovely Postgis database and spatially enable it and add hstore.

Build osm2pgsql

No need for any special configuration options, just build and install!

sudo apt-get install libxml2-dev libbz2-dev
cd ~/src/GIS
git clone https://github.com/openstreetmap/osm2pgsql.git
cd osm2pgsql
./autogen.sh
./configure
sed -i 's/-g -O2/-O2 -march=native -fomit-frame-pointer/' Makefile
make
sudo make install

Using osm2pgsql

# bellman
osm2pgsql oregon.osm.bz2 -d osm -U postgres -S /green/bwilson/src/GIS/osm2pgsql/default.style --hstore
osm2pgsql california.osm.bz2 --append -d osm -U postgres -S /green/bwilson/src/GIS/osm2pgsql/default.style --hstore
# dart
createdb -U postgres osm
createuser -U postgres osm
psql -U postgres osm 
CREATE EXTENSION hstore;
CREATE EXTENSION postgis;

# The western US - I had to increase the node cache size
osm2pgsql us-west-latest.osm.pbf -d osm -U osm -S ~/src/GIS/osm2pgsql/default.style --hstore -C 10000
# The whole planet - I RUN OUT OF MEMORY!! Dang.
osm2pgsql planet-latest.osm -d osm -U osm -S ~/src/GIS/osm2pgsql/default.style --hstore -C 15000

On my little server Bellman, it took 628 seconds to load the Oregon data and it took 3302 seconds to load California. Conclusion: California is much bigger, in fact there is probably room for me there in Nevada county.

I just loaded Oregon data onto my much snazzier server at work and it took 183 seconds.

Nice to have some data in my PostGIS server.

Now I need to get it showing up in Geoserver