Module: Neo4j::Core::Spatial
- Included in:
- CypherSession
- Defined in:
- lib/neo4j/spatial.rb
Instance Method Summary collapse
- #add_layer(name, type = nil, lat = nil, lon = nil) ⇒ Object
-
#add_node_to_layer(layer, node, execute: true) ⇒ Object
Hmmm this one has trouble, because we actually need to MATCH the node itself…
- #add_point_layer(layer) ⇒ Object
- #add_wkt(layer, geometry, execute: true) ⇒ Object
- #add_wkt_layer(layer, node_property_name = 'wkt') ⇒ Object
- #bbox(layer, min, max, execute: true) ⇒ Object (also: #find_geometries_in_bbox)
-
#closest(layer, coordinate, distance = 100, execute: true) ⇒ Object
TODO: figure out what closest is supposed to do…
- #get_layer(layer, execute: true) ⇒ Object
- #import_shapefile_to_layer(layer, file_uri, execute: true) ⇒ Object
- #intersects(layer, geometry, execute: true) ⇒ Object
- #remove_layer(name) ⇒ Object
- #spatial? ⇒ Boolean
- #spatial_procedures ⇒ Object
- #update_from_wkt(layer, geometry, node, execute: true) ⇒ Object
- #within_distance(layer, coordinate, distance, execute: true) ⇒ Object (also: #find_geometries_within_distance)
Instance Method Details
#add_layer(name, type = nil, lat = nil, lon = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/neo4j/spatial.rb', line 15 def add_layer(name, type = nil, lat = nil, lon = nil) # supported names for type are: 'SimplePoint', 'WKT', 'WKB' type ||= 'SimplePoint' = { name: name, type: type || 'point', encoderConfig: "#{lon || 'lon'}:#{lat || 'lat'}" } wrap_spatial_procedure('addLayer', ) end |
#add_node_to_layer(layer, node, execute: true) ⇒ Object
Hmmm this one has trouble, because we actually need to MATCH the node itself… Wish this could be cleaner but for now it works…
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/neo4j/spatial.rb', line 71 def add_node_to_layer(layer, node, execute: true) query_ = Query.new(session: self) procedure = query_.match(:n) .where('id(n) = {node_id}') .with(:n).call('spatial.addNode({layer}, n) YIELD node') .return('node') .params(layer: layer, node_id: node.neo_id) procedure = execute_and_format_response(procedure) if execute procedure end |
#add_point_layer(layer) ⇒ Object
32 33 34 35 36 |
# File 'lib/neo4j/spatial.rb', line 32 def add_point_layer(layer) = {layer: layer} wrap_spatial_procedure('addPointLayer', ) end |
#add_wkt(layer, geometry, execute: true) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/neo4j/spatial.rb', line 52 def add_wkt(layer, geometry, execute: true) = { layer: layer, geometry: geometry } wrap_spatial_procedure('addWKT', , execute: execute) end |
#add_wkt_layer(layer, node_property_name = 'wkt') ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/neo4j/spatial.rb', line 38 def add_wkt_layer(layer, node_property_name = 'wkt') = { layer: layer, node_property_name: node_property_name } wrap_spatial_procedure('addWKTLayer', ) end |
#bbox(layer, min, max, execute: true) ⇒ Object Also known as: find_geometries_in_bbox
83 84 85 86 87 |
# File 'lib/neo4j/spatial.rb', line 83 def bbox(layer, min, max, execute: true) = {layer: layer, min: min, max: max} wrap_spatial_procedure('bbox', , execute: execute) end |
#closest(layer, coordinate, distance = 100, execute: true) ⇒ Object
TODO: figure out what closest is supposed to do…
108 109 110 111 112 113 114 115 116 |
# File 'lib/neo4j/spatial.rb', line 108 def closest(layer, coordinate, distance = 100, execute: true) = { layer: layer, coordinate: coordinate, distanceInKm: distance } wrap_spatial_procedure('closest', , execute: execute) end |
#get_layer(layer, execute: true) ⇒ Object
47 48 49 50 |
# File 'lib/neo4j/spatial.rb', line 47 def get_layer(layer, execute: true) = {layer: layer} wrap_spatial_procedure('layer', , execute: execute) end |
#import_shapefile_to_layer(layer, file_uri, execute: true) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/neo4j/spatial.rb', line 118 def import_shapefile_to_layer(layer, file_uri, execute: true) = {layer: layer, file_uri: file_uri} execution_args = {execute: execute, node: false} wrap_spatial_procedure('importShapefileToLayer', , execution_args) end |
#intersects(layer, geometry, execute: true) ⇒ Object
101 102 103 104 105 |
# File 'lib/neo4j/spatial.rb', line 101 def intersects(layer, geometry, execute: true) = {layer: layer, geometry: geometry} wrap_spatial_procedure('intersects', , execute: execute) end |
#remove_layer(name) ⇒ Object
27 28 29 30 |
# File 'lib/neo4j/spatial.rb', line 27 def remove_layer(name) = {name: name} wrap_spatial_procedure('removeLayer', , node: false) end |
#spatial? ⇒ Boolean
4 5 6 7 8 9 |
# File 'lib/neo4j/spatial.rb', line 4 def spatial? spatial_procedures true rescue Neo4j::Core::CypherSession::CypherError false end |
#spatial_procedures ⇒ Object
11 12 13 |
# File 'lib/neo4j/spatial.rb', line 11 def spatial_procedures query('CALL spatial.procedures() YIELD name').map(&:name) end |
#update_from_wkt(layer, geometry, node, execute: true) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/neo4j/spatial.rb', line 60 def update_from_wkt(layer, geometry, node, execute: true) = { layer: layer, geometry: geometry, geometryNodeId: get_id(node) } wrap_spatial_procedure('updateFromWKT', , execute: execute) end |
#within_distance(layer, coordinate, distance, execute: true) ⇒ Object Also known as: find_geometries_within_distance
90 91 92 93 94 95 96 97 98 |
# File 'lib/neo4j/spatial.rb', line 90 def within_distance(layer, coordinate, distance, execute: true) = { layer: layer, coordinate: coordinate, distanceInKm: distance } wrap_spatial_procedure('withinDistance', , execute: execute) end |