Skip to content

Commit

Permalink
passing spatial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jan 27, 2014
1 parent 0465e80 commit 4371c20
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 45 deletions.
30 changes: 30 additions & 0 deletions spec/integration/mh_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'

describe Neography::Rest do
before(:each) do
@neo = Neography::Rest.new
end

describe "the spatial plugin works" do
it "better work" do
@neo.create_spatial_index("geom", "point", "lat", "lon")
node = @neo.create_node({:lat => 60.1, :lon => 15.2})
added = @neo.add_node_to_index("geom", "dummy", "dummy", node)
existing_node = @neo.execute_query("start node = node:geom('withinDistance:[60.0,15.0, 100.0]') return node")
puts existing_node.inspect
end

it "can find a geometry in a bounding box using cypher" do
properties = {:lat => 60.1, :lon => 15.2}
@neo.create_spatial_index("geombbcypher", "point", "lat", "lon")
node = @neo.create_node(properties)
added = @neo.add_node_to_index("geombbcypher", "dummy", "dummy", node)
existing_node = @neo.execute_query("start node = node:geombbcypher('withinDistance:[60.0,15.0, 100.0]') return node")
puts existing_node.inspect
existing_node["data"][0][0]["data"].should_not be_empty
existing_node["data"][0][0]["data"]["lat"].should == properties[:lat]
existing_node["data"][0][0]["data"]["lon"].should == properties[:lon]
end

end
end
63 changes: 18 additions & 45 deletions spec/integration/rest_spatial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@
end

it "can find a geometry in a bounding box using cypher" do
node = @neo.execute_query("start n = node:restaurants({bbox}) return n", {:bbox => "bbox:[87.5,87.7,41.7,41.9]"})
#node = @neo.execute_query("start n = node:restaurants({bbox}) return n", {:bbox => "bbox:[87.6278,41.8819,87.6278,41.8819]"})
node.should_not be_empty
puts node.inspect
node.first["data"]["lat"].should == properties[:lat]
node.first["data"]["lon"].should == properties[:lon]
node.first["data"]["name"].should == "Max's Restaurant"
properties = {:lat => 60.1, :lon => 15.2}
@neo.create_spatial_index("geombbcypher", "point", "lat", "lon")
node = @neo.create_node(properties)
added = @neo.add_node_to_index("geombbcypher", "dummy", "dummy", node)
existing_node = @neo.execute_query("start node = node:geombbcypher('bbox:[15.0,15.3,60.0,60.2]') return node")
existing_node.should_not be_empty
existing_node["data"][0][0]["data"]["lat"].should == properties[:lat]
existing_node["data"][0][0]["data"]["lon"].should == properties[:lon]
end
end

Expand All @@ -125,44 +126,16 @@
end

it "can find a geometry within distance using cypher" do
properties = {:name => "Max's Restaurant", :lat => 41.8819, :lon => 87.6278}
node = @neo.execute_query("start n = node:restaurants({bbox}) return n", {:bbox => "withinDistance:[87.6278,41.8819,10.0]"})
node.should_not be_empty
puts node.inspect
node.first["data"]["lat"].should == properties[:lat]
node.first["data"]["lon"].should == properties[:lon]
node.first["data"]["name"].should == "Max's Restaurant"
end
end

describe "complete example" do
it "can do what the manual does" do
@neo.add_point_layer("geom", "lat", "lon")
node = @neo.create_node({:lat => 60.1, :lon => 15.2})
@neo.create_spatial_index("geom", "point", "lat", "lon")
@neo.add_node_to_layer("geom", node)

existing_node = @neo.find_geometries_in_bbox("geom", 15.0,15.3,60.0,60.3)
existing_node.first["data"]["lat"].should == 60.1
existing_node.first["data"]["lon"].should == 15.2

existing_node = @neo.find_geometries_within_distance("geom", 15.0, 60.0, 100.0)
existing_node.first["data"]["lat"].should == 60.1
existing_node.first["data"]["lon"].should == 15.2

added = @neo.add_node_to_index("geom", "dummy", "dummy", node)
existing_node = @neo.execute_query("start node = node:geom(\'bbox:[15.0,15.3,60.0,60.2]\') return node")
puts existing_node.inspect
existing_node.first["data"]["lat"].should == 60.1
existing_node.first["data"]["lon"].should == 15.2

existing_node = @neo.execute_query("start node = node:geom(\'withinDistance:[60.0,15.0, 100.0]\') return node")
puts existing_node.inspect
existing_node.first["data"]["lat"].should == 60.1
existing_node.first["data"]["lon"].should == 15.2

properties = {:lat => 60.1, :lon => 15.2}
@neo.create_spatial_index("geowdcypher", "point", "lat", "lon")
node = @neo.create_node(properties)
added = @neo.add_node_to_index("geowdcypher", "dummy", "dummy", node)
existing_node = @neo.execute_query("start n = node:geowdcypher({bbox}) return n", {:bbox => "withinDistance:[60.0,15.0,100.0]"})
existing_node.should_not be_empty
existing_node.should_not be_empty
existing_node["data"][0][0]["data"]["lat"].should == properties[:lat]
existing_node["data"][0][0]["data"]["lon"].should == properties[:lon]
end
end



end

0 comments on commit 4371c20

Please sign in to comment.