-
Notifications
You must be signed in to change notification settings - Fork 135
/
spatial.rb
137 lines (123 loc) · 4.35 KB
/
spatial.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
module Neography
class Rest
module Spatial
include Neography::Rest::Helpers
def get_spatial
@connection.get("/ext/SpatialPlugin")
end
def add_point_layer(layer, lat = nil, lon = nil)
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("/ext/SpatialPlugin/graphdb/addSimplePointLayer", options)
end
def add_editable_layer(layer, format = "WKT", node_property_name = "wkt")
options = {
:body => {
:layer => layer,
:format => format,
:nodePropertyName => node_property_name
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}
@connection.post("/ext/SpatialPlugin/graphdb/addEditableLayer", options)
end
def get_layer(layer)
options = {
:body => {
:layer => layer
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}
@connection.post("/ext/SpatialPlugin/graphdb/getLayer", options)
end
def add_geometry_to_layer(layer, geometry)
options = {
:body => {
:layer => layer,
:geometry => geometry
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}
@connection.post("/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer", options)
end
def edit_geometry_from_layer(layer, geometry, node)
options = {
:body => {
:layer => layer,
:geometry => geometry,
:geometryNodeId => get_id(node)
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}
@connection.post("/ext/SpatialPlugin/graphdb/updateGeometryFromWKT", options)
end
def add_node_to_layer(layer, node)
options = {
:body => {
:layer => layer,
:node => get_id(node)
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}
@connection.post("/ext/SpatialPlugin/graphdb/addNodeToLayer", options)
end
def find_geometries_in_bbox(layer, minx, maxx, miny, maxy)
options = {
:body => {
:layer => layer,
:minx => minx,
:maxx => maxx,
:miny => miny,
:maxy => maxy
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}
@connection.post("/ext/SpatialPlugin/graphdb/findGeometriesInBBox", options)
end
def find_geometries_within_distance(layer, pointx, pointy, distance)
options = {
:body => {
:layer => layer,
:pointX => pointx,
:pointY => pointy,
:distanceInKm => distance
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}
@connection.post("/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance", options)
end
def create_spatial_index(name, type = nil, lat = nil, lon = nil)
options = {
:body => {
:name => name,
:config => {
:provider => "spatial",
:geometry_type => type || "point",
:lat => lat || "lat",
:lon => lon || "lon"
}
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}
@connection.post("/index/node", options)
end
def add_node_to_spatial_index(index, id)
options = {
:body => {
:uri => @connection.configuration + "/node/#{get_id(id)}",
:key => "k",
:value => "v"
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}
@connection.post("/index/node/%{index}" % {:index => index}, options)
end
end
end
end