[H-GEN] Extracting info from XML open street map file

mick bareman at tpg.com.au
Tue Jan 26 02:41:40 EST 2016


On Tue, 26 Jan 2016 13:24:05 +1000
Russell Stuart <russell-humbug at stuart.id.au> wrote:

> [ Humbug *General* list - semi-serious discussions about Humbug and     ]
> [ Unix-related topics. Posts from non-subscribed addresses will vanish. ]
> 
> On Tue, 2016-01-26 at 01:10 +0000, mick wrote:
> > I have grep'd and sort -u the input to produce a list of unique
> > key/value tags (2.1 million of them). The next step is to process that
> > list into an osm2psql style file but I can't think how to automate
> > that process.
> > 
> > Generic key/value lines:
> > ========================
> > 		<tag k="107" v="96"/>
> > 		<tag k="1744_field_ref" v="143"/>
> > 		<tag k="1744_field_ref" v="94"/>
> > 		<tag k="1860name" v="Aberargie Mill (Corn & Flour)"/>
> > 
> 
> I don't have clue how you went from the key/value format to osm2pgsql,
> so more detail is required.  (None of the keys or values in your key/val
> sample appear in the osm2pgsql sample, and I can't figure out where the
> should appear.)
> 
> This sort of thing is usually best accomplished in a scripting language
> of some sort - awk, lua, perl, php, python, even bash if it is simple
> enough. I doubt it would be more than 10 lines, so if you post enough
> detail someone will probably give you the script.
 
I extracted the key/value format sample from the downloaded XML open street map file, the osm2pgsql .style file specifies how to handle each tag when loading the osm data into a postgis database.

the basic flow of the process is:
download great-britain-latest.osm.bz2
unzip file to get great-britain-latest.osm
grep '<tag k=" great-britain-latest.osm >> keys.txt
sort -u keys.txt
read through keys.txt and add line in the osm2pgsql .style file
run osm2pgsql with the *.style to create postgis database
import database into Qgis for use.

OsmType is the object type (node = point, way=line or polygon.
Tag is part of the description of an object in osm
DataType is the data type of the database field (text, integer or real)
Flags is how to process items with the listed tag (options delete, linear or
	polygon). 

osm2pgsql .style:
================
# OsmType	Tag			DataType	Flags
=============================================================
node,way	107			text		delete
node,way	1744			text		delete
node,way	1860name		text		delete

Hope this makes more sense


More information about the General mailing list