line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
RDF::Query::Functions::Geo - Geographic extension functions |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 VERSION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
This document describes RDF::Query::Functions::Geo version 2.916. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Defines the following function: |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=over |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=item * java:com.ldodds.sparql.Distance |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=back |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package RDF::Query::Functions::Geo; |
22
|
|
|
|
|
|
|
|
23
|
35
|
|
|
35
|
|
33101
|
use strict; |
|
35
|
|
|
|
|
90
|
|
|
35
|
|
|
|
|
989
|
|
24
|
35
|
|
|
35
|
|
203
|
use warnings; |
|
35
|
|
|
|
|
83
|
|
|
35
|
|
|
|
|
1170
|
|
25
|
35
|
|
|
35
|
|
212
|
use Scalar::Util qw(blessed reftype refaddr looks_like_number); |
|
35
|
|
|
|
|
83
|
|
|
35
|
|
|
|
|
2487
|
|
26
|
35
|
|
|
35
|
|
205
|
use Log::Log4perl; |
|
35
|
|
|
|
|
82
|
|
|
35
|
|
|
|
|
441
|
|
27
|
|
|
|
|
|
|
our ($VERSION, $l); |
28
|
|
|
|
|
|
|
BEGIN { |
29
|
35
|
|
|
35
|
|
3384
|
$l = Log::Log4perl->get_logger("rdf.query.functions.geo"); |
30
|
35
|
|
|
|
|
18739
|
$VERSION = '2.916'; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $GEO_DISTANCE_LOADED; |
34
|
|
|
|
|
|
|
BEGIN { |
35
|
35
|
|
|
35
|
|
97
|
$GEO_DISTANCE_LOADED = do { |
36
|
35
|
|
|
|
|
86
|
eval { |
37
|
35
|
|
|
|
|
28742
|
require Geo::Distance; |
38
|
|
|
|
|
|
|
}; |
39
|
35
|
50
|
|
|
|
634669
|
($@) ? 0 : 1; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=begin private |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item C<< install >> |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Documented in L<RDF::Query::Functions>. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=end private |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub install { |
54
|
|
|
|
|
|
|
RDF::Query::Functions->install_function( |
55
|
|
|
|
|
|
|
"java:com.ldodds.sparql.Distance", |
56
|
|
|
|
|
|
|
sub { |
57
|
|
|
|
|
|
|
# http://xmlarmyknife.com/blog/archives/000281.html |
58
|
19
|
|
|
19
|
|
30
|
my $query = shift; |
59
|
19
|
|
|
|
|
24
|
my ($lat1, $lon1, $lat2, $lon2); |
60
|
|
|
|
|
|
|
|
61
|
19
|
50
|
|
|
|
49
|
unless ($GEO_DISTANCE_LOADED) { |
62
|
0
|
|
|
|
|
0
|
throw RDF::Query::Error::FilterEvaluationError ( -text => "Cannot compute distance because Geo::Distance is not available" ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $geo = ref($query) |
66
|
19
|
100
|
66
|
|
|
127
|
? ($query->{_query_cache}{'java:com.ldodds.sparql.Distance'}{_geo_dist_obj} ||= new Geo::Distance) |
67
|
|
|
|
|
|
|
: new Geo::Distance; |
68
|
19
|
50
|
|
|
|
1234
|
if (2 == @_) { |
69
|
0
|
|
|
|
|
0
|
my ($point1, $point2) = map { $_->literal_value } splice(@_,0,2); |
|
0
|
|
|
|
|
0
|
|
70
|
0
|
|
|
|
|
0
|
($lat1, $lon1) = split(/ /, $point1); |
71
|
0
|
|
|
|
|
0
|
($lat2, $lon2) = split(/ /, $point2); |
72
|
|
|
|
|
|
|
} else { |
73
|
19
|
|
|
|
|
45
|
($lat1, $lon1, $lat2, $lon2) = map { $_->literal_value } splice(@_,0,4); |
|
76
|
|
|
|
|
404
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
19
|
|
|
|
|
160
|
my $dist = $geo->distance( |
77
|
|
|
|
|
|
|
'kilometer', |
78
|
|
|
|
|
|
|
$lon1, |
79
|
|
|
|
|
|
|
$lat1, |
80
|
|
|
|
|
|
|
$lon2, |
81
|
|
|
|
|
|
|
$lat2, |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
# warn "ldodds:Distance => $dist\n"; |
84
|
19
|
|
|
|
|
1086
|
return RDF::Query::Node::Literal->new("$dist", undef, 'http://www.w3.org/2001/XMLSchema#float'); |
85
|
|
|
|
|
|
|
} |
86
|
35
|
|
|
35
|
1
|
457
|
); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Gregory Williams <gwilliams@cpan.org>. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |