the_geom_geojson 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/README.md +2 -0
- data/lib/the_geom_geojson/active_record.rb +2 -2
- data/lib/the_geom_geojson/version.rb +1 -1
- data/spec/the_geom_geojson/active_record_spec.rb +106 -24
- 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: fc02ba580ac039493fc7228507036db38174680d
|
4
|
+
data.tar.gz: a2516ef9680f359defc7656ac113cacf8a43033c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a1ca14c7a817883c4f1f2576e1915f8392925c49bf59c4cca56db60676bb19e3e54974caa5151a200563653f133f6cbd24f429776eb434e7827ffa41e83f56e
|
7
|
+
data.tar.gz: 8c4c00f3e442d4d1473a864302d1564838b16ef29b92b37a2a881710cbb67b7ee48bddcb709eebb3a81619c004c58f0334f5a5aec57d5c275f5b2a04ed75b299
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -6,6 +6,8 @@ For PostGIS/PostgreSQL and ActiveRecord, provides `the_geom_geojson` getter and
|
|
6
6
|
|
7
7
|
Web mapping libraries like [Leaflet](http://leafletjs.com/) often don't support PostGIS's native [Well-Known Binary (WKB) and Well-Known Text (WKT)](http://postgis.net/docs/using_postgis_dbmanagement.html#OpenGISWKBWKT) representation, but they do support [GeoJSON](http://geojson.org/), so this library helps translate between the two.
|
8
8
|
|
9
|
+
<img src="https://www.nyu.edu/greyart/exhibits/cisneros/images/garcianew.jpg" alt="Composición constructiva 16" />
|
10
|
+
|
9
11
|
## Requirements
|
10
12
|
|
11
13
|
* [PostgreSQL](postgresql.org) >=9
|
@@ -27,7 +27,7 @@ module TheGeomGeoJSON
|
|
27
27
|
memo << 'the_geom = ST_SetSRID(ST_GeomFromGeoJSON(?), 4326)' if has_the_geom
|
28
28
|
memo << ',' if has_the_geom && has_the_geom_webmercator
|
29
29
|
memo << 'the_geom_webmercator = ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON(?), 4326), 3857)' if has_the_geom_webmercator
|
30
|
-
memo <<
|
30
|
+
memo << " WHERE #{model.quoted_primary_key} = ?"
|
31
31
|
memo.join.freeze
|
32
32
|
end)
|
33
33
|
model.send :sanitize_sql_array, [sql, the_geom_geojson, the_geom_geojson, id]
|
@@ -48,7 +48,7 @@ module TheGeomGeoJSON
|
|
48
48
|
@the_geom_geojson_change
|
49
49
|
elsif id
|
50
50
|
self.class.connection_pool.with_connection do |c|
|
51
|
-
c.select_value "SELECT ST_AsGeoJSON(the_geom) FROM #{self.class.quoted_table_name} WHERE
|
51
|
+
c.select_value "SELECT ST_AsGeoJSON(the_geom) FROM #{self.class.quoted_table_name} WHERE #{self.class.quoted_primary_key} = #{c.quote(id)} LIMIT 1"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -5,10 +5,16 @@ unless ENV['FAST'] == 'true'
|
|
5
5
|
system 'dropdb', '--if-exists', dbname
|
6
6
|
system 'createdb', dbname
|
7
7
|
system 'psql', dbname, '--command', 'CREATE EXTENSION postgis'
|
8
|
+
system 'psql', dbname, '--command', 'CREATE EXTENSION "uuid-ossp"'
|
8
9
|
system 'psql', dbname, '--command', 'CREATE TABLE pets (id serial primary key, the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
|
10
|
+
system 'psql', dbname, '--command', 'CREATE TABLE pet_alt_ids (alt_id serial primary key, the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
|
11
|
+
system 'psql', dbname, '--command', 'CREATE TABLE pet_text_ids (id text unique not null, the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
|
12
|
+
system 'psql', dbname, '--command', 'CREATE TABLE pet_uuids (id uuid unique not null, the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
|
13
|
+
system 'psql', dbname, '--command', 'CREATE TABLE pet_auto_uuids (id uuid unique not null default uuid_generate_v4(), the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
|
9
14
|
end
|
10
15
|
|
11
16
|
require 'active_record'
|
17
|
+
require 'securerandom'
|
12
18
|
|
13
19
|
ActiveRecord::Base.establish_connection "postgresql://127.0.0.1/#{dbname}"
|
14
20
|
|
@@ -22,6 +28,30 @@ class Pet < ActiveRecord::Base
|
|
22
28
|
include TheGeomGeoJSON::ActiveRecord
|
23
29
|
end
|
24
30
|
|
31
|
+
class PetAltId < ActiveRecord::Base
|
32
|
+
include TheGeomGeoJSON::ActiveRecord
|
33
|
+
self.primary_key = 'alt_id'
|
34
|
+
end
|
35
|
+
|
36
|
+
class PetTextId < ActiveRecord::Base
|
37
|
+
include TheGeomGeoJSON::ActiveRecord
|
38
|
+
self.primary_key = 'id'
|
39
|
+
end
|
40
|
+
|
41
|
+
class PetUuid < ActiveRecord::Base
|
42
|
+
include TheGeomGeoJSON::ActiveRecord
|
43
|
+
self.primary_key = 'id'
|
44
|
+
end
|
45
|
+
|
46
|
+
class PetAutoUuid < ActiveRecord::Base
|
47
|
+
include TheGeomGeoJSON::ActiveRecord
|
48
|
+
self.primary_key = 'id'
|
49
|
+
|
50
|
+
before_save do
|
51
|
+
self.id ||= SecureRandom.uuid
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
25
55
|
if ENV['PRY'] == 'true'
|
26
56
|
require 'pry'
|
27
57
|
require 'logger'
|
@@ -61,43 +91,95 @@ describe TheGeomGeoJSON do
|
|
61
91
|
end
|
62
92
|
end
|
63
93
|
|
64
|
-
|
65
|
-
|
66
|
-
|
94
|
+
shared_examples 'different states of persistence' do
|
95
|
+
describe "creating" do
|
96
|
+
before do
|
97
|
+
@pet = create_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
|
98
|
+
end
|
99
|
+
it_behaves_like 'the_geom_geojson=(geojson)'
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "building and saving" do
|
103
|
+
before do
|
104
|
+
@pet = build_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
|
105
|
+
@pet.save!
|
106
|
+
end
|
107
|
+
it_behaves_like 'the_geom_geojson=(geojson)'
|
67
108
|
end
|
68
|
-
|
109
|
+
|
110
|
+
describe "modifying" do
|
111
|
+
before do
|
112
|
+
@pet = create_pet
|
113
|
+
@pet.the_geom_geojson = TheGeomGeoJSON::EXAMPLES[:burlington_point]
|
114
|
+
@pet.save!
|
115
|
+
end
|
116
|
+
it_behaves_like 'the_geom_geojson=(geojson)'
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "building (without saving)" do
|
120
|
+
before do
|
121
|
+
@pet = build_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
|
122
|
+
end
|
123
|
+
it "raises exception if you try to access the_geom" do
|
124
|
+
expect{@pet.the_geom}.to raise_error(TheGeomGeoJSON::Dirty)
|
125
|
+
end
|
126
|
+
it "raises exception if you try to access the_geom_webmercator" do
|
127
|
+
expect{@pet.the_geom_webmercator}.to raise_error(TheGeomGeoJSON::Dirty)
|
128
|
+
end
|
129
|
+
it "lets you access the_geom_geojson" do
|
130
|
+
expect(@pet.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington_point])
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "with autoincrement id" do
|
136
|
+
def create_pet(attrs = {})
|
137
|
+
Pet.create! attrs
|
138
|
+
end
|
139
|
+
def build_pet(attrs = {})
|
140
|
+
Pet.new attrs
|
141
|
+
end
|
142
|
+
it_behaves_like 'different states of persistence'
|
69
143
|
end
|
70
144
|
|
71
|
-
describe "
|
72
|
-
|
73
|
-
|
74
|
-
|
145
|
+
describe "with alt id" do
|
146
|
+
def create_pet(attrs = {})
|
147
|
+
PetAltId.create! attrs
|
148
|
+
end
|
149
|
+
def build_pet(attrs = {})
|
150
|
+
PetAltId.new attrs
|
75
151
|
end
|
76
|
-
it_behaves_like '
|
152
|
+
it_behaves_like 'different states of persistence'
|
77
153
|
end
|
78
154
|
|
79
|
-
describe "
|
80
|
-
|
81
|
-
|
82
|
-
@pet.the_geom_geojson = TheGeomGeoJSON::EXAMPLES[:burlington_point]
|
83
|
-
@pet.save!
|
155
|
+
describe "with auto-generating uuid" do
|
156
|
+
def create_pet(attrs = {})
|
157
|
+
PetAutoUuid.create! attrs
|
84
158
|
end
|
85
|
-
|
159
|
+
def build_pet(attrs = {})
|
160
|
+
PetAutoUuid.new attrs
|
161
|
+
end
|
162
|
+
it_behaves_like 'different states of persistence'
|
86
163
|
end
|
87
164
|
|
88
|
-
describe "
|
89
|
-
|
90
|
-
|
165
|
+
describe "with text id" do
|
166
|
+
def create_pet(attrs = {})
|
167
|
+
PetTextId.create! attrs.reverse_merge(id: rand.to_s)
|
91
168
|
end
|
92
|
-
|
93
|
-
|
169
|
+
def build_pet(attrs = {})
|
170
|
+
PetTextId.new attrs.reverse_merge(id: rand.to_s)
|
94
171
|
end
|
95
|
-
|
96
|
-
|
172
|
+
it_behaves_like 'different states of persistence'
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "with uuid id" do
|
176
|
+
def create_pet(attrs = {})
|
177
|
+
PetUuid.create! attrs.reverse_merge(id: SecureRandom.uuid)
|
97
178
|
end
|
98
|
-
|
99
|
-
|
179
|
+
def build_pet(attrs = {})
|
180
|
+
PetUuid.new attrs.reverse_merge(id: SecureRandom.uuid)
|
100
181
|
end
|
182
|
+
it_behaves_like 'different states of persistence'
|
101
183
|
end
|
102
184
|
|
103
185
|
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.0.2
|
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-07-
|
11
|
+
date: 2014-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|