OSM::Tree -- use OpenStreetMapData
#!/usr/bin/perl use strict; use warnings; use OSM::Tree; use Data::Dumper; my $osm=OSM::Tree->new('map2.osm'); # or: # my $osmdata=' ... some osmxml ... '; # my $osm=OSM::Tree->new($osmdata); # get Version print "FILE VERSION: ".$osm->version()."\n"; # get Generator print "FILE GENERATOR: ".$osm->generator()."\n"; print "\n#############################################################\n"; print "Nodes:".$osm->node_list_length()."\n"; print "WAYS:".$osm->way_list_length()."\n"; print "Relations:".$osm->relation_list_length()."\n"; print "\n#############################################################\n"; # print boundaty Box print "BOUNDARY BOX: (".join(', ',$osm->bbox()).")\n"; my ($map_lan,$map_lon)=$osm->center_of_node_list($osm->node_list()); print "Center of the Map: $map_lan,$map_lon\n"; print "\n#############################################################\n"; # get the fist way in list # print ID and all avaiable tags my @ways=$osm->way_list(); print "WAY:\n"; print " ID: ".$ways[0]->id()."\n"; my $tags=$ways[0]->tags(); if($ways[0]->has_tags()) { print " TAGS:\n"; my $tags=$ways[0]->tags(); for my $tag ($tags->tag_list()) { print $tag->name()."->".join(';',$tag->value_list())."\n"; } } print "\n"; # print the center of all ways: for my $way ($osm->way_list()) { my ($lon,$lat)=$way->center(); print "Cener of the Way:".$way->id()." is $lon,$lat\n"; } print "\n#############################################################\n"; # get all nodes who has a tag with name "name" for my $node ($osm->node_list()) { if($node->tag('name')) { print "NODE ID: ".$node->id()."\n"; print " NAME :".$node->tag('name')->value()."\n"; print " KOORDINATE: ".join(' x ', $node->coordinate())."\n\n"; } } print "\n#############################################################\n"; # get the first node with a way # and print all nodes of this way for my $node ($osm->node_list()) { my $way=$node->way(); if($way) { print "NODE ".$node->id()." id part of WAY: ".$way->id()."\n"; print "All NODES of this WAY are:\n"; for my $node_id ($way->node_id_list()) { my $node=$osm->node($node_id); print " ID: ".$node->id()."\n"; if($node->has_tags()) { print " TAGS:\n"; my @tags=$node->tags()->tag_list(); map{ $_=$_->name()." = ".$_->value() }@tags; print " ".join("\n ", @tags)."\n"; } } last; } }
Parse OpenStreetMap XML file
ToPeG
create a new Tree-Object
parser types:
Falback
plain perl robust OSM-Parser
Default
using XML::Parser (fastest parser)
BigFile (BigFilePP)
using a BerkleyDB to store the values (<filename>.db) slower than "Default" but mutch less memory usage
"OSM::Tree::XML::Default" is the Default
returns an OSM::Tree Object
set new XML data
returns 1 on success else 0
setup new XML data
returns 1 on success else 0
setup new XML data from a file
returns 1 on success else 0
set new OSM Parser
returns 1 on success else 0
get an OSM::Tree error
returns '' if there is no error
read OSM version
returns the version stored in OSM-XML
read name of XML-generator
returns the the OSM-generator stored in XML
returns the BoundaryBox of the OSM Data
returns (lonmin, latmin, lonmax, latmax)
If it's set the nodes/ways/relation with "action='delete'" are listet as normal returns the actual state
It's not set by default
If it's set the nodes/ways/relation are deleted from the Stack. If it's not set the tag "action='delete'" is set
It's set by default
returns the actual state
get node-object for an node-ID see OSM::Tree::Node for more
returns the an node-object or undef if there is no node with this ID
add node-object
keys are:
the unique node ID
longitude
latitude
username or user id
ChangeSet
optional
Is this an visible node? Default: "yes"
Version of the Node Default: 1
Timestamp of change/creation dafault time()
returns the an node-object or undef
see OSM::Tree::Node and OSM-XML spec for more
detete a node returns 1 on success
detete a node returns 1 on success
get a node-object-list of all nodes if an coderefence is given it will use as filter.
see OSM::Tree::Node for more
returns a list of node-objects or an empty list if there are no nodes
get a list of all node-IDs
returns a list of node-IDs or an empty list if there are no nodes
get the length the list of all nodes
returns the length of the node-list
returns true if the node-id exists
get a way-object with this ID
see OSM::Tree::Way for more
returns an way-object if this ID or undef if there is no id with this id
add way-object
keys are:
the unique node ID
username or user id
ChangeSet
optional
Is this an visible node? Default: "yes"
Version of the Node Default: 1
Timestamp of change/creation Default: time()
hash of key/value pairs
List of Node-IDs
returns the an node-object or undef
see OSM::Tree::Way and OSM-XML spec for more
detete a node returns 1 on success
detete a way returns 1 on success
get a list of all way-Objects if an coderefence is given it will use as filter.
see OSM::Tree::Way for more
returns a list of way-Objects or an empty list if there are no ways
get a list of all way-IDs
returns a list of way-IDs or an empty list if there are no ways
get the length the list of all ways
returns the length of the way-list
returns true if the way-id exists
get an relation-object with this id
see OSM::Tree::Relation for more
returns an relation.object or undef if thre is no relation with this id
add relation-object
keys are:
the unique node ID
username or user id
ChangeSet
optional
Is this an visible node? Default: "yes"
Version of the Node Default: 1
Timestamp of change/creation Default: time()
hash of key/value pairs
List of Hashes with ref type role see OSM::Tree::Member for more
returns the an node-object or undef
see OSM::Tree::Way and OSM-XML spec for more
detete a relation returns 1 on success
detete a relation returns 1 on success;
get a list of all relation-Objects if an coderefence is given it will use as filter.
see OSM::Tree::Relation for more
returns a list of relation-Objects or an empty list if there are no relations
get a list of all relation-IDs
returns a list of relation-IDs or an empty list if there are no relations
get the length the list of all relations
returns the length of the relation-list
returns true if the relation-id exists
get the center of a list of kooardiantepairs
returns a longitude,latitude pair
Examples:
my ($lon,$lat)= $osm->center_of_coordinate_list( [1,3], [12,5], [12,5.3221], [13,7]); my ($lon,$lat)= OSM::Tree::center_of_coordinate_list( [1,3], [12,5], [12,5.3221], [13,7]);
get the center of a list of Nodes oder Nodeids (can be mixed)
returns a longitude,latitude pair
Example:
my ($lon,$lat)= $osm->center_of_coordinate_list(1,2,4,6,9,$nodea,$nodeb);
get the center of a way or wayid
returns a longitude,latitude pair
Examples:
my ($lon,$lat)= $osm->center_of_way($wayid); my ($lon,$lat)= $osm->center_of_way($wayref);
get the length of a way or wayid
returns a distance
Examples:
my $length= $osm->length_of_way($wayid); my $length= $osm->length_of_way($wayref);
convert OSM::Tree back to OSM-XML
returns the a String of the OSM-XML
None known.
Please send bugreports!
- distances beween Ways/Nodes
- crossing of ways
Tobias Grönhagen <osm@topeg.de>
Version 0.9.6
Copyright (c) Tobias Grönhagen. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms and conditions as Perl itself.
This means that you can, at your option, redistribute it and/or modify it under either the terms the GNU Public License (GPL) version 2 or later, or under the Perl Artistic License.
See http://dev.perl.org/licenses/
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Use of this software in any way or in any form, source or binary, is not allowed in any country which prohibits disclaimers of any implied warranties of merchantability or fitness for a particular purpose or any disclaimers of a similar nature.
IN NO EVENT SHALL I BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION (INCLUDING, BUT NOT LIMITED TO, LOST PROFITS) EVEN IF I HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE