geocoder-neo4j_spatial 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -4
- data/lib/geocoder/neo4j_spatial/version.rb +1 -1
- data/lib/geocoder/stores/neo4j.rb +27 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1414165c59044babc2c24f02a1b2d9539e4f66f1
|
4
|
+
data.tar.gz: 74bfbb8d7fe2d1fe81c063ccc402156382049747
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40c8aa7f3cf0749529d195663f808fee68b9367117c0fb6eb030d77dbb67bf5d4cdd6ed3e31ecc9f89704cf157a113552fc9d094a0f0d818d5a9cc98d86d3239
|
7
|
+
data.tar.gz: bf0536a402d7ef01a05e09c8ddec48a0a8ab8dc77787f42bf90c40adb48f699e6b5a59b7beba12f1f7f98afacac198700006a22e407cc77b1243b9e27cbe4c2e
|
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# Geocoder::Neo4jSpatial
|
2
2
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/geocoder/neo4j_spatial`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
3
|
## Installation
|
8
4
|
|
9
5
|
Add this line to your application's Gemfile:
|
@@ -46,10 +42,21 @@ end
|
|
46
42
|
Restaurant.near(location: 'Eiffel Tower', radius: 10.0).to_a
|
47
43
|
```
|
48
44
|
|
45
|
+
or
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
Restaurant.near(location: [48.85837009999999, 2.2944813], radius: 10.0).to_a
|
49
|
+
```
|
50
|
+
|
51
|
+
will generate following query:
|
52
|
+
|
49
53
|
```
|
50
54
|
CYPHER 9ms START result_restaurant = node:restaurants({spatial_params}) MATCH (result_restaurant:`Restaurant`) MATCH (result_restaurant:`Restaurant`) RETURN result_restaurant | {:spatial_params=>"withinDistance:[48.85837009999999, 2.2944813, 10.0]"}
|
51
55
|
```
|
52
56
|
|
57
|
+
* not implemented yet
|
58
|
+
- within_bounding_box
|
59
|
+
|
53
60
|
## Development
|
54
61
|
|
55
62
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -15,17 +15,27 @@ module Geocoder::Store
|
|
15
15
|
}
|
16
16
|
|
17
17
|
scope :near, -> (location:, radius:) {
|
18
|
-
|
18
|
+
if location.is_a?(Array)
|
19
|
+
coordinates = location << radius.to_f
|
19
20
|
|
20
|
-
|
21
|
-
coordinates << radius
|
22
|
-
|
23
|
-
query_proxy = instance_variable_get(:@query_proxy)
|
24
|
-
spatial_match(query_proxy.node_identity, "withinDistance:#{coordinates}")
|
21
|
+
within(coordinates)
|
25
22
|
else
|
26
|
-
|
23
|
+
coordinates = Geocoder::Calculations.extract_coordinates(location)
|
24
|
+
|
25
|
+
if Geocoder::Calculations.coordinates_present?(*coordinates)
|
26
|
+
coordinates << radius.to_f
|
27
|
+
|
28
|
+
within(coordinates)
|
29
|
+
else
|
30
|
+
[]
|
31
|
+
end
|
27
32
|
end
|
28
33
|
}
|
34
|
+
|
35
|
+
scope :within, -> (coordinates) {
|
36
|
+
query_proxy = instance_variable_get(:@query_proxy)
|
37
|
+
spatial_match(query_proxy.node_identity, "withinDistance:#{coordinates}")
|
38
|
+
}
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
@@ -33,8 +43,10 @@ module Geocoder::Store
|
|
33
43
|
do_lookup(false) do |o, rs|
|
34
44
|
if r = rs.first
|
35
45
|
unless r.latitude.nil? or r.longitude.nil?
|
36
|
-
o.__send__
|
37
|
-
o.__send__
|
46
|
+
o.__send__ "#{self.class.geocoder_options[:latitude]}=", r.latitude
|
47
|
+
o.__send__ "#{self.class.geocoder_options[:longitude]}=", r.longitude
|
48
|
+
|
49
|
+
o.add_to_spatial_index o.class.spatial_index_name
|
38
50
|
end
|
39
51
|
|
40
52
|
r.coordinates
|
@@ -53,5 +65,11 @@ module Geocoder::Store
|
|
53
65
|
end
|
54
66
|
end
|
55
67
|
end
|
68
|
+
|
69
|
+
def nearbys(radius = 20)
|
70
|
+
return nil unless geocoded?
|
71
|
+
|
72
|
+
self.class.near(location: to_coordinates, radius: radius)
|
73
|
+
end
|
56
74
|
end
|
57
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geocoder-neo4j_spatial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kajisha
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neo4j
|