Tag: osmosis

Playing with Osmosis

Command to filter the file with tag amenity=school and write the filtered data in second file.

$ osmosis –read-xml file=”ludhiana.osm” –nkv keyValueList=”amenity.school” –write-xml file=”school.osm”

Do you want to update your OSM data without deleting existing data?

So here are the steps given below.

Step 1

Derive a change set between two files. The first file is the file after changing, the second planet file is the file before changing. The changeset will be written in the third file.

$ osmosis –read-xml file=”classroom.osm” –read-xml file=”class_lib_tcc.osm” –derive-change –write-xml-change file=”classroom_classlibtcc_diff.osm”

Step 2

Dump the changeset to the database in append mode. It means it will change only affected data. Rest will exist there.

$ osm2pgsql –slim -a -d classroom -C 2500 –hstore -S openstreetmap-carto.style ~/osmosis_files/class_audi_diff.osm

And you are done.:)

Note: Osmosis and osm2pgsql have different schemas. So for using postgis flags of osmosis we have to create schema compatible with osmosis. I followed this link to create ans setup database.

For my satisfaction, I have written that command again.

$ psql -d classroom -f /home/amisha/osm/osmosis/script/pgsnapshot_schema_0.6_action.sql

OUTPUT

CREATE TABLE
ALTER TABLE

 

Advertisements

Osmosis in OSM

Till now, whatever changes I do in the OSM data, I again download the latest data from OSM or from http://extract.bbbike.org/ and import the fresh data in the database. But this is not the efficient approach.

So Today, I am going to introduce you with the term osmosis. You can read it in detail from here

Osmosis Installation

$sudo apt install osmosis

$osmosis -v                          //tell version

INFO: Osmosis Version 0.44.1

Now, it’s time to use the tool. The first command I tried to check the difference in the changesets of the two files was

$ osmosis –read-xml file=”ludh.osm” –read-xml file=”ludhiana.pbf” –derive-change –write-xml-change file=”planetdiff-1-2.osc”

Luckily, I encountered with an error.;)

SEVERE: Thread for task 1-read-xml failed
org.openstreetmap.osmosis.core.OsmosisRuntimeException: An output error has occurred, aborting.

After browsing on the internet then I came to know about my silly mistake. For the file ludhiana.pbf I was using the flag –read-xml instead of –read-pbf. The correct command is

$ osmosis –read-xml file=”ludh.osm” –read-pbf file=”ludhiana.pbf” –derive-change –write-xml-change file=”planetdiff-1-2.osc”

Similarly, we can explore osmosis a lot.