the_geom_geojson 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b923b316a16ae77ca598e803b10757e992adba8
4
+ data.tar.gz: e70e6840959521ef9375a61754d4290105cf4faa
5
+ SHA512:
6
+ metadata.gz: 017a2f05ac92ad2d8722896f613f39066c77b95c445ad844c987a85c2705aa136e0510698112aa606bc29480de947357f2eb4a718c94c86a922fafefe29d1485
7
+ data.tar.gz: 247a8189a55c71b300e2b8f568c026302dda564da710e9bf2d6d839495bd51231a91a4ebf6f5058f5c2934415177350ab69bde16579e91aa3794e60566eed6f1
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 1.9.3
5
+ addons:
6
+ postgresql: "9.3"
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --no-private
2
+ --readme README.md
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ 0.0.1 / 2014-07-17
2
+
3
+ initial release!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in the_geom_geojson.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Seamus Abshere
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # TheGeomGeoJSON
2
+
3
+ [![Build Status](https://travis-ci.org/seamusabshere/the_geom_geojson.svg?branch=master)](https://travis-ci.org/seamusabshere/the_geom_geojson)
4
+
5
+ For PostGIS/PostgreSQL and ActiveRecord, provides `the_geom_geojson` getter and setter that update `the_geom geometry(Geometry,4326)` and `the_geom_webmercator geometry(Geometry,3857)` columns.
6
+
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
+
9
+ ## Requirements
10
+
11
+ * [PostgreSQL](postgresql.org) >=9
12
+ * [PostGIS](http://postgis.net/) 2.0.0 with [support for JSON-C >= 0.9 compiled in](http://www.postgis.org/docs/ST_GeomFromGeoJSON.html)
13
+ * [ActiveRecord](http://guides.rubyonrails.org/active_record_querying.html) >=4
14
+ * if it exists, column `the_geom` must be [WGS 84 SRID 4326](http://spatialreference.org/ref/epsg/wgs-84/)
15
+ * if it exists, column `the_geom_webmercator` must be [spherical mercator SRID 3857](http://spatialreference.org/ref/sr-org/epsg3857/) (which is basically identical and should be used in preference to [Google webmercator unofficial SRID 900913](http://trac.osgeo.org/openlayers/wiki/SphericalMercator)).
16
+
17
+ ## Why `the_geom` and `the_geom_webmercator`?
18
+
19
+ Per the commonly used [CartoDB column naming convention](http://docs.cartodb.com/tutorials/projections.html), you have a table like:
20
+
21
+ ```sql
22
+ CREATE TABLE pets (
23
+ id serial primary key,
24
+ the_geom geometry(Geometry,4326),
25
+ the_geom_webmercator geometry(Geometry,3857)
26
+ )
27
+ ```
28
+
29
+ ## Usage with ActiveRecord
30
+
31
+ You simply include it in your models:
32
+
33
+ ```ruby
34
+ class Pet < ActiveRecord::Base
35
+ include TheGeomGeoJSON::ActiveRecord
36
+ end
37
+ ```
38
+
39
+ Then:
40
+
41
+ ```
42
+ [1] > jerry = Pet.create!
43
+ SQL (1.0ms) INSERT INTO "pets" DEFAULT VALUES RETURNING "id"
44
+ => #<Pet id: 1, the_geom: nil, the_geom_webmercator: nil>
45
+
46
+ [2] > jerry.the_geom_geojson = '{"type":"Point","coordinates":[-72.4861,44.1853]}'
47
+ => "{\"type\":\"Point\",\"coordinates\":[-72.4861,44.1853]}"
48
+
49
+ [3] > jerry.save!
50
+ SQL (1.5ms) UPDATE "pets" SET the_geom = ST_SetSRID(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-72.4861,44.1853]}'), 4326), the_geom_webmercator = ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-72.4861,44.1853]}'), 4326), 3857) WHERE id = 1
51
+ Pet Load (0.3ms) SELECT "pets".* FROM "pets" WHERE "pets"."id" = $1 LIMIT 1 [["id", 1]]
52
+ => true
53
+
54
+ [4] > jerry.the_geom
55
+ => "0101000020E61000007AA52C431C1F52C072F90FE9B7174640"
56
+
57
+ [5] > jerry.the_geom_webmercator
58
+ => "0101000020110F0000303776EFFEC75EC11E1648AD64F55441"
59
+ ```
60
+
61
+ If you see warnings like:
62
+
63
+ ```
64
+ unknown OID 136825: failed to recognize type of 'the_geom'. It will be treated as String.
65
+ ```
66
+
67
+ ... then [define the OID](http://gray.fm/2013/09/17/unknown-oid-with-rails-and-postgresql/) by creating `config/initializers/active_record_postgis`:
68
+
69
+ ```sql
70
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.tap do |klass|
71
+ klass::OID.register_type('geometry', klass::OID::Identity.new)
72
+ end
73
+ ```
74
+
75
+ ## Corporate support
76
+
77
+ <p><a href="http://faraday.io" alt="Faraday"><img src="https://s3.amazonaws.com/creative.faraday.io/logo.png" alt="Faraday logo"/></a></p>
78
+
79
+ ## Known issues
80
+
81
+ 1. It's hard to install PostGIS with JSON-C support on Mac OS X
82
+ 2. The `the_geom_geojson` getter is rather inefficient - it's assumed you'll mostly use the setter
83
+
84
+ ## Contributing
85
+
86
+ 1. Fork it ( https://github.com/seamusabshere/the_geom_geojson/fork )
87
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
88
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
89
+ 4. Push to the branch (`git push origin my-new-feature`)
90
+ 5. Create a new Pull Request
91
+
92
+ ## Copyright
93
+
94
+ Copyright 2014 Faraday
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ require 'yard'
9
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,5 @@
1
+ require_relative 'the_geom_geojson/version'
2
+
3
+ module TheGeomGeoJSON
4
+ Dirty = Class.new(RuntimeError)
5
+ end
@@ -0,0 +1,73 @@
1
+ module TheGeomGeoJSON
2
+ module ActiveRecord
3
+ class << self
4
+ def included(model)
5
+ model.class_eval do
6
+ after_save do
7
+ if @the_geom_geojson_dirty
8
+ raise "can't update the_geom without an id" if id.nil?
9
+ model.connection_pool.with_connection do |c|
10
+ c.execute TheGeomGeoJSON::ActiveRecord.sql(model, id, @the_geom_geojson_change)
11
+ end
12
+ @the_geom_geojson_dirty = false
13
+ reload
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ # @private
20
+ def sql(model, id, the_geom_geojson)
21
+ sql = (@sql[model.name] ||= begin
22
+ cols = model.column_names
23
+ has_the_geom, has_the_geom_webmercator = cols.include?('the_geom'), cols.include?('the_geom_webmercator')
24
+ raise "Can't set the_geom_geojson on #{model.name} because it lacks both the_geom and the_geom_webmercator columns" unless has_the_geom or has_the_geom_webmercator
25
+ memo = []
26
+ memo << "UPDATE #{model.quoted_table_name} SET "
27
+ memo << 'the_geom = ST_SetSRID(ST_GeomFromGeoJSON(?), 4326)' if has_the_geom
28
+ memo << ',' if has_the_geom && has_the_geom_webmercator
29
+ memo << 'the_geom_webmercator = ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON(?), 4326), 3857)' if has_the_geom_webmercator
30
+ memo << ' WHERE id = ?'
31
+ memo.join.freeze
32
+ end)
33
+ model.send :sanitize_sql_array, [sql, the_geom_geojson, the_geom_geojson, id]
34
+ end
35
+ end
36
+
37
+ # memoizes update sql with bind placeholders
38
+ @sql = {}
39
+
40
+ def the_geom_geojson=(v)
41
+ @the_geom_geojson_dirty = true
42
+ @the_geom_geojson_change = v
43
+ end
44
+
45
+ # warning inefficient!
46
+ def the_geom_geojson
47
+ if @the_geom_geojson_dirty
48
+ @the_geom_geojson_change
49
+ elsif id
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 id = #{c.quote(id)} LIMIT 1"
52
+ end
53
+ end
54
+ end
55
+
56
+ def the_geom
57
+ if @the_geom_geojson_dirty
58
+ raise TheGeomGeoJSON::Dirty, "the_geom can't be accessed on #{self.class.name} id #{id.inspect} until it has been saved"
59
+ else
60
+ read_attribute :the_geom
61
+ end
62
+ end
63
+
64
+ def the_geom_webmercator
65
+ if @the_geom_geojson_dirty
66
+ raise TheGeomGeoJSON::Dirty, "the_geom_webmercator can't be accessed on #{self.class.name} id #{id.inspect} until it has been saved"
67
+ else
68
+ read_attribute :the_geom_webmercator
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,16 @@
1
+ module TheGeomGeoJSON
2
+ EXAMPLES = {
3
+ barre_montp_metro_polygon: '{"type":"Polygon","coordinates":[[[-72.2289400021792,44.4269414217094],[-72.3678968361699,44.2041095212377],[-72.4425771306298,44.1287229154304],[-72.5888838521079,44.1603344756557],[-72.683137316234,44.013279134225],[-72.9163355643347,44.0719380666887],[-72.9109606402212,44.2818163689305],[-72.8045593317476,44.4517204276558],[-72.6539563860782,44.3982706050046],[-72.5963646467109,44.4793368998783],[-72.4901804489683,44.4257596612796],[-72.4338671543455,44.5061428140398],[-72.2289400021792,44.4269414217094]]]}',
4
+ barre_point: '{"type":"Point","coordinates":[-72.4861,44.1853]}',
5
+ burlington: '{"type":"Polygon","coordinates":[[[-73.2544326782227,44.4952808693111],[-73.2623291015625,44.4685812127015],[-73.1936645507812,44.4494675360069],[-73.1428527832031,44.4636808664498],[-73.143196105957,44.4869538473269],[-73.2544326782227,44.4952808693111]]]}',
6
+ burlington_metro: '{"type":"Polygon","coordinates":[[[-73.2230186462402,44.4918522395362],[-73.2298851013184,44.4622106823564],[-73.2110023498535,44.4399083513046],[-73.1461143493652,44.4478744471836],[-73.1716918945312,44.4902603071915],[-73.2230186462402,44.4918522395362]]]}',
7
+ burlington_point: '{"type":"Point","coordinates":[-73.1936,44.4775]}',
8
+ downtown_burlington: '{"type":"Polygon","coordinates":[[[-73.2180404663086,44.4876886323838],[-73.2206153869629,44.4734811475783],[-73.2110023498535,44.4668661383073],[-73.2032775878906,44.4759309607507],[-73.2032775878906,44.4827898905016],[-73.2180404663086,44.4876886323838]]]}',
9
+ downtown_burlington_point: '{"type":"Point","coordinates":[-73.2101440429688,44.4762984238562]}',
10
+ montreal: '{"type":"Polygon","coordinates":[[[-74.0643310546875,45.6946698435472],[-74.06982421875,45.3405631388986],[-73.67431640625,45.2284805958436],[-73.23486328125,45.3251166433327],[-73.2568359375,45.6140374113509],[-73.641357421875,45.775186183521],[-74.0643310546875,45.6946698435472]]]}',
11
+ northampton_ma_point: '{"type":"Point","coordinates":[-72.6381,42.318]}',
12
+ south_burlington: '{"type":"Polygon","coordinates":[[[-73.1759834289551,44.4743385938871],[-73.1826782226562,44.4607404612394],[-73.1629371643066,44.4563295757472],[-73.1550407409668,44.4667436310651],[-73.1698036193848,44.4738486261104],[-73.1759834289551,44.4743385938871]]]}',
13
+ south_burlington_point: '{"type":"Point","coordinates":[-73.1708335876465,44.4677236818036]}',
14
+ vermont: '{"type":"MultiPolygon","coordinates":[[[[-71.4652810350704,45.0136740921081],[-71.5386411060663,44.9876482991498],[-71.4949119839671,44.904935677564],[-71.5559082311558,44.8492522250988],[-71.5932506534844,44.7821926292262],[-71.6267620560918,44.7461089549863],[-71.5999650349199,44.7054878828813],[-71.5854265437744,44.6569382972147],[-71.5529291054811,44.6296118479332],[-71.5477715366207,44.5715907748108],[-71.590912834446,44.5654790326065],[-71.5721467665558,44.5383875158682],[-71.5773924416804,44.504795628544],[-71.6556174756354,44.4575842635223],[-71.6653785347815,44.437497307203],[-71.7426030604065,44.401593649355],[-71.7900571774886,44.4003277721065],[-71.8124840748932,44.3568172825136],[-71.8725731294504,44.3366032393682],[-71.9159562732437,44.3470295764368],[-72.0328714035569,44.3205183335643],[-72.068267173563,44.2725758737951],[-72.0476497892934,44.2394907913363],[-72.0656232451116,44.1889985746845],[-72.0390245886718,44.1555266718593],[-72.0531506510485,44.1186649606436],[-72.0419965506196,44.0793215610918],[-72.083470475863,44.021391036795],[-72.1168821381898,43.9938693880775],[-72.0989880476446,43.9573015829302],[-72.1180268061557,43.9232395021891],[-72.1850390675781,43.8635292290268],[-72.1833237715031,43.8096345502268],[-72.2318451262613,43.7478797412623],[-72.2710062037477,43.7340378639244],[-72.3000814868528,43.7057585766342],[-72.3286014830337,43.6012223664117],[-72.374963015393,43.5787671391696],[-72.398567536734,43.5113585632972],[-72.3802145312888,43.4925891723995],[-72.4145989561172,43.3642557678067],[-72.3899518331573,43.3560406089049],[-72.4103476303482,43.3304832941341],[-72.3954226049632,43.3132689557969],[-72.4370005653915,43.2560485116378],[-72.4386548616246,43.2014661570238],[-72.457067782571,43.1465235064938],[-72.4328401191079,43.1194093843771],[-72.4335666904147,43.0855700936913],[-72.4670369657832,43.0541563651196],[-72.4437081638785,43.0098992105563],[-72.4757890076724,42.9714813427244],[-72.5322718195464,42.9547865595992],[-72.5250663219872,42.9145238867145],[-72.5572279085895,42.8536740697468],[-72.5417204846968,42.8074556433103],[-72.4789240060734,42.762844222053],[-72.4584471135625,42.7269600083283],[-72.8463581795254,42.7373692412871],[-73.2761920979235,42.745980717451],[-73.2908881592095,42.8019554141581],[-73.2786777953224,42.8334723973611],[-73.270102777218,43.0298023092314],[-73.256564420585,43.2577019995215],[-73.246878246029,43.5257594146829],[-73.2495213860356,43.554195454945],[-73.2971234303866,43.5876006914255],[-73.3018282638826,43.6243579630326],[-73.3661314692282,43.6233617442716],[-73.3993105885789,43.5681870726839],[-73.4313322540602,43.5879173137677],[-73.4285070276083,43.6365346263424],[-73.3704507107918,43.7250565919606],[-73.3509986681513,43.7724341746593],[-73.3927963012338,43.8227736353836],[-73.3741504033419,43.8762343153286],[-73.4088622107153,43.934506898594],[-73.4103904443496,44.0265056738413],[-73.4379015767698,44.0451251846575],[-73.3906264489292,44.191066922614],[-73.319046344295,44.2502847730753],[-73.3117644008574,44.2791900694105],[-73.3354266881899,44.3599373816722],[-73.2959980390626,44.4287345257907],[-73.2996335004757,44.4774481456921],[-73.3197769055187,44.5235698292573],[-73.3745706674855,44.5756808411071],[-73.3901885448712,44.6189330442253],[-73.3703297781352,44.6627714750981],[-73.365618517551,44.7418072879085],[-73.3351731870471,44.804256760167],[-73.3797359695302,44.8386464823755],[-73.3607532750112,44.8966194647899],[-73.3396999897322,44.9163803468889],[-73.3429328823848,45.0107159350691],[-73.0653616036896,45.0159616529509],[-72.6346759983699,45.014687873586],[-72.5553981209717,45.0080184883601],[-72.3142543161308,45.0038470393866],[-71.9139806338036,45.0076285637164],[-71.4652810350704,45.0136740921081]]]]}',
15
+ }
16
+ end
@@ -0,0 +1,3 @@
1
+ module TheGeomGeoJSON
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'the_geom_geojson'
3
+ require 'the_geom_geojson/examples'
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ dbname = 'the_geom_geojson_activerecord_test'
4
+ unless ENV['FAST'] == 'true'
5
+ system 'dropdb', '--if-exists', dbname
6
+ system 'createdb', dbname
7
+ system 'psql', dbname, '--command', 'CREATE EXTENSION postgis'
8
+ system 'psql', dbname, '--command', 'CREATE TABLE pets (id serial primary key, the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
9
+ end
10
+
11
+ require 'active_record'
12
+
13
+ ActiveRecord::Base.establish_connection "postgresql://127.0.0.1/#{dbname}"
14
+
15
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.tap do |klass|
16
+ klass::OID.register_type('geometry', klass::OID::Identity.new)
17
+ end
18
+
19
+ require 'the_geom_geojson/active_record'
20
+
21
+ class Pet < ActiveRecord::Base
22
+ include TheGeomGeoJSON::ActiveRecord
23
+ end
24
+
25
+ if ENV['PRY'] == 'true'
26
+ require 'pry'
27
+ require 'logger'
28
+ ActiveRecord::Base.logger = Logger.new($stdout).tap { |logger| logger.level = Logger::DEBUG }
29
+ binding.pry
30
+ end
31
+
32
+ describe TheGeomGeoJSON do
33
+ describe 'ActiveRecord' do
34
+ # # select st_setsrid(st_geomfromgeojson('{"type":"Point","coordinates":[-73.1936,44.4775]}'),4326);
35
+ # st_setsrid
36
+ # ----------------------------------------------------
37
+ # 0101000020E61000005C2041F1634C52C085EB51B81E3D4640
38
+ # (1 row)
39
+ let(:the_geom_expected) { '0101000020E61000005C2041F1634C52C085EB51B81E3D4640' }
40
+
41
+ # # select st_transform(st_setsrid(st_geomfromgeojson('{"type":"Point","coordinates":[-73.1936,44.4775]}'),4326), 3857);
42
+ # st_transform
43
+ # ----------------------------------------------------
44
+ # 0101000020110F000011410192E8145FC137D58F0ECD215541
45
+ # (1 row)
46
+ let(:the_geom_webmercator_expected) { '0101000020110F000011410192E8145FC137D58F0ECD215541' }
47
+
48
+ before do
49
+ Pet.delete_all
50
+ end
51
+
52
+ shared_examples 'the_geom_geojson=(geojson)' do
53
+ it "sets the_geom" do
54
+ expect(@pet.the_geom).to eq(the_geom_expected)
55
+ end
56
+ it "sets the_geom_webmercator" do
57
+ expect(@pet.the_geom_webmercator).to eq(the_geom_webmercator_expected)
58
+ end
59
+ it "lets you access the_geom_geojson" do
60
+ expect(@pet.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington_point])
61
+ end
62
+ end
63
+
64
+ describe "creating" do
65
+ before do
66
+ @pet = Pet.create! the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
67
+ end
68
+ it_behaves_like 'the_geom_geojson=(geojson)'
69
+ end
70
+
71
+ describe "building and saving" do
72
+ before do
73
+ @pet = Pet.new the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
74
+ @pet.save!
75
+ end
76
+ it_behaves_like 'the_geom_geojson=(geojson)'
77
+ end
78
+
79
+ describe "modifying" do
80
+ before do
81
+ @pet = Pet.create!
82
+ @pet.the_geom_geojson = TheGeomGeoJSON::EXAMPLES[:burlington_point]
83
+ @pet.save!
84
+ end
85
+ it_behaves_like 'the_geom_geojson=(geojson)'
86
+ end
87
+
88
+ describe "building (without saving)" do
89
+ before do
90
+ @pet = Pet.new the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
91
+ end
92
+ it "raises exception if you try to access the_geom" do
93
+ expect{@pet.the_geom}.to raise_error(TheGeomGeoJSON::Dirty)
94
+ end
95
+ it "raises exception if you try to access the_geom_webmercator" do
96
+ expect{@pet.the_geom_webmercator}.to raise_error(TheGeomGeoJSON::Dirty)
97
+ end
98
+ it "lets you access the_geom_geojson" do
99
+ expect(@pet.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington_point])
100
+ end
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheGeomGeoJSON do
4
+ it 'has a version number' do
5
+ expect(TheGeomGeoJSON::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'the_geom_geojson/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "the_geom_geojson"
8
+ spec.version = TheGeomGeoJSON::VERSION
9
+ spec.authors = ["Seamus Abshere"]
10
+ spec.email = ["seamus@abshere.net"]
11
+ spec.summary = %q{For PostGIS/PostgreSQL and ActiveRecord, provides "the_geom_geojson" getter and setter that update "the_geom" and "the_geom_webmercator" columns.}
12
+ spec.description = %q{Web mapping libraries like Leaflet often don't support PostGIS's native Well-Known Binary (WKB) and Well-Known Text (WKT) representation, but they do support GeoJSON, so this library helps translate between the two.}
13
+ spec.homepage = "https://github.com/seamusabshere/the_geom_geojson"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'activerecord'
22
+ spec.add_runtime_dependency 'pg'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "yard"
28
+ spec.add_development_dependency "pry"
29
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_geom_geojson
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Seamus Abshere
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Web mapping libraries like Leaflet often don't support PostGIS's native
112
+ Well-Known Binary (WKB) and Well-Known Text (WKT) representation, but they do support
113
+ GeoJSON, so this library helps translate between the two.
114
+ email:
115
+ - seamus@abshere.net
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
+ - ".yardopts"
124
+ - CHANGELOG
125
+ - Gemfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - lib/the_geom_geojson.rb
130
+ - lib/the_geom_geojson/active_record.rb
131
+ - lib/the_geom_geojson/examples.rb
132
+ - lib/the_geom_geojson/version.rb
133
+ - spec/spec_helper.rb
134
+ - spec/the_geom_geojson/active_record_spec.rb
135
+ - spec/the_geom_geojson_spec.rb
136
+ - the_geom_geojson.gemspec
137
+ homepage: https://github.com/seamusabshere/the_geom_geojson
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.2.2
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: For PostGIS/PostgreSQL and ActiveRecord, provides "the_geom_geojson" getter
161
+ and setter that update "the_geom" and "the_geom_webmercator" columns.
162
+ test_files:
163
+ - spec/spec_helper.rb
164
+ - spec/the_geom_geojson/active_record_spec.rb
165
+ - spec/the_geom_geojson_spec.rb
166
+ has_rdoc: