the_geom_geojson 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG +6 -0
- data/lib/the_geom_geojson/active_record.rb +9 -4
- data/lib/the_geom_geojson/version.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/the_geom_geojson/active_record_spec.rb +13 -25
- 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: fff860aa315c7be49742c15cb2721b987c60a767
|
4
|
+
data.tar.gz: 78f1b9205edcbaa42bc10762fe9fbcdce91ee66d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc6fd10e4092e17d8060410eef982a4ccd09ab869fc4e951a234d28a4e23c77a43ea70d62c523c98d1f04f020747ac10c340c6e8d91e48a1ab6ef9020bca30f7
|
7
|
+
data.tar.gz: 20a5680eaee7bbfaaa2ae14f59c95664942a6c1e90b8c50b1e4a2869cb6dce1a6e111dabac4519395f01e66bb1a9bebfbc6067f532ed7319b6c322b0cec2cf2b
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
@@ -45,14 +45,19 @@ module TheGeomGeoJSON
|
|
45
45
|
end
|
46
46
|
|
47
47
|
|
48
|
-
def the_geom_geojson
|
48
|
+
def the_geom_geojson(simplify: nil)
|
49
49
|
if @the_geom_geojson_dirty
|
50
|
-
@the_geom_geojson_change
|
51
|
-
elsif preselected = read_attribute(:the_geom_geojson)
|
50
|
+
simplify ? raise("can't get simplified the_geom_geojson until you save") : @the_geom_geojson_change
|
51
|
+
elsif !simplify and (preselected = read_attribute(:the_geom_geojson))
|
52
52
|
preselected
|
53
53
|
elsif the_geom
|
54
54
|
self.class.connection_pool.with_connection do |c|
|
55
|
-
|
55
|
+
sql = if simplify
|
56
|
+
"SELECT ST_AsGeoJSON(ST_Simplify(the_geom, #{c.quote(simplify)}::float)) FROM #{self.class.quoted_table_name} WHERE #{self.class.quoted_primary_key} = #{c.quote(id)} LIMIT 1"
|
57
|
+
else
|
58
|
+
"SELECT ST_AsGeoJSON(the_geom) FROM #{self.class.quoted_table_name} WHERE #{self.class.quoted_primary_key} = #{c.quote(id)} LIMIT 1"
|
59
|
+
end
|
60
|
+
c.select_value sql
|
56
61
|
end
|
57
62
|
end
|
58
63
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -18,10 +18,6 @@ require 'securerandom'
|
|
18
18
|
|
19
19
|
ActiveRecord::Base.establish_connection "postgresql://127.0.0.1/#{dbname}"
|
20
20
|
|
21
|
-
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.tap do |klass|
|
22
|
-
klass::OID.register_type('geometry', klass::OID::Identity.new)
|
23
|
-
end
|
24
|
-
|
25
21
|
require 'the_geom_geojson/active_record'
|
26
22
|
|
27
23
|
class Pet < ActiveRecord::Base
|
@@ -61,19 +57,8 @@ end
|
|
61
57
|
|
62
58
|
describe TheGeomGeoJSON do
|
63
59
|
describe 'ActiveRecord' do
|
64
|
-
|
65
|
-
|
66
|
-
# ----------------------------------------------------
|
67
|
-
# 0101000020E61000003108AC1C5A4C52C0931804560E3D4640
|
68
|
-
# (1 row)
|
69
|
-
let(:the_geom_expected) { '0101000020E61000003108AC1C5A4C52C0931804560E3D4640' }
|
70
|
-
|
71
|
-
# # SELECT ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-73.193,44.477]}'), 4326), 3857);
|
72
|
-
# st_transform
|
73
|
-
# ----------------------------------------------------
|
74
|
-
# 0101000020110F0000C22156DFD7145FC10858288EB9215541
|
75
|
-
# (1 row)
|
76
|
-
let(:the_geom_webmercator_expected) { '0101000020110F0000C22156DFD7145FC10858288EB9215541' }
|
60
|
+
let(:the_geom_expected) { '0103000020E6100000010000000600000083C0CAA1454E52C0022B8716D93E46406DE7FBA9F14A52C01F85EB51B83E4640D34D6210584952C0F0A7C64B373946402FDD2406814D52C0D578E926313846402DB29DEFA74E52C04260E5D0223B464083C0CAA1454E52C0022B8716D93E4640' }
|
61
|
+
let(:the_geom_webmercator_expected) { '0103000020110F00000100000006000000213FC2C41A185FC1B8ACA6A9DB2355417F507E9D73125FC1B31193A6B4235541B0E24EDEBB0F5FC1CCA725C4271D5541FACC63CFCC165FC16AE385ECEF1B5541337871BFC1185FC1F8C0EA95701F5541213FC2C41A185FC1B8ACA6A9DB235541' }
|
77
62
|
|
78
63
|
before do
|
79
64
|
Pet.delete_all
|
@@ -87,20 +72,23 @@ describe TheGeomGeoJSON do
|
|
87
72
|
expect(@pet.the_geom_webmercator).to eq(the_geom_webmercator_expected)
|
88
73
|
end
|
89
74
|
it "lets you access the_geom_geojson" do
|
90
|
-
expect(@pet.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:
|
75
|
+
expect(@pet.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington])
|
76
|
+
end
|
77
|
+
it "lets you access a simplified the_geom_geojson" do
|
78
|
+
expect(@pet.the_geom_geojson(simplify: 0.03).length).to be < @pet.the_geom_geojson.length
|
91
79
|
end
|
92
80
|
it "can be loaded from db" do
|
93
81
|
if @pet.persisted?
|
94
82
|
reloaded = pet_model.find @pet.id
|
95
83
|
expect(reloaded.the_geom).to eq(the_geom_expected)
|
96
84
|
expect(reloaded.the_geom_webmercator).to eq(the_geom_webmercator_expected)
|
97
|
-
expect(reloaded.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:
|
85
|
+
expect(reloaded.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington])
|
98
86
|
end
|
99
87
|
end
|
100
88
|
it "can be loaded with .with_geojson scope" do
|
101
89
|
if @pet.persisted?
|
102
90
|
reloaded = pet_model.with_geojson.find @pet.id
|
103
|
-
expect(reloaded.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:
|
91
|
+
expect(reloaded.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington])
|
104
92
|
end
|
105
93
|
end
|
106
94
|
end
|
@@ -108,14 +96,14 @@ describe TheGeomGeoJSON do
|
|
108
96
|
shared_examples 'different states of persistence' do
|
109
97
|
describe "creating" do
|
110
98
|
before do
|
111
|
-
@pet = create_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:
|
99
|
+
@pet = create_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington]
|
112
100
|
end
|
113
101
|
it_behaves_like 'the_geom_geojson=(geojson)'
|
114
102
|
end
|
115
103
|
|
116
104
|
describe "building and saving" do
|
117
105
|
before do
|
118
|
-
@pet = build_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:
|
106
|
+
@pet = build_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington]
|
119
107
|
@pet.save!
|
120
108
|
end
|
121
109
|
it_behaves_like 'the_geom_geojson=(geojson)'
|
@@ -124,7 +112,7 @@ describe TheGeomGeoJSON do
|
|
124
112
|
describe "modifying" do
|
125
113
|
before do
|
126
114
|
@pet = create_pet
|
127
|
-
@pet.the_geom_geojson = TheGeomGeoJSON::EXAMPLES[:
|
115
|
+
@pet.the_geom_geojson = TheGeomGeoJSON::EXAMPLES[:burlington]
|
128
116
|
@pet.save!
|
129
117
|
end
|
130
118
|
it_behaves_like 'the_geom_geojson=(geojson)'
|
@@ -132,7 +120,7 @@ describe TheGeomGeoJSON do
|
|
132
120
|
|
133
121
|
describe "building (without saving)" do
|
134
122
|
before do
|
135
|
-
@pet = build_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:
|
123
|
+
@pet = build_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington]
|
136
124
|
end
|
137
125
|
it "raises exception if you try to access the_geom" do
|
138
126
|
expect{@pet.the_geom}.to raise_error(TheGeomGeoJSON::Dirty)
|
@@ -141,7 +129,7 @@ describe TheGeomGeoJSON do
|
|
141
129
|
expect{@pet.the_geom_webmercator}.to raise_error(TheGeomGeoJSON::Dirty)
|
142
130
|
end
|
143
131
|
it "lets you access the_geom_geojson" do
|
144
|
-
expect(@pet.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:
|
132
|
+
expect(@pet.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington])
|
145
133
|
end
|
146
134
|
end
|
147
135
|
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seamus Abshere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|