Skip to content

Commit

Permalink
starting on spatial
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jan 24, 2014
1 parent 292304c commit c9da4c1
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
require 'neography/rest/batch'
require 'neography/rest/clean'
require 'neography/rest/transactions'
require 'neography/rest/spatial'

require 'neography/errors'

Expand Down Expand Up @@ -69,6 +70,7 @@ def initialize(options = ENV['NEO4J_URL'] || {})
@batch = Batch.new(@connection)
@clean = Clean.new(@connection)
@transactions = Transactions.new(@connection)
@spatial = Spatial.new(@connection)
end

# meta-data
Expand Down Expand Up @@ -452,6 +454,16 @@ def batch(*args)
def batch_not_streaming(*args)
@batch.not_streaming(*args)
end

# spatial

def get_spatial
@spatial.index
end

def add_point_layer(layer, lat = nil, lon = nil)
@spatial.add_point_layer(layer, lat, lon)
end

# clean database

Expand Down
54 changes: 54 additions & 0 deletions lib/neography/rest/spatial.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module Neography
class Rest
class Spatial
extend Neography::Rest::Paths
include Neography::Rest::Helpers

add_path :index, "/ext/SpatialPlugin"
add_path :add_simple_point_layer, "/ext/SpatialPlugin/graphdb/addSimplePointLayer"
add_path :add_editable_layer, "/ext/SpatialPlugin/graphdb/addEditableLayer"
add_path :get_layer, "/ext/SpatialPlugin/graphdb/getLayer"
add_path :add_geometry_to_layer, "/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer"
add_path :edit_geometry_from_layer, "/ext/SpatialPlugin/graphdb/updateGeometryFromWKT"
add_path :add_node_to_layer, "/ext/SpatialPlugin/graphdb/addNodeToLayer"
add_path :find_geometries_in_bbox, "/ext/SpatialPlugin/graphdb/findGeometriesInBBox"
add_path :find_geometries_within_distance,"/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance"

def initialize(connection)
@connection = connection
end

def index
@connection.get(index_path)
end

def add_point_layer(layer, lat, lon)
options = {
:body => {
:layer => layer,
:lat => lat || "lat",
:lon => lon || "lon"
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}

@connection.post(add_simple_point_layer_path, options)
end

def add_editable_layer(layer, format = "WKT", node_property_name = "wkt")
options = {
:body => {
:layer => name,
:format => format,
:nodePropertyName => node_property_name
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}

@connection.post(add_editable_layer_path, options)
end


end
end
end
33 changes: 33 additions & 0 deletions spec/integration/rest_spatial_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

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

describe "find the spatial plugin" do
it "can get a description of the spatial plugin" do
si = @neo.get_spatial
si.should_not be_nil
si["graphdb"]["addEditableLayer"].should_not be_nil
end
end

describe "add a point layer" do
it "can add a simple point layer" do
pl = @neo.add_point_layer("restaurants")
pl.should_not be_nil
pl.first["data"]["layer"].should == "restaurants"
pl.first["data"]["geomencoder_config"].should == "lon:lat"
end

it "can add a simple point layer with lat and long" do
pl = @neo.add_point_layer("coffee_shops", "latitude", "longitude")
pl.should_not be_nil
pl.first["data"]["layer"].should == "coffee_shops"
pl.first["data"]["geomencoder_config"].should == "longitude:latitude"
end

end

end

0 comments on commit c9da4c1

Please sign in to comment.