Skip to content

Commit

Permalink
Replace use of Geo::Distance with GIS::Distance (#168 via @jonassmede…
Browse files Browse the repository at this point in the history
…gaard).

Resolves #168.
  • Loading branch information
kasei committed Apr 21, 2020
1 parent 2db05bf commit 616df42
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion RDF-Query/Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license 'perl';

recommends 'LWP::Simple' => 0;
recommends 'Getopt::Simple' => 0;
recommends 'Geo::Distance' => 0.09;
recommends 'GIS::Distance' => 0;

build_requires 'Test::JSON' => 0;
build_requires 'Test::More' => 0.88;
Expand Down
2 changes: 1 addition & 1 deletion RDF-Query/README
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ REQUIREMENTS

The following additional modules are recommended for some functionality:

* Geo::Distance
* GIS::Distance

INSTALLATION

Expand Down
2 changes: 1 addition & 1 deletion RDF-Query/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h2>Requirements</h2>
</ul>
<p>The following additional modules are recommended for some functionality:</p>
<ul>
<li>Geo::Distance</li>
<li>GIS::Distance</li>
</ul>
<h2 id="installing">Installing RDF::Query</h2>
<p>To install, run:</p>
Expand Down
14 changes: 7 additions & 7 deletions RDF-Query/lib/RDF/Query/Functions/Geo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ our $GEO_DISTANCE_LOADED;
BEGIN {
$GEO_DISTANCE_LOADED = do {
eval {
require Geo::Distance;
require GIS::Distance;
};
($@) ? 0 : 1;
};
Expand All @@ -59,12 +59,12 @@ sub install {
my ($lat1, $lon1, $lat2, $lon2);

unless ($GEO_DISTANCE_LOADED) {
throw RDF::Query::Error::FilterEvaluationError ( -text => "Cannot compute distance because Geo::Distance is not available" );
throw RDF::Query::Error::FilterEvaluationError ( -text => "Cannot compute distance because GIS::Distance is not available" );
}

my $geo = ref($query)
? ($query->{_query_cache}{'java:com.ldodds.sparql.Distance'}{_geo_dist_obj} ||= new Geo::Distance)
: new Geo::Distance;
? ($query->{_query_cache}{'java:com.ldodds.sparql.Distance'}{_geo_dist_obj} ||= new GIS::Distance)
: new GIS::Distance;
if (2 == @_) {
my ($point1, $point2) = map { $_->literal_value } splice(@_,0,2);
($lat1, $lon1) = split(/ /, $point1);
Expand All @@ -74,11 +74,11 @@ sub install {
}

my $dist = $geo->distance(
'kilometer',
$lon1,
# 'kilometer',
$lat1,
$lon2,
$lon1,
$lat2,
$lon2,
);
# warn "ldodds:Distance => $dist\n";
return RDF::Query::Node::Literal->new("$dist", undef, 'http://www.w3.org/2001/XMLSchema#float');
Expand Down
4 changes: 2 additions & 2 deletions RDF-Query/t/algebra-func.t
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,11 @@ local($RDF::Query::Node::Literal::LAZY_COMPARISONS) = 1;
}

{
eval "use Geo::Distance 0.09;";
eval "use GIS::Distance 0.09;";
my $GEO_DISTANCE_LOADED = ($@) ? 0 : 1;
# ldodds:Distance
SKIP: {
skip( "Need Geo::Distance 0.09 or higher to run these tests.", 4 ) unless ($GEO_DISTANCE_LOADED);
skip( "Need GIS::Distance to run these tests.", 4 ) unless ($GEO_DISTANCE_LOADED);
my @args = map { RDF::Query::Node::Literal->new($_, undef, 'http://www.w3.org/2001/XMLSchema#float') } qw(34.015673 -118.496947 41.8351 -71.3971);
my $TEST = "ldodds:Distance";
my $alg = $func->new( "java:com.ldodds.sparql.Distance", @args );
Expand Down
4 changes: 2 additions & 2 deletions RDF-Query/t/ext-select-expr.t
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ END
is( $count, 1, 'expecting one statement in model' );
}

eval "use Geo::Distance 0.09;";
eval "use GIS::Distance;";
my $GEO_DISTANCE_LOADED = ($@) ? 0 : 1;
SKIP: {
skip( "Need Geo::Distance 0.09 or higher to run these tests.", 2 ) unless ($GEO_DISTANCE_LOADED);
skip( "Need GIS::Distance to run these tests.", 2 ) unless ($GEO_DISTANCE_LOADED);
print "# select expression (function)\n";
my $query = new RDF::Query ( <<"END", undef, undef, 'sparql11' );
PREFIX dcterms: <http://purl.org/dc/terms/>
Expand Down
14 changes: 7 additions & 7 deletions RDF-Query/t/filters.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ my @models = test_models( @files );
my $tests = 0 + (scalar(@models) * 46);
plan tests => $tests;

eval "use Geo::Distance 0.09;";
eval "use GIS::Distance;";
my $GEO_DISTANCE_LOADED = ($@) ? 0 : 1;

use RDF::Query;
Expand Down Expand Up @@ -137,7 +137,7 @@ END
}

SKIP: {
skip( "Need Geo::Distance 0.09 or higher to run these tests.", 4 ) unless ($GEO_DISTANCE_LOADED);
skip( "Need GIS::Distance to run these tests.", 4 ) unless ($GEO_DISTANCE_LOADED);
print "# FILTER geo:distance(...)\n";
my $sparql = <<"END";
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
Expand All @@ -158,17 +158,17 @@ END
my $query = RDF::Query->new( $sparql, undef, undef, 'sparql' );
$query->add_function( 'http://kasei.us/e/ns/geo#distance', sub {
my $query = shift;
my $geo = new Geo::Distance;
my $geo = new GIS::Distance;
my $point = shift;
my $plat = get_first_literal( $model, $point, 'http://www.w3.org/2003/01/geo/wgs84_pos#lat' );
my $plon = get_first_literal( $model, $point, 'http://www.w3.org/2003/01/geo/wgs84_pos#long' );
my ($lat, $lon) = map { Scalar::Util::blessed($_) ? $_->literal_value : $_ } @_;
my $dist = $geo->distance(
'kilometer',
$lon,
# 'kilometer',
$lat,
$lon,
$plat,
$plon,
$plat
);
# warn "\t-> ${dist} kilometers from Providence";
return RDF::Query::Node::Literal->new("$dist", undef, 'http://www.w3.org/2001/XMLSchema#float');
Expand Down Expand Up @@ -295,7 +295,7 @@ END

SKIP: {
local($RDF::Query::error) = 1;
skip( "Need Geo::Distance 0.09 or higher to run these tests.", 4 ) unless ($GEO_DISTANCE_LOADED);
skip( "Need GIS::Distance to run these tests.", 4 ) unless ($GEO_DISTANCE_LOADED);
my $sparql = <<"END";
PREFIX ldodds: <java:com.ldodds.sparql.>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
Expand Down

0 comments on commit 616df42

Please sign in to comment.