line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RDF::KML::Exporter; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
43171
|
use 5.010; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
84
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
82
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
2309
|
use Geo::GoogleEarth::Pluggable; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use PerlX::Maybe; |
8
|
|
|
|
|
|
|
use RDF::TrineX::Functions -shortcuts_nodes; |
9
|
|
|
|
|
|
|
use Scalar::Util qw[blessed]; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub GEO { return 'http://www.w3.org/2003/01/geo/wgs84_pos#' . shift; } |
12
|
|
|
|
|
|
|
sub RDFS { return 'http://www.w3.org/2000/01/rdf-schema#' . shift; } |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use namespace::clean; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new |
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
my ($class, %options) = @_; |
21
|
|
|
|
|
|
|
bless { %options }, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub export_kml |
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
my ($self, $model, %options) = @_; |
27
|
|
|
|
|
|
|
$model = rdf_parse($model) |
28
|
|
|
|
|
|
|
unless blessed($model) && $model->isa('RDF::Trine::Model'); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $kml = Geo::GoogleEarth::Pluggable->new; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my @subjects = $model->subjects; |
33
|
|
|
|
|
|
|
S: foreach my $s (@subjects) |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
my ($lat) = |
36
|
|
|
|
|
|
|
map { $_->literal_value } |
37
|
|
|
|
|
|
|
grep { $_->is_literal } |
38
|
|
|
|
|
|
|
$model->objects_for_predicate_list($s, |
39
|
|
|
|
|
|
|
rdf_resource(GEO('lat')), |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
defined $lat or next S; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my ($long) = |
44
|
|
|
|
|
|
|
map { $_->literal_value } |
45
|
|
|
|
|
|
|
grep { $_->is_literal } |
46
|
|
|
|
|
|
|
$model->objects_for_predicate_list($s, |
47
|
|
|
|
|
|
|
rdf_resource(GEO('long')), |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
defined $long or next S; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my ($alt) = |
52
|
|
|
|
|
|
|
map { $_->literal_value } |
53
|
|
|
|
|
|
|
grep { $_->is_literal } |
54
|
|
|
|
|
|
|
$model->objects_for_predicate_list($s, |
55
|
|
|
|
|
|
|
rdf_resource(GEO('alt')), |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my ($name) = |
59
|
|
|
|
|
|
|
map { $_->literal_value } |
60
|
|
|
|
|
|
|
grep { $_->is_literal } |
61
|
|
|
|
|
|
|
$model->objects_for_predicate_list($s, |
62
|
|
|
|
|
|
|
rdf_resource('http://www.geonames.org/ontology#name'), |
63
|
|
|
|
|
|
|
rdf_resource('http://www.w3.org/2004/02/skos/core#prefLabel'), |
64
|
|
|
|
|
|
|
rdf_resource(RDFS('label')), |
65
|
|
|
|
|
|
|
rdf_resource('http://xmlns.com/foaf/0.1/name'), |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$kml->Point( |
69
|
|
|
|
|
|
|
lat => $lat, |
70
|
|
|
|
|
|
|
lon => $long, |
71
|
|
|
|
|
|
|
maybe alt => $alt, |
72
|
|
|
|
|
|
|
maybe name => $name, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return $kml; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
RDF::KML::Exporter - export RDF geo data to KML (Google Earth) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SYNOPSIS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
use RDF::KML::Exporter; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $exporter = RDF::KML::Exporter->new; |
92
|
|
|
|
|
|
|
my $input = 'http://dbpedia.org/resource/Lewes'; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
print $exporter->export_kml($input)->render; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 DESCRIPTION |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 Constructor |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item * C<< new(%options) >> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns a new RDF::KML::Exporter object. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
There are no valid options at the moment - the hash is reserved |
107
|
|
|
|
|
|
|
for future use. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 Methods |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=over |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * C<< export_kml($input, %options) >> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Returns a KML document including all the locations in the input, |
118
|
|
|
|
|
|
|
in no particular order. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The input may be a URI, file name, L<RDF::Trine::Model> or anything else |
121
|
|
|
|
|
|
|
that can be handled by the C<parse> function of L<RDF::TrineX::Functions>. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The returned object is an L<Geo::GoogleEarth::Pluggable> instance, which |
124
|
|
|
|
|
|
|
can be output as XML using its C<render> method. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 RDF Input |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Input is expected to use the W3C's WGS84 Geo Positioning vocabulary |
131
|
|
|
|
|
|
|
L<http://www.w3.org/2003/01/geo/wgs84_pos#>. Place names should use |
132
|
|
|
|
|
|
|
rdfs:label. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SEE ALSO |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L<HTML::Microformats>, L<RDF::TrineX::Functions>, |
137
|
|
|
|
|
|
|
L<Geo::GoogleEarth::Pluggable>. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
L<http://www.w3.org/2003/01/geo/wgs84_pos#>. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L<http://www.perlrdf.org/>. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This software is copyright (c) 2011-2012 by Toby Inkster. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
148
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
153
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
154
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
155
|
|
|
|
|
|
|
|