Perl Scripts
From OpenStreetMap
This page tries to give an overview of the Perl scripts that can be found on SVN. The idea is to have a short description here of what every script does.
If you are writing a new script, look at the Geo::OSM library, it contains functions to simplify many tasks. It also removes most of the distinction between different server versions.
Contents |
/applications/utils/planet.osm/perl
- This script will import a planet.osm file into a database (mysql or postgresql). It can optionally only import the things within a bounding box, just exclude things within a bounding box. It can read from STDIN, or from a file, or download the latest planet.osm for you. If requested, can output the schema to use, or clean the database from a previous import.
- The postgres support has been updated for the 0.5 API, but the mysql part may need some tweaks for 0.5
- Sample use might be:
- ./planetosm-to-db.pl --dbtype pgsql --schema | psql -U osm -d osm
- ./planetosm-to-db.pl --dbtype pgsql Planet.osm
- This script takes an osm file like planet.osm and runs some simple statistics. A user name has to be given and then file and user statistics about nodes, ways and relations are given based on the field "user".
- This program counts the numbers of nodes, ways and relations per user in a planet.osm file. Of course segments/parts can be used like germany.osm or hessen.osm. No history data is used. Just the field user in xml. Output is first general stats, then lists of users with numbers of nodes, ways and relations, unsorted. Then TOP lists are generated and displayed.
- This program calculates the center of a user's activity in a given osm file/area for all users. It uses the field user and builds the means of longitude and latitude for each user. This information is added to the original OSM file and can be fed to a renderer, i.e. KOSMOS. The file is written to STDOUT. Users are labeled light, medium and heavy according to contributed nodes. Limits can be edited in source file. Example output of KOSMOS see here: KOSMOS CenterUserActivity.png
/applications/utils/osm-extract
- This takes a bounding box, and only outputs the parts of the planet.osm that are within it (much like the -bbox parameter to planetosm-to-db.pl). So, you can produce a mini planet.osm for just one area, without going via a database. Updated for 0.5
- Oh, and it reads from STDIN if you want it to, so you can do
bzcat planet-061023.osm.bz2 | planetosm-excerpt-area.pl -bbox 50,-2,60,1 | bzip > mini-planet.osm.bz2
- This script finds ways with certain tags on them, their segments and nodes, and nodes with certain tags on them. So, you could do an area excerpt for just the UK, then filter it through this to get all the railways and cities, then pass that straight to osmarender.
- It doesn't support STDIN, as it has to make multiple passes over the file, so you should probably do an area excerpt first. Updated for 0.5
/applications/utils/import
osmtrackfilter/osmtrackfilter.pl
With this program you can read your tracks and filter them with different filters.
common usage:
osmtrackfilter.pl [-d] [-v] [--out-osm] [--limit-area]
<File1.gps> [<File2.sav>,<File2.ns1>,...] Other options which might be useful:
- --man Complete documentation
- --out-raw-gpx: write a raw .gpx file after conversion from .nmea, .gps, ...
- --out-upload-gpx : write a reduced .gpx file
- --out-osm: write a .osm file for loading into JOSM
- --split-tracks: split Tracks if distance too long, speed too high, ...
- --filter-against-osm : throw out all tracksegments found already in osm
- --filter-dup-seg: throw out second time you drove a street
- --filter-reduce: reduce number of points. (for example: reduce long straight lines)
- --limit-area: use filter files to reduce area
- --filter-clew: clews are produced if you have your GPS standing still
- --filter-all: use filter files to reduce area
- --draw_filter_areas: draw the (--limit-area) areas into GPX file
- --generate_ways: try to guess way info(not working yet)
- --fake-gpx-date: write faked date into GPX
- --write-gpx-wpt: also include waypoints into GPX-file
- --stdin: read from stdin
- --stdout: write to stdout
/csv2osm
| | Software described on this page or in this section is unlikely to be compatible with API version 0.4 deployed on May 05, 2007. If you have fixed the software, or concluded that this notice does not apply, remove it. |
| | Software described on this page or in this section is unlikely to be compatible with API version 0.5 deployed on 8 October, 2007. If you have fixed the software, or concluded that this notice does not apply, remove it. |
Takes a CSV file, and a config file which defines the mappings, and adds the entries into OSM.
Will do a search before adding, and won't add if there are any (potentially) matching entries found in the area to be added to.
A .osm file is produced for all the entries that were added, and another for all the entries that failed.
All configuration is done in the file 'config'. You should copy one of the sample ones, and edit it to suit your needs
/applications/utils/perl_lib
This is a directory to include for all sorts of perl modules which might be useful for other osm-related Perl applications.
/Utils
- Debug.pm
- File.pm
- LWP/
Stuff for downloading/mirroring planet.osm Files
- Math.pm
/Geo
- Geo/OSM/SegmentList.pm
- Geo/OSM/Write.pm
- Geo/OSM/MapFeatures.pm
- Geo/OSM/OsmXML.pm
- Geo/OSM/Planet.pm
- Geo/OSM/Upload.pm
- Geo/OSM/Tracks2OSM.pm
The Geo::OSM library also lives here.
/Geo/GPX
- Geo/GPX/File.pm
Read/write GPX Files
- Geo/Geometry.pm
/Geo/Tracks
- Geo/Tracks/Tools.pm
Handle Track data-structure in memory. Copy one track to another, split tracks, ...
Stuff to read different Track formats.
- Geo/Tracks/Kismet.pm
- Geo/Tracks/GpsBabel.pm
- Geo/Tracks/NMEA.pm
/Geo/Filter
Stuff for filtering Tracks and OSM Data.
- Geo/Filter/Area.pm
Filter data for a given Area. For now the area can be specified as a bounding box or country/region name.

