NAME

OSM::Tree -- use OpenStreetMapData

SYNOPSIS

 #!/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;
   }
 }

DESCRIPTION

Parse OpenStreetMap XML file

AUTHOR

ToPeG

USING

OSM::Tree::Node

OSM::Tree::Way

OSM::Tree::Relation

OSM::Tree::Polygon

METHODS

new([XMLDATA|FILENAME],<PARSER>)

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

parse([XMLDATA|FILENAME])

set new XML data

returns 1 on success else 0

set_data(XMLDATA)

setup new XML data

returns 1 on success else 0

set_file(FILENAME)

setup new XML data from a file

returns 1 on success else 0

set_parser(type)

set new OSM Parser

returns 1 on success else 0

error()

get an OSM::Tree error

returns '' if there is no error

version()

read OSM version

returns the version stored in OSM-XML

generator()

read name of XML-generator

returns the the OSM-generator stored in XML

bbox()

returns the BoundaryBox of the OSM Data

returns (lonmin, latmin, lonmax, latmax)

show_deleted(<1/0>)

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

force_delete(<1/0>)

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

node(ID)

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

node_add(<HASH>)

add node-object

keys are:

optional

returns the an node-object or undef

see OSM::Tree::Node and OSM-XML spec for more

node_del(NODE)

detete a node returns 1 on success

node_id_del(ID)

detete a node returns 1 on success

node_list(<CODE>)

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

node_id_list()

get a list of all node-IDs

returns a list of node-IDs or an empty list if there are no nodes

node_list_length()

get the length the list of all nodes

returns the length of the node-list

node_exists(ID)

returns true if the node-id exists

way(ID)

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

way_add(<HASH>)

add way-object

keys are:

optional

returns the an node-object or undef

see OSM::Tree::Way and OSM-XML spec for more

way_del(WAY)

detete a node returns 1 on success

way_id_del(ID)

detete a way returns 1 on success

way_list(<CODE>)

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

way_id_list()

get a list of all way-IDs

returns a list of way-IDs or an empty list if there are no ways

way_list_length()

get the length the list of all ways

returns the length of the way-list

way_exists(ID)

returns true if the way-id exists

relation(ID)

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

relation_add(<HASH>)

add relation-object

keys are:

optional

returns the an node-object or undef

see OSM::Tree::Way and OSM-XML spec for more

relation_del(RELATION)

detete a relation returns 1 on success

relation_id_del(ID)

detete a relation returns 1 on success;

relation_list(<CODE>)

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

relation_id_list()

get a list of all relation-IDs

returns a list of relation-IDs or an empty list if there are no relations

relation_list_length()

get the length the list of all relations

returns the length of the relation-list

relation_exists(ID)

returns true if the relation-id exists

center_of_coordinate_list()

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]);
center_of_node_list()

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);
center_of_way()

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);
length_of_way()

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);
to_xml()

convert OSM::Tree back to OSM-XML

returns the a String of the OSM-XML

BUGS

None known.

Please send bugreports!

TODO

- distances beween Ways/Nodes

- crossing of ways

See also

OSM::Tree::BASE

OSM::Tree::Node

OSM::Tree::Way

OSM::Tree::Relation

OSM::Tree::TagList

OSM::Tree::Polygon

OSM::Tree

OSM::Filter

AUTHOR

Tobias Grönhagen <osm@topeg.de>

VERSION

Version 0.9.6

COPYRIGHT

Copyright (c) Tobias Grönhagen. All rights reserved.

LICENSE

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/

DISCLAIMER

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