Permalink
Browse files

implemented inside_haversine geo method

  • Loading branch information...
Philipp Brüll
Philipp Brüll committed Mar 28, 2010
1 parent b3e981e commit 0bb227e554f10c0ad99e524158bfd3b72badc788
@@ -79,6 +79,30 @@ def inside_circle(type, predicate, x, y, radius)
@server.request :get, self.path + "/circle", :parameters => parameters, :expected_status_code => 200
end
+ def inside_haversine(type, predicate, latitude, longitude, radius, unit = :km)
+ parameters = {
+ :type => type,
+ :predicate => predicate,
+ :lat => float_to_iso_6709(latitude, 2),
+ :long => float_to_iso_6709(longitude, 3),
+ :radius => radius.to_s,
+ :unit => unit.to_s
+ }
+ @server.request :get, self.path + "/haversine", :parameters => parameters, :expected_status_code => 200
+ end
+
+ private
+
+ def float_to_iso_6709(value, digits)
+ sign = "+"
+ if value < 0
+ sign = "-"
+ value = -value
+ end
+ floor = value.to_i
+ sign + (("%%0%dd" % digits) % floor) + (".%07d" % ((value - floor) * 10000000))
+ end
+
end
end
View
@@ -202,3 +202,17 @@
:code: "200"
:body:
- [ "\"test_subject\"", "\"at\"", "\"+10.000000000931323+10.000000000931323\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>" ]
+-
+ :http_method: "get"
+ :url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/geo/haversine"
+ :parameters:
+ :type: "<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
+ :predicate: "\"at\""
+ :lat: "+09.0000000"
+ :long: "+009.0000000"
+ :radius: "200.0"
+ :unit: "km"
+ :response:
+ :code: "200"
+ :body:
+ - [ "\"test_subject\"", "\"at\"", "\"+100000+0100000\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/spherical/degrees/2.0/20.0/2.0/20.0/1.0>" ]
@@ -199,7 +199,7 @@
end
- context "with statements" do
+ context "in a cartesian system" do
before :each do
@type = @geo.cartesian_type 1.0, 2.0, 2.0, 20.0, 20.0
@@ -218,6 +218,20 @@
end
+ context "in a spherical system" do
+
+ before :each do
+ @type = @geo.spherical_type 1.0, :degree, 2.0, 2.0, 20.0, 20.0
+ @repository.statements.create "\"test_subject\"", "\"at\"", "\"+10.00+010.00\"^^#{@type}"
+ end
+
+ it "should find objects inside a haversine" do
+ result = @geo.inside_haversine @type, "\"at\"", 9.0, 9.0, 200.0, :km
+ result.should include([ "\"test_subject\"", "\"at\"", "\"+100000+0100000\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/spherical/degrees/2.0/20.0/2.0/20.0/1.0>"])
+ end
+
+ end
+
end
end
@@ -68,4 +68,13 @@
end
+ describe "inside_haversine" do
+
+ it "should find objects inside a haversine" do
+ result = @geo.inside_haversine @type, "\"at\"", 9.0, 9.0, 200.0, :km
+ result.should include([ "\"test_subject\"", "\"at\"", "\"+100000+0100000\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/spherical/degrees/2.0/20.0/2.0/20.0/1.0>"])
+ end
+
+ end
+
end

0 comments on commit 0bb227e

Please sign in to comment.