the_geom_geojson 0.0.5 → 0.1.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/CHANGELOG +13 -0
- data/lib/the_geom_geojson.rb +7 -0
- data/lib/the_geom_geojson/active_record.rb +11 -3
- data/lib/the_geom_geojson/version.rb +1 -1
- data/spec/the_geom_geojson/active_record_spec.rb +33 -15
- 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: b0cb34abb081e5fdf3f64760adc9b8ed2a4b2690
|
4
|
+
data.tar.gz: c370e1e32937b9bdf8b0f668dfdea446f224df75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7286bb6c4c26277a6e18a5c2598e8068e4e1057ad569e820cfa625e890263a6801866912ecf1d423b170908b1bbeb30514681c7c890de5135f004375ccf58f70
|
7
|
+
data.tar.gz: 43525ed84188d6306b38803a783912397b5260caf39781d3bebf6659e8d75b324b76dd218d0459dd631f1ceec34d7c21ef39202263aedff4b5e8ae2e6f29e6f3
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
0.1.0 / 2014-10-19
|
2
|
+
|
3
|
+
* Breaking changes
|
4
|
+
|
5
|
+
* Provide .with_geojson scope for faster #the_geom_geojson accesses (RGeo is WAY slower than ST_AsGeoJSON)
|
6
|
+
|
7
|
+
* Enhancements
|
8
|
+
|
9
|
+
* Much faster than 0.0.5 if you use .with_geojson scope; unlike 0.0.4, works even if you don't
|
10
|
+
* Opportunistically use read_attribute(:the_geom_geojson) if the user has included it in their SELECT
|
11
|
+
* Provide TheGeomGeoJSON.ewkb_to_geojson(ewkb)
|
12
|
+
* Warn when EWKB->GeoJSON parsing is taking too long
|
13
|
+
|
1
14
|
0.0.5 / 2014-10-17
|
2
15
|
|
3
16
|
* Enhancements
|
data/lib/the_geom_geojson.rb
CHANGED
@@ -5,4 +5,11 @@ require 'rgeo/geo_json'
|
|
5
5
|
|
6
6
|
module TheGeomGeoJSON
|
7
7
|
Dirty = Class.new(RuntimeError)
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def ewkb_to_geojson(ewkb)
|
11
|
+
parser = RGeo::WKRep::WKBParser.new nil, support_ewkb: true
|
12
|
+
JSON.dump RGeo::GeoJSON.encode(parser.parse(ewkb))
|
13
|
+
end
|
14
|
+
end
|
8
15
|
end
|
@@ -3,6 +3,8 @@ module TheGeomGeoJSON
|
|
3
3
|
class << self
|
4
4
|
def included(model)
|
5
5
|
model.class_eval do
|
6
|
+
scope :with_geojson, -> { select('*', 'ST_AsGeoJSON(the_geom) AS the_geom_geojson') }
|
7
|
+
|
6
8
|
after_save do
|
7
9
|
if @the_geom_geojson_dirty
|
8
10
|
raise "can't update the_geom without an id" if id.nil?
|
@@ -42,13 +44,19 @@ module TheGeomGeoJSON
|
|
42
44
|
@the_geom_geojson_change = v
|
43
45
|
end
|
44
46
|
|
45
|
-
|
47
|
+
|
46
48
|
def the_geom_geojson
|
47
49
|
if @the_geom_geojson_dirty
|
48
50
|
@the_geom_geojson_change
|
51
|
+
elsif preselected = read_attribute(:the_geom_geojson)
|
52
|
+
preselected
|
49
53
|
elsif the_geom
|
50
|
-
|
51
|
-
|
54
|
+
started_at = Time.now
|
55
|
+
memo = TheGeomGeoJSON.ewkb_to_geojson the_geom
|
56
|
+
if (elapsed = Time.now - started_at) > 0.1
|
57
|
+
$stderr.puts "[the_geom_geojson] EWKB->GeoJSON parsing took #{elapsed}s, recommend using #{self.class.name}.with_geojson scope"
|
58
|
+
end
|
59
|
+
memo
|
52
60
|
end
|
53
61
|
end
|
54
62
|
|
@@ -89,6 +89,20 @@ describe TheGeomGeoJSON do
|
|
89
89
|
it "lets you access the_geom_geojson" do
|
90
90
|
expect(@pet.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington_point])
|
91
91
|
end
|
92
|
+
it "can be loaded from db" do
|
93
|
+
if @pet.persisted?
|
94
|
+
reloaded = pet_model.find @pet.id
|
95
|
+
expect(reloaded.the_geom).to eq(the_geom_expected)
|
96
|
+
expect(reloaded.the_geom_webmercator).to eq(the_geom_webmercator_expected)
|
97
|
+
expect(reloaded.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington_point])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
it "can be loaded with .with_geojson scope" do
|
101
|
+
if @pet.persisted?
|
102
|
+
reloaded = pet_model.with_geojson.find @pet.id
|
103
|
+
expect(reloaded.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington_point])
|
104
|
+
end
|
105
|
+
end
|
92
106
|
end
|
93
107
|
|
94
108
|
shared_examples 'different states of persistence' do
|
@@ -132,37 +146,38 @@ describe TheGeomGeoJSON do
|
|
132
146
|
end
|
133
147
|
end
|
134
148
|
|
149
|
+
def create_pet(attrs = {})
|
150
|
+
pet_model.create! attrs
|
151
|
+
end
|
152
|
+
def build_pet(attrs = {})
|
153
|
+
pet_model.new attrs
|
154
|
+
end
|
155
|
+
|
135
156
|
describe "with autoincrement id" do
|
136
|
-
def
|
137
|
-
Pet
|
138
|
-
end
|
139
|
-
def build_pet(attrs = {})
|
140
|
-
Pet.new attrs
|
157
|
+
def pet_model
|
158
|
+
Pet
|
141
159
|
end
|
142
160
|
it_behaves_like 'different states of persistence'
|
143
161
|
end
|
144
162
|
|
145
163
|
describe "with alt id" do
|
146
|
-
def
|
147
|
-
PetAltId
|
148
|
-
end
|
149
|
-
def build_pet(attrs = {})
|
150
|
-
PetAltId.new attrs
|
164
|
+
def pet_model
|
165
|
+
PetAltId
|
151
166
|
end
|
152
167
|
it_behaves_like 'different states of persistence'
|
153
168
|
end
|
154
169
|
|
155
170
|
describe "with auto-generating uuid" do
|
156
|
-
def
|
157
|
-
PetAutoUuid
|
158
|
-
end
|
159
|
-
def build_pet(attrs = {})
|
160
|
-
PetAutoUuid.new attrs
|
171
|
+
def pet_model
|
172
|
+
PetAutoUuid
|
161
173
|
end
|
162
174
|
it_behaves_like 'different states of persistence'
|
163
175
|
end
|
164
176
|
|
165
177
|
describe "with text id" do
|
178
|
+
def pet_model
|
179
|
+
PetTextId
|
180
|
+
end
|
166
181
|
def create_pet(attrs = {})
|
167
182
|
PetTextId.create! attrs.reverse_merge(id: rand.to_s)
|
168
183
|
end
|
@@ -173,6 +188,9 @@ describe TheGeomGeoJSON do
|
|
173
188
|
end
|
174
189
|
|
175
190
|
describe "with uuid id" do
|
191
|
+
def pet_model
|
192
|
+
PetUuid
|
193
|
+
end
|
176
194
|
def create_pet(attrs = {})
|
177
195
|
PetUuid.create! attrs.reverse_merge(id: SecureRandom.uuid)
|
178
196
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_geom_geojson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seamus Abshere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|