User:Sarchittuorg/Note

From OpenStreetMap Wiki
Jump to navigation Jump to search

Josm on Ubuntu and derivatives

To install

sudo mkdir /usr/share/josm/
sudo wget -O /usr/share/josm/josm-tested.jar http://josm.openstreetmap.de/josm-tested.jar

Using an editor with root permissions, create two files:

sudo nano /usr/bin/josm

and paste in it

java -jar /usr/share/josm/josm-tested.jar

Then:

sudo nano /usr/bin/josm-update

and paste in it

sudo wget -O /usr/share/josm/josm-tested.jar http://josm.openstreetmap.de/josm-tested.jar

Finally make executable the two files (chmod +x /usr/bin/josm).

Now to start Josm you need only to type "josm" in terminal or Alt-F2. To update use the command "josm-update"

Cut extract with poly

Generate .poly file for osmosis from the "poly" josm plugin

Cut OSM file

osmosis --read-xml file="source.osm" --bounding-polygon file="file.poly" completeWays=yes --write-xml file="result.osm"

Cut OSM PBF file

osmosis --rbf file="source.pbf" --bounding-polygon file="file.poly" completeWays=yes --wb file="result.pbf"

Postgresql

sudo apt-get install postgresql pgadmin3 postgis postgresql-9.3-postgis-2.1

Install osm2pgsql from source https://github.com/openstreetmap/osm2pgsql

Manual creating gis database:

sudo passwd postgres (to change password)
su postgres
psql (enter pg shell)
CREATE USER stefano WITH PASSWORD 'myPassword'; (your user account)
CREATE DATABASE gis;
GRANT ALL PRIVILEGES ON DATABASE gis TO stefano;
ALTER USER stefano WITH SUPERUSER;
\q (exit pg shell)
exit
psql -d gis
CREATE EXTENSION postgis;
ALTER TABLE geometry_columns OWNER TO stefano;
ALTER TABLE spatial_ref_sys OWNER TO stefano;
\q
osm2pgsql -W --extra-attributes -d gis -S /usr/share/osm2pgsql/default.style file.osm.bz2

To return data in correct reference, execute this query (http://spatialreference.org/ref/epsg/4326/postgis/)

INSERT into spatial_ref_sys (srid, auth_name, auth_srid, proj4text, srtext) 
values ( 94326, 'epsg', 4326, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ', 
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]');

Shapefiles

From shp to osm, splitted in 1000000 nodes files, applying rules.txt file

java -cp shp-to-osm-0.8.7-jar-with-dependencies.jar com.yellowbkpk.geo.shp.Main --shapefile ./test.shp
   --rulesfile ./rules.txt --osmfile osmname --outputFormat osm --maxnodes 1000000

From osm to shp

osmjs -2 -m -l sparsetable -i osm2shape -j config.js file.osm

Mapsforge Writer

Works only with osmosis, unpack it and point the terminal at that folder.

Download the jar here.

Put the .jar in plugins/ directory (if doesn't exist, create it).


bin/osmosis --rb file=berlin.osm.pbf --mapfile-writer file=berlin.map

JOSM search queries

All untagged nodes which aren't part of a way

type:node untagged -child

All nodes of a power line which aren't tagged (useful to set pylons power=tower)

type:node untagged child (type:way power=line)

OSMQualityMetrics

sudo apt-get install g++ libboost-dev zlib1g-dev libshp-dev libgd2-xpm-dev 
    libgdal1-dev libexpat1-dev libgeos++-dev libsparsehash-dev 
    libv8-dev libicu-dev libprotobuf-dev protobuf-compiler doxygen
    libboost-test-dev libosmpbf-dev
git clone https://github.com/joto/osmium.git
cd osmium/
make doc
sudo make install
cd osmjs/
make
sudo make install
git clone https://github.com/mvexel/OSMQualityMetrics.git
cd OSMQualityMetrics/
osmjs -j OSMQualityMetrics.js -l array liguria.osm.bz2 

This applies both for OSMQualityMetrics and for OSMetrics.

Fix osm files and cutting via poly

If shp2osm produces files unreadable by Josm

perl -CSDA -pe's/[^\x9\xA\xD\x20-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]+//g;' strade0.xml > strade0_fixed.xml

To create clipping regions http://wiki.openstreetmap.org/wiki/Osmosis/Examples#Extract_administrative_Boundaries_from_a_PBF_Extract

Then connect the missing borders, save to poly file (with JOSM)

Lastly cut with osmconvert

./osmconvert stradario.osm -B=olbia.poly | gzip -1  > stradeolbia.osm.gz

History files

Import

osm-history-importer genova.osh.bz2

Single date

osm-history-renderer/renderer/render.py --style osm-mapnik-style/osm.xml
 --date 2011-10-01 --bbox 8.9180,44.3985,8.9363,44.4176 --file 2011

Animation

osm-history-renderer/renderer/render-animation.py --style osm-mapnik-style/osm.xml 
--bbox 8.910084,44.399142,8.944588,44.417781 -- --type html --file genova 
--label "%d.%m.%Y" --label-gravity SouthEast --size 1024x768