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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dc66a9e2f982e061c64880c64a0dcac61c3fc6e
4
- data.tar.gz: 58a42e2156d1a7e56305fb917c718c86d471f360
3
+ metadata.gz: fff860aa315c7be49742c15cb2721b987c60a767
4
+ data.tar.gz: 78f1b9205edcbaa42bc10762fe9fbcdce91ee66d
5
5
  SHA512:
6
- metadata.gz: 029b1cca09c0a13b708bf2ec8a8148a87e2c6727e70eec4459394045d89c5d50c8344cc86fb45a31bd3deeac7de8159159a54496cc0d5fce9dffafb25fc65b43
7
- data.tar.gz: 7dd1bfa7f2d6e5ca96f1588647282e9b387d3567aba7a4d78a1b761bd8b8c12f2012fff61813d4a0278d18961a76ca032919274b7b995829367a5f885b58867e
6
+ metadata.gz: fc6fd10e4092e17d8060410eef982a4ccd09ab869fc4e951a234d28a4e23c77a43ea70d62c523c98d1f04f020747ac10c340c6e8d91e48a1ab6ef9020bca30f7
7
+ data.tar.gz: 20a5680eaee7bbfaaa2ae14f59c95664942a6c1e90b8c50b1e4a2869cb6dce1a6e111dabac4519395f01e66bb1a9bebfbc6067f532ed7319b6c322b0cec2cf2b
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1.2
4
- - 1.9.3
5
4
  addons:
6
5
  postgresql: "9.3"
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.1.3 / 2015-02-16
2
+
3
+ * Enhancements
4
+
5
+ * add simplify: option to #the_geom_geojson getter
6
+
1
7
  0.1.2 / 2014-11-07
2
8
 
3
9
  * Enhancements
@@ -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
- 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"
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
@@ -1,3 +1,3 @@
1
1
  module TheGeomGeoJSON
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'pry'
2
+
1
3
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
4
  require 'the_geom_geojson'
3
5
  require 'the_geom_geojson/examples'
@@ -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
- # # SELECT ST_SetSRID(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-73.193,44.477]}'), 4326);
65
- # st_setsrid
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[:burlington_point])
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[:burlington_point])
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[:burlington_point])
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[:burlington_point]
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[:burlington_point]
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[:burlington_point]
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[:burlington_point]
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[:burlington_point])
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.2
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: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord