Finding the data
All of the OpenStreetMap data can be downloaded under a Creative Commons Attribution-ShareAlike 2.0 license on:
| Latest weekly | Contains | Use |
|---|---|---|
| Planet | A representation of the whole planet. | Initial import |
| Changeset (1 week) | Changes made since the previous week | Incremental update |
But you will quickly find that the data provided by OpenStreetMap is a little difficult to exploit as the planet file is very large and the changeset files are not very useful by themselves. To mitigate this problem there are two good mirrors below that provide extracts for all the countries:
- http://download.geofabrik.de/
- http://downloads.cloudmade.com/ (seems out-dated)
Note that if you still want to create the extracts yourself, you can find polygon files for continents, countries and states on the GeoFabrik download server in each of the sub-region sections.
Listed below are some websites that provide data that can also be useful:
Tools
There are two main tools osmosis and osm2pgsql
that are used to deal with the OpenStreetMap data. Other tools exist for dealing more efficiently with specialized tasks such as creating extracts (osmconvert, osm-history-splitter, ...) but they are not available as packages and will require patching.
Installation
make -C /usr/ports/astro/osmosis/ install make -C /usr/ports/converters/osm2pgsql/ install
Tuning
Increase heap memory (necessary for mapsforge map writer), and optimise java vm for long run (-server)
JAVACMD_OPTIONS="-Xmx2G -server" JAVACMD_OPTIONS=-Djava.io.tmpdir=/database/osm/tmp
Database
Installation
make install -C /usr/ports/databases/postgresql94-server make install -C /usr/ports/databases/postgresql94-contrib make install -C /usr/ports/databases/postgis21
Templates
sqldir=/usr/local/share/postgresql/contrib/postgis-2.1 createuser -sdrP root createdb template_postgis psql -d template_postgis -c 'CREATE EXTENSION hstore;' psql -d template_postgis -c 'CREATE EXTENSION postgis;' #psql -d template_postgis -c 'CREATE EXTENSION fuzzystrmatch;' #psql -d template_postgis -c 'CREATE EXTENSION postgis_topology;' #psql -d template_postgis -c 'CREATE EXTENSION postgis_tiger_geocoder;'
sqldir=/usr/local/share/osmosis/script
createdb -T template_postgis template_osmosis
psql -d template_osmosis -f ${sqldir}/pgsnapshot_schema_0.6_action.sql
psql -d template_osmosis -f ${sqldir}/pgsnapshot_schema_0.6.sql
psql -d template_osmosis -f ${sqldir}/pgsnapshot_schema_0.6_bbox.sql
psql -d template_osmosis -f ${sqldir}/pgsnapshot_schema_0.6_linestring.sql
Creation
createuser -lP osm createdb -O osm -T template_osmosis osmosis
Import
osmosis --read-pbf planet.osm.pbf \
--write-pgsql host="127.0.0.1" database="osmosis" user="osm" password="osm"
Initialisation
osm2pgsql -u -U osm -j --multi-geometry --number-processes 3 -s -C 2000 --keep-coastlines -S /data/planet/default.style -v /data/planet/data/planet-120704.osm.pbf
mkdir -p $HOME/.openstreetmap/osmosis/plugins cp mapsforge-map-writer-0.4.3-jar-with-dependencies.jar $HOME/.openstreetmap/osmosis/plugins
Vocabulary
- planet
- The file containing all the information for the whole planet.
- extract
- A part of the planet cut (extracted) by a polygon file.
- polygon file (POLY)
- A file containing a set of polygons, the format is described in Polygon Filter File_Format. It is used to extract information from the planet and is generally defined as to follow administrative boundaries (continent, country, state, ...).
Map
bin/osmosis --rb file=../data/berlin.osm.pbf --mapfile-writer file=/tmp/berlin.map
osmosis --rri workingDirectory=~/.osmosis-minutely/
--sc
--wpc user="osm" database="osmosis" password="osm"