| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Encoding and name #_{ |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=encoding utf8 |
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Geo::OSM::Primitive - Abstract base classes for the three Open Street Map primitives: L, L and L. |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=cut |
|
9
|
|
|
|
|
|
|
package Geo::OSM::Primitive; |
|
10
|
|
|
|
|
|
|
#_} |
|
11
|
|
|
|
|
|
|
#_{ use … |
|
12
|
1
|
|
|
1
|
|
88126
|
use warnings; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
46
|
|
|
13
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
580
|
use utf8; |
|
|
1
|
|
|
|
|
23
|
|
|
|
1
|
|
|
|
|
7
|
|
|
16
|
1
|
|
|
1
|
|
42
|
use Carp; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
618
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#_} |
|
19
|
|
|
|
|
|
|
our $VERSION = 0.01; |
|
20
|
|
|
|
|
|
|
#_{ Synopsis |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
… |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
|
27
|
|
|
|
|
|
|
#_} |
|
28
|
|
|
|
|
|
|
#_{ Overview |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 OVERVIEW |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
The idea is to encapsulte methods that use OpenStreetMap data (that is possibly stored in L. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#_} |
|
37
|
|
|
|
|
|
|
#_{ Methods |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
|
40
|
|
|
|
|
|
|
=cut |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { #_{ |
|
43
|
|
|
|
|
|
|
#_{ POD |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 new |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
new($osm_id, $primitive_type); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#_} |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
54
|
0
|
|
|
|
|
|
my $id = shift; |
|
55
|
0
|
|
|
|
|
|
my $type = shift; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $self = {}; |
|
58
|
0
|
|
|
|
|
|
bless $self, $class; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
croak "Wrong class $class" unless $self->isa('Geo::OSM::Primitive'); |
|
62
|
0
|
0
|
0
|
|
|
|
croak "id $id is not an integer" if ref($id) or int($id) != $id; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$self->{id} = $id; |
|
65
|
0
|
|
|
|
|
|
$self->{primitive_type} = $type; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $self; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} #_} |
|
70
|
|
|
|
|
|
|
sub primitive_type { #_{ |
|
71
|
|
|
|
|
|
|
#_{ POD |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 primitive_type |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $type = $osm_primitive->primitive_type(); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
if ($type eq 'way') { |
|
78
|
|
|
|
|
|
|
… |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
elsif ($type eq 'nod') { |
|
81
|
|
|
|
|
|
|
… |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
elsif ($type eq 'rel') { |
|
84
|
|
|
|
|
|
|
… |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Returns the type of the primitive: C<'nod'> (I) if the primitive is a L<>, |
|
88
|
|
|
|
|
|
|
C<'way'> if the primitive is a L<> or C<'rel'> if the primitive is |
|
89
|
|
|
|
|
|
|
a L<>. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#_} |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return $self->{primitive_type}; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} #_} |
|
100
|
|
|
|
|
|
|
sub member_of { #_{ |
|
101
|
|
|
|
|
|
|
#_{ POD |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 member_of |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
if ($osm_primitive->member_of($rel)) { … |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Tests whether the primitive is a member of the L C<$rel>. |
|
109
|
|
|
|
|
|
|
(B: currently only checks the cache. If the membership is not found in the cache, it is not |
|
110
|
|
|
|
|
|
|
further checked for its existence. That should of course be fixed once). |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#_} |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
117
|
0
|
|
|
|
|
|
my $rel = shift; |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
croak unless $rel->isa('Geo::OSM::Primitive::Relation'); |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return $self->{cache}->{member_of}->{$rel->{id}}; |
|
122
|
|
|
|
|
|
|
} #_} |
|
123
|
|
|
|
|
|
|
sub role { #_{ |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#_{ POD |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 role |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $role = $osm_primitive->role($osm_relation); |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Returns the role of C<$osm_relation> in L<> C<<$osm_relation>>. |
|
132
|
|
|
|
|
|
|
(B: currently only works if the role had been set with L. Of course, the role |
|
133
|
|
|
|
|
|
|
should also be found if it is not in the cache.). |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
#_} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
142
|
0
|
|
|
|
|
|
my $rel = shift; |
|
143
|
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
croak unless $rel->isa('Geo::OSM::Primitive::Relation'); |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
return undef unless $self->member_of($rel); |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
if (exists $self->{cache}->{member_of}->{$rel->{id}}->{rol}) { |
|
149
|
0
|
|
|
|
|
|
return $self->{cache}->{member_of}->{$rel->{id}}->{rol}; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return undef; |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} #_} |
|
156
|
|
|
|
|
|
|
sub _set_cache_role { #_{ |
|
157
|
|
|
|
|
|
|
#_{ POD |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 _set_cache_role |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my $role = 'outer'; |
|
162
|
|
|
|
|
|
|
$osm_primitive->_set_cache_role($osm_relation, $role); |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This method assumes that the primitive on which it is called is a member of C<< $osm_relation >> (which must |
|
165
|
|
|
|
|
|
|
be a L) and that the role (which is a string) is C<< $role >>. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This method is internal and should not be called from a user of C. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
#_} |
|
172
|
|
|
|
|
|
|
|
|
173
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
174
|
0
|
|
|
|
|
|
my $rel = shift; |
|
175
|
0
|
|
|
|
|
|
my $rol = shift; |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
0
|
|
|
|
|
croak "Relation expected unless " unless $self->isa('Geo::OSM::Primitive'); |
|
178
|
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
$self->{cache}->{member_of}->{$rel->{id}}->{rol}=$rol; |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
} #_} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
#_} |
|
184
|
|
|
|
|
|
|
#_{ POD: Author |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 AUTHOR |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
René Nyffenegger |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
#_} |
|
193
|
|
|
|
|
|
|
#_{ POD: See also |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
L is a base class to render osm data. L is a derivation of that base class to |
|
198
|
|
|
|
|
|
|
render SVG files. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
L can be used to store Open Street Map data in a database. (It should be database independant (hence DBI), yet currently, it probably only works |
|
201
|
|
|
|
|
|
|
with SQLite. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
#_} |
|
206
|
|
|
|
|
|
|
#_{ POD: Copyright and license |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
209
|
|
|
|
|
|
|
Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved. |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
212
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
|
213
|
|
|
|
|
|
|
copy of the full license at: L |
|
214
|
|
|
|
|
|
|
=cut |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
#_} |
|
217
|
|
|
|
|
|
|
#_{ POD: Source Code |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 Source Code |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
The source code is on L<< github|https://github.com/ReneNyffenegger/perl-Geo-OSM-Primitive >>. Meaningful pull requests are welcome. |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
#_} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
'tq84'; |