This program uses an osm file to extract boundaries (-poly). These can be provided
- as is (as many nodes as given in osm file) as a *.poly file
- simplified (-simplify -slope -same -npk) according to default or customized parameters as a *.poly file. This may improve osmosis polygon operation significantly.
- resized (-resize) according to resizeFactor around center of polygon. Works with -simplify option also. Expect problems with certain polygon shapes. Always check results in maps (-pics option)
- original, simplified and resized boundary in map so a comparison can be made
- as HTML overview with valid and invalid relations
- as CSV overview with same data as HTML
- nested relations
- query by admin level of boundaries
- exclaves - V3
- multi boundary relations (like germany with islands) - V3
- role inner for polygons
The program also is able to create a hierarchy of boundaries (-hierarchy). For faster calculation -simplify should be used as well.
The hierarchies are given in two formats:
- HTML and
The HTML file contains links to osm and the relation analyzer.
Command line options
- -in= osm file name (input, mandatory)
- -html= output file name (defaults to boundaries.htm, >=V3.1)
- -csv= output file name (defaults to boundaries.csv, >=V3.1)
- -poly create polygons
- -polybase= poly base file name (like germany or tmp/germany) used to create output file names for relations. id is appended. (defaults to polygon, >=V3.1)
- -pics create pictures of polygons (valid and selected)
- -picsize=integer size in pixels for the longitude of the maps. latitude will be automatically calculated.
- -allpics create pictures of all polygons (-pics must be given, >=V3)
- -bigpic create picture of all (selected) boundaries (>=V3)
- -bigpicsize=integer size in pixels for the longitude of the big map. latitude will be automatically calculated.
- -simplify -slope -same -npk build simplified polygons (-poly and -polybase must be given). A minimum of 10 nodes is implemented in the code to prevent errors in Math::Polygon.
- -hierarchy build hierarchy. output as html and csv. html and csv names must be given and will be adapted. -poly and -polybase= must be given.
- -resize -factor=float build a resized (factor > 1 means bigger polygon, maybe 1.2) polygon. -poly and -polybase must be given. -simplify can be given.
- -adminlevel=integer selects one admin_level as selection criteria. So only country borders can be selected i.e.
- -ignoremissing program does not stop upon missing data (whatever then happens...) (>=V3.3)
- -verbose program talks even more...
perl boundaries.pl -in=../../osmdata/hamburg.osm -html=hamburg.htm -csv=hamburg.csv -polybase=./tmp/hamburg -poly -pics -simplify -resize -factor=1.2
perl boundaries.pl -in=../../osmdata/hamburg.osm -html=test.htm -csv=test.csv -polybase=./tmp/hamburg -poly -hierarchy
Sample Poly file
Darmstadt, Stadt (SIMPLIFIED) 1 8.671681E+00 4.995068E+01 8.731599E+00 4.995263E+01 8.734629E+00 4.993234E+01 8.741450E+00 4.992805E+01 ... 8.627218E+00 4.993874E+01 8.627084E+00 4.994218E+01 8.671681E+00 4.995068E+01 END END
Sample Hierarchy File (csv)
- relation id
- relation name
- relation type
- boundary type
- list of relations (is_in)
So 55736 is in 62422, 62504 and 62342 i.e.
20;55736;Berlin-Lankwitz;boundary;administrative;10;62422;62504;62342; 21;92778;Thalwinkel Gemeinde;boundary;administrative;8;62639;62607; 22;30564;Bretleben Gemeinde;boundary;administrative;8;62604;62366; 23;55513;Ebeleben erfüllende Gemeinde für ...;boundary;administrative;7;62366; 24;93376;Reisholz;multipolygon;administrative;10;93380;63306;62539; 25;62681;Landkreis Mansfeld-Südharz;multipolygon;administrative;6; 26;54724;Innenstadt;multipolygon;administrative;10;58745;63306;54462;
The is_in boundaries are ordered by their size. They themselves can overlap!
Todos, feature requests and ideas
- error handling for command line parameters and options
- map of all (valid) relations (all relations in one map)
- transform coordinates before polygon transformation
- support enclaves
- polygons for invalid boundaries as well (option, and hint in filename)
- temp files for nodes, ways and relations, faster access
- only a good idea if you have got large disks and empty space on them
- On smaller osm files the program performs well. I just tried to run it on a planet file from Feb 7th, 2009 and it appears that there are nodes missing in the file. I added checks to account for that. Let's see... --Gary68 11:08, 23 May 2009 (UTC)
- On a europe file I get "out of memory" currently. Don't know why... --Gary68 04:47, 24 May 2009 (UTC)
- First idea: Monitoring the program it seems that building the polygons use a lot of memory. So maybe it has to be accepted that for larger areas like Europe or Planet a query restriction like adminlevel=2 has to be used. (france used 1.6GB for complete boundary calculation, >8000 boundary relations).
- Windows users have a look here boundaries.pl/windows