rgeo 0.1.22 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/History.rdoc +31 -0
  2. data/README.rdoc +53 -59
  3. data/Spatial_Programming_With_RGeo.rdoc +120 -67
  4. data/Version +1 -1
  5. data/ext/proj4_c_impl/extconf.rb +1 -1
  6. data/lib/rgeo.rb +80 -87
  7. data/lib/rgeo/cartesian.rb +0 -10
  8. data/lib/rgeo/coord_sys.rb +0 -7
  9. data/lib/rgeo/coord_sys/proj4.rb +2 -2
  10. data/lib/rgeo/error.rb +2 -6
  11. data/lib/rgeo/feature.rb +0 -7
  12. data/lib/rgeo/feature/curve.rb +5 -5
  13. data/lib/rgeo/feature/factory.rb +45 -5
  14. data/lib/rgeo/feature/factory_generator.rb +2 -4
  15. data/lib/rgeo/feature/geometry.rb +97 -27
  16. data/lib/rgeo/feature/geometry_collection.rb +3 -3
  17. data/lib/rgeo/feature/line_string.rb +3 -3
  18. data/lib/rgeo/feature/multi_curve.rb +2 -2
  19. data/lib/rgeo/feature/multi_surface.rb +3 -3
  20. data/lib/rgeo/feature/point.rb +6 -6
  21. data/lib/rgeo/feature/polygon.rb +4 -4
  22. data/lib/rgeo/feature/surface.rb +3 -3
  23. data/lib/rgeo/geographic.rb +0 -11
  24. data/lib/rgeo/geographic/factory.rb +5 -2
  25. data/lib/rgeo/geographic/interface.rb +1 -1
  26. data/lib/rgeo/geos.rb +0 -7
  27. data/lib/rgeo/geos/factory.rb +1 -1
  28. data/lib/rgeo/impl_helper.rb +0 -7
  29. data/lib/rgeo/wkrep.rb +0 -7
  30. data/lib/rgeo/wkrep/wkb_parser.rb +2 -2
  31. data/test/tc_oneoff.rb +0 -1
  32. metadata +7 -155
  33. data/lib/active_record/connection_adapters/mysql2spatial_adapter.rb +0 -124
  34. data/lib/active_record/connection_adapters/mysqlspatial_adapter.rb +0 -136
  35. data/lib/active_record/connection_adapters/postgis_adapter.rb +0 -426
  36. data/lib/active_record/connection_adapters/spatialite_adapter.rb +0 -488
  37. data/lib/rgeo/active_record/arel_modifications.rb +0 -78
  38. data/lib/rgeo/active_record/base_modifications.rb +0 -124
  39. data/lib/rgeo/active_record/common.rb +0 -166
  40. data/lib/rgeo/active_record/mysql_common.rb +0 -150
  41. data/lib/rgeo/all.rb +0 -49
  42. data/lib/rgeo/geo_json.rb +0 -60
  43. data/lib/rgeo/geo_json/coder.rb +0 -401
  44. data/lib/rgeo/geo_json/entities.rb +0 -285
  45. data/lib/rgeo/geo_json/interface.rb +0 -129
  46. data/lib/rgeo/shapefile.rb +0 -60
  47. data/lib/rgeo/shapefile/reader.rb +0 -898
  48. data/test/active_record/common_setup_methods.rb +0 -129
  49. data/test/active_record/readme.txt +0 -43
  50. data/test/active_record/tc_mysqlspatial.rb +0 -170
  51. data/test/active_record/tc_postgis.rb +0 -282
  52. data/test/active_record/tc_spatialite.rb +0 -198
  53. data/test/shapefile/shapelib_testcases/readme.txt +0 -11
  54. data/test/shapefile/shapelib_testcases/test.dbf +0 -0
  55. data/test/shapefile/shapelib_testcases/test.shp +0 -0
  56. data/test/shapefile/shapelib_testcases/test.shx +0 -0
  57. data/test/shapefile/shapelib_testcases/test0.shp +0 -0
  58. data/test/shapefile/shapelib_testcases/test0.shx +0 -0
  59. data/test/shapefile/shapelib_testcases/test1.shp +0 -0
  60. data/test/shapefile/shapelib_testcases/test1.shx +0 -0
  61. data/test/shapefile/shapelib_testcases/test10.shp +0 -0
  62. data/test/shapefile/shapelib_testcases/test10.shx +0 -0
  63. data/test/shapefile/shapelib_testcases/test11.shp +0 -0
  64. data/test/shapefile/shapelib_testcases/test11.shx +0 -0
  65. data/test/shapefile/shapelib_testcases/test12.shp +0 -0
  66. data/test/shapefile/shapelib_testcases/test12.shx +0 -0
  67. data/test/shapefile/shapelib_testcases/test13.shp +0 -0
  68. data/test/shapefile/shapelib_testcases/test13.shx +0 -0
  69. data/test/shapefile/shapelib_testcases/test2.shp +0 -0
  70. data/test/shapefile/shapelib_testcases/test2.shx +0 -0
  71. data/test/shapefile/shapelib_testcases/test3.shp +0 -0
  72. data/test/shapefile/shapelib_testcases/test3.shx +0 -0
  73. data/test/shapefile/shapelib_testcases/test4.shp +0 -0
  74. data/test/shapefile/shapelib_testcases/test4.shx +0 -0
  75. data/test/shapefile/shapelib_testcases/test5.shp +0 -0
  76. data/test/shapefile/shapelib_testcases/test5.shx +0 -0
  77. data/test/shapefile/shapelib_testcases/test6.shp +0 -0
  78. data/test/shapefile/shapelib_testcases/test6.shx +0 -0
  79. data/test/shapefile/shapelib_testcases/test7.shp +0 -0
  80. data/test/shapefile/shapelib_testcases/test7.shx +0 -0
  81. data/test/shapefile/shapelib_testcases/test8.shp +0 -0
  82. data/test/shapefile/shapelib_testcases/test8.shx +0 -0
  83. data/test/shapefile/shapelib_testcases/test9.shp +0 -0
  84. data/test/shapefile/shapelib_testcases/test9.shx +0 -0
  85. data/test/shapefile/tc_shapelib_tests.rb +0 -527
  86. data/test/tc_geojson.rb +0 -279
@@ -1,129 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Common setup methods for ActiveRecord adapter tests
4
- #
5
- # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
8
- # All rights reserved.
9
- #
10
- # Redistribution and use in source and binary forms, with or without
11
- # modification, are permitted provided that the following conditions are met:
12
- #
13
- # * Redistributions of source code must retain the above copyright notice,
14
- # this list of conditions and the following disclaimer.
15
- # * Redistributions in binary form must reproduce the above copyright notice,
16
- # this list of conditions and the following disclaimer in the documentation
17
- # and/or other materials provided with the distribution.
18
- # * Neither the name of the copyright holder, nor the names of any other
19
- # contributors to this software, may be used to endorse or promote products
20
- # derived from this software without specific prior written permission.
21
- #
22
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
- # POSSIBILITY OF SUCH DAMAGE.
33
- # -----------------------------------------------------------------------------
34
- ;
35
-
36
-
37
- require 'rgeo'
38
- require 'yaml'
39
- require 'active_record'
40
- require 'logger'
41
-
42
-
43
- module RGeo
44
- module Tests # :nodoc:
45
- module ActiveRecord # :nodoc:
46
-
47
-
48
- if ::File.exists?(::File.dirname(__FILE__)+'/database.yml')
49
-
50
- TESTS_AVAILABLE = true
51
-
52
- ALL_DATABASES_CONFIG = ::YAML.load_file(::File.dirname(__FILE__)+'/database.yml')
53
-
54
-
55
- module CommonSetupMethods # :nodoc:
56
-
57
- @class_num = 0
58
-
59
-
60
- def self.included(klass_)
61
- database_config_ = ALL_DATABASES_CONFIG[klass_.const_get(:ADAPTER_NAME)]
62
- database_config_.symbolize_keys!
63
- if klass_.respond_to?(:before_open_database)
64
- klass_.before_open_database(:config => database_config_)
65
- end
66
- klass_.const_set(:DATABASE_CONFIG, database_config_)
67
- ar_class_ = CommonSetupMethods.new_class(database_config_)
68
- klass_.const_set(:DEFAULT_AR_CLASS, ar_class_)
69
- if klass_.respond_to?(:initialize_database)
70
- klass_.initialize_database(:ar_class => ar_class_, :connection => ar_class_.connection)
71
- end
72
- end
73
-
74
-
75
- def self.new_class(param_)
76
- base_ = param_.kind_of?(::Class) ? param_ : ::ActiveRecord::Base
77
- config_ = param_.kind_of?(::Hash) ? param_ : nil
78
- klass_ = ::Class.new(base_)
79
- @class_num += 1
80
- self.const_set("Klass#{@class_num}".to_sym, klass_)
81
- klass_.class_eval do
82
- establish_connection(config_) if config_
83
- set_table_name(:spatial_test)
84
- end
85
- klass_
86
- end
87
-
88
-
89
- def setup
90
- @factory = ::RGeo::Cartesian.preferred_factory(:srid => 4326)
91
- @geographic_factory = ::RGeo::Geographic.spherical_factory(:srid => 4326)
92
- cleanup_tables
93
- end
94
-
95
-
96
- def teardown
97
- cleanup_tables
98
- end
99
-
100
-
101
- def cleanup_tables
102
- klass_ = self.class.const_get(:DEFAULT_AR_CLASS)
103
- if klass_.connection.tables.include?('spatial_test')
104
- klass_.connection.drop_table(:spatial_test)
105
- end
106
- end
107
-
108
-
109
- def create_ar_class(opts_={})
110
- @ar_class = CommonSetupMethods.new_class(self.class.const_get(:DEFAULT_AR_CLASS))
111
- end
112
-
113
-
114
- end
115
-
116
-
117
- else
118
-
119
- TESTS_AVAILABLE = false
120
-
121
- puts "WARNING: database.yml not found. Skipping ActiveRecord tests."
122
- puts " See tests/active_record/readme.txt for more info."
123
-
124
- end
125
-
126
-
127
- end
128
- end
129
- end
@@ -1,43 +0,0 @@
1
- The ActiveRecord adapter unit tests require that you connect to actual
2
- databases. In order for these tests to run, you must therefore provide
3
- the database connection parameters, in the form of a "database.yml" file
4
- located in this directory. If this file is not present, the ActiveRecord
5
- adapter tests will be skipped.
6
-
7
- The format of this file is the same as the Rails "config/database.yml"
8
- file, except that the main keys, instead of environment names, should be
9
- adapter names.
10
-
11
- For example:
12
-
13
- ####
14
- mysqlspatial:
15
- adapter: mysqlspatial
16
- encoding: utf8
17
- reconnect: false
18
- database: <mysql_test_database>
19
- username: <mysql_user>
20
- password: <mysql_password>
21
- host: localhost
22
- mysql2spatial:
23
- adapter: mysql2spatial
24
- encoding: utf8
25
- reconnect: false
26
- database: <mysql_test_database>
27
- username: <mysql_user>
28
- password: <mysql_password>
29
- host: localhost
30
- spatialite:
31
- adapter: spatialite
32
- database: /path/to/sqlite3_test_database.db
33
- libspatialite: /path/to/libspatialite.so
34
- postgis:
35
- adapter: postgis
36
- database: <postgres_test_database>
37
- username: <postgres_user>
38
- password: <postgres_password>
39
- host: localhost
40
- ####
41
-
42
- Note that the tests assume they "own" these databases, and they may
43
- modify and/or delete any and all tables at any time.
@@ -1,170 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Tests for the MysqlSpatial ActiveRecord adapter
4
- #
5
- # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
8
- # All rights reserved.
9
- #
10
- # Redistribution and use in source and binary forms, with or without
11
- # modification, are permitted provided that the following conditions are met:
12
- #
13
- # * Redistributions of source code must retain the above copyright notice,
14
- # this list of conditions and the following disclaimer.
15
- # * Redistributions in binary form must reproduce the above copyright notice,
16
- # this list of conditions and the following disclaimer in the documentation
17
- # and/or other materials provided with the distribution.
18
- # * Neither the name of the copyright holder, nor the names of any other
19
- # contributors to this software, may be used to endorse or promote products
20
- # derived from this software without specific prior written permission.
21
- #
22
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
- # POSSIBILITY OF SUCH DAMAGE.
33
- # -----------------------------------------------------------------------------
34
- ;
35
-
36
- require 'test/unit'
37
- require ::File.expand_path('common_setup_methods.rb', ::File.dirname(__FILE__))
38
-
39
-
40
- module RGeo
41
- module Tests # :nodoc:
42
- module ActiveRecord # :nodoc:
43
-
44
- if TESTS_AVAILABLE
45
-
46
-
47
- module CommonMysqlTestMethods # :nodoc:
48
-
49
-
50
- def populate_ar_class(content_)
51
- klass_ = create_ar_class
52
- case content_
53
- when :latlon_point
54
- klass_.connection.create_table(:spatial_test) do |t_|
55
- t_.column 'latlon', :point
56
- end
57
- end
58
- klass_
59
- end
60
-
61
-
62
- def test_create_simple_geometry
63
- klass_ = create_ar_class
64
- klass_.connection.create_table(:spatial_test) do |t_|
65
- t_.column 'latlon', :geometry
66
- end
67
- assert_equal(::RGeo::Feature::Geometry, klass_.columns.last.geometric_type)
68
- assert(klass_.cached_attributes.include?('latlon'))
69
- end
70
-
71
-
72
- def test_create_point_geometry
73
- klass_ = create_ar_class
74
- klass_.connection.create_table(:spatial_test) do |t_|
75
- t_.column 'latlon', :point
76
- end
77
- assert_equal(::RGeo::Feature::Point, klass_.columns.last.geometric_type)
78
- assert(klass_.cached_attributes.include?('latlon'))
79
- end
80
-
81
-
82
- def test_create_geometry_with_index
83
- klass_ = create_ar_class
84
- klass_.connection.create_table(:spatial_test, :options => 'ENGINE=MyISAM') do |t_|
85
- t_.column 'latlon', :geometry, :null => false
86
- end
87
- klass_.connection.change_table(:spatial_test) do |t_|
88
- t_.index([:latlon], :spatial => true)
89
- end
90
- assert(klass_.connection.indexes(:spatial_test).last.spatial)
91
- end
92
-
93
-
94
- def test_set_and_get_point
95
- klass_ = populate_ar_class(:latlon_point)
96
- obj_ = klass_.new
97
- assert_nil(obj_.latlon)
98
- obj_.latlon = @factory.point(1, 2)
99
- assert_equal(@factory.point(1, 2), obj_.latlon)
100
- assert_equal(4326, obj_.latlon.srid)
101
- end
102
-
103
-
104
- def test_set_and_get_point_from_wkt
105
- klass_ = populate_ar_class(:latlon_point)
106
- obj_ = klass_.new
107
- assert_nil(obj_.latlon)
108
- obj_.latlon = 'SRID=1000;POINT(1 2)'
109
- assert_equal(@factory.point(1, 2), obj_.latlon)
110
- assert_equal(1000, obj_.latlon.srid)
111
- end
112
-
113
-
114
- def test_save_and_load_point
115
- klass_ = populate_ar_class(:latlon_point)
116
- obj_ = klass_.new
117
- obj_.latlon = @factory.point(1, 2)
118
- obj_.save!
119
- id_ = obj_.id
120
- obj2_ = klass_.find(id_)
121
- assert_equal(@factory.point(1, 2), obj2_.latlon)
122
- assert_equal(4326, obj2_.latlon.srid)
123
- end
124
-
125
-
126
- def test_save_and_load_point_from_wkt
127
- klass_ = populate_ar_class(:latlon_point)
128
- obj_ = klass_.new
129
- obj_.latlon = 'SRID=1000;POINT(1 2)'
130
- obj_.save!
131
- id_ = obj_.id
132
- obj2_ = klass_.find(id_)
133
- assert_equal(@factory.point(1, 2), obj2_.latlon)
134
- assert_equal(1000, obj2_.latlon.srid)
135
- end
136
-
137
-
138
- end
139
-
140
-
141
- if ALL_DATABASES_CONFIG.include?('mysqlspatial')
142
- class TestMysqlSpatial < ::Test::Unit::TestCase # :nodoc:
143
- ADAPTER_NAME = 'mysqlspatial'
144
- include CommonSetupMethods
145
- include CommonMysqlTestMethods
146
- end
147
- else
148
- puts "WARNING: Couldn't find mysqlspatial in database.yml. Skipping those tests."
149
- puts " See tests/active_record/readme.txt for more info."
150
- end
151
-
152
-
153
- if ALL_DATABASES_CONFIG.include?('mysql2spatial')
154
- class TestMysql2Spatial < ::Test::Unit::TestCase # :nodoc:
155
- ADAPTER_NAME = 'mysql2spatial'
156
- include CommonSetupMethods
157
- include CommonMysqlTestMethods
158
- end
159
- else
160
- puts "WARNING: Couldn't find mysql2spatial in database.yml. Skipping those tests."
161
- puts " See tests/active_record/readme.txt for more info."
162
- end
163
-
164
-
165
- end
166
-
167
- end
168
-
169
- end
170
- end
@@ -1,282 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Tests for the PostGIS ActiveRecord adapter
4
- #
5
- # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
8
- # All rights reserved.
9
- #
10
- # Redistribution and use in source and binary forms, with or without
11
- # modification, are permitted provided that the following conditions are met:
12
- #
13
- # * Redistributions of source code must retain the above copyright notice,
14
- # this list of conditions and the following disclaimer.
15
- # * Redistributions in binary form must reproduce the above copyright notice,
16
- # this list of conditions and the following disclaimer in the documentation
17
- # and/or other materials provided with the distribution.
18
- # * Neither the name of the copyright holder, nor the names of any other
19
- # contributors to this software, may be used to endorse or promote products
20
- # derived from this software without specific prior written permission.
21
- #
22
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
- # POSSIBILITY OF SUCH DAMAGE.
33
- # -----------------------------------------------------------------------------
34
- ;
35
-
36
- require 'fileutils'
37
- require 'test/unit'
38
- require ::File.expand_path('common_setup_methods.rb', ::File.dirname(__FILE__))
39
-
40
-
41
- module RGeo
42
- module Tests # :nodoc:
43
- module ActiveRecord # :nodoc:
44
-
45
- if TESTS_AVAILABLE
46
-
47
-
48
- if ALL_DATABASES_CONFIG.include?('postgis')
49
-
50
- class TestPostGis < ::Test::Unit::TestCase # :nodoc:
51
-
52
-
53
- ADAPTER_NAME = 'postgis'
54
-
55
- include CommonSetupMethods
56
-
57
-
58
- def populate_ar_class(content_)
59
- klass_ = create_ar_class
60
- case content_
61
- when :latlon_point
62
- klass_.connection.create_table(:spatial_test) do |t_|
63
- t_.column 'latlon', :point, :srid => 4326
64
- end
65
- when :latlon_point_geographic
66
- klass_.connection.create_table(:spatial_test) do |t_|
67
- t_.column 'latlon', :point, :srid => 4326, :geographic => true
68
- end
69
- end
70
- klass_
71
- end
72
-
73
-
74
- def test_postgis_available
75
- connection_ = create_ar_class.connection
76
- assert_equal('PostGIS', connection_.adapter_name)
77
- assert_not_nil(connection_.postgis_lib_version)
78
- end
79
-
80
-
81
- def test_create_simple_geometry
82
- klass_ = create_ar_class
83
- klass_.connection.create_table(:spatial_test) do |t_|
84
- t_.column 'latlon', :geometry
85
- end
86
- assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
87
- col_ = klass_.columns.last
88
- assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
89
- assert_equal(false, col_.geographic?)
90
- assert_equal(4326, col_.srid)
91
- assert(klass_.cached_attributes.include?('latlon'))
92
- klass_.connection.drop_table(:spatial_test)
93
- assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
94
- end
95
-
96
-
97
- def test_create_simple_geography
98
- klass_ = create_ar_class
99
- klass_.connection.create_table(:spatial_test) do |t_|
100
- t_.column 'latlon', :geometry, :geographic => true
101
- end
102
- col_ = klass_.columns.last
103
- assert_equal(::RGeo::Feature::Geometry, col_.geometric_type)
104
- assert_equal(true, col_.geographic?)
105
- assert_equal(4326, col_.srid)
106
- assert(klass_.cached_attributes.include?('latlon'))
107
- assert_equal(0, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
108
- end
109
-
110
-
111
- def test_create_point_geometry
112
- klass_ = create_ar_class
113
- klass_.connection.create_table(:spatial_test) do |t_|
114
- t_.column 'latlon', :point
115
- end
116
- assert_equal(::RGeo::Feature::Point, klass_.columns.last.geometric_type)
117
- assert(klass_.cached_attributes.include?('latlon'))
118
- end
119
-
120
-
121
- def test_create_geometry_with_index
122
- klass_ = create_ar_class
123
- klass_.connection.create_table(:spatial_test) do |t_|
124
- t_.column 'latlon', :geometry
125
- end
126
- klass_.connection.change_table(:spatial_test) do |t_|
127
- t_.index([:latlon], :spatial => true)
128
- end
129
- end
130
-
131
-
132
- def test_set_and_get_point
133
- klass_ = populate_ar_class(:latlon_point)
134
- obj_ = klass_.new
135
- assert_nil(obj_.latlon)
136
- obj_.latlon = @factory.point(1, 2)
137
- assert_equal(@factory.point(1, 2), obj_.latlon)
138
- assert_equal(4326, obj_.latlon.srid)
139
- end
140
-
141
-
142
- def test_set_and_get_point_from_wkt
143
- klass_ = populate_ar_class(:latlon_point)
144
- obj_ = klass_.new
145
- assert_nil(obj_.latlon)
146
- obj_.latlon = 'POINT(1 2)'
147
- assert_equal(@factory.point(1, 2), obj_.latlon)
148
- assert_equal(4326, obj_.latlon.srid)
149
- end
150
-
151
-
152
- def test_save_and_load_point
153
- klass_ = populate_ar_class(:latlon_point)
154
- obj_ = klass_.new
155
- obj_.latlon = @factory.point(1, 2)
156
- obj_.save!
157
- id_ = obj_.id
158
- obj2_ = klass_.find(id_)
159
- assert_equal(@factory.point(1, 2), obj2_.latlon)
160
- assert_equal(4326, obj2_.latlon.srid)
161
- assert_equal(true, ::RGeo::Geos.is_geos?(obj2_.latlon))
162
- end
163
-
164
-
165
- def test_save_and_load_geographic_point
166
- klass_ = populate_ar_class(:latlon_point_geographic)
167
- obj_ = klass_.new
168
- obj_.latlon = @factory.point(1, 2)
169
- obj_.save!
170
- id_ = obj_.id
171
- obj2_ = klass_.find(id_)
172
- assert_equal(@geographic_factory.point(1, 2), obj2_.latlon)
173
- assert_equal(4326, obj2_.latlon.srid)
174
- assert_equal(false, ::RGeo::Geos.is_geos?(obj2_.latlon))
175
- end
176
-
177
-
178
- def test_save_and_load_point_from_wkt
179
- klass_ = populate_ar_class(:latlon_point)
180
- obj_ = klass_.new
181
- obj_.latlon = 'POINT(1 2)'
182
- obj_.save!
183
- id_ = obj_.id
184
- obj2_ = klass_.find(id_)
185
- assert_equal(@factory.point(1, 2), obj2_.latlon)
186
- assert_equal(4326, obj2_.latlon.srid)
187
- end
188
-
189
-
190
- def test_add_geometry_column
191
- klass_ = create_ar_class
192
- klass_.connection.create_table(:spatial_test) do |t_|
193
- t_.column('latlon', :geometry)
194
- end
195
- klass_.connection.change_table(:spatial_test) do |t_|
196
- t_.column('geom2', :point, :srid => 4326)
197
- t_.column('name', :string)
198
- end
199
- assert_equal(2, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
200
- cols_ = klass_.columns
201
- assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
202
- assert_equal(4326, cols_[-3].srid)
203
- assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
204
- assert_equal(4326, cols_[-2].srid)
205
- assert_equal(false, cols_[-2].geographic?)
206
- assert_nil(cols_[-1].geometric_type)
207
- end
208
-
209
-
210
- def test_add_geography_column
211
- klass_ = create_ar_class
212
- klass_.connection.create_table(:spatial_test) do |t_|
213
- t_.column('latlon', :geometry)
214
- end
215
- klass_.connection.change_table(:spatial_test) do |t_|
216
- t_.column('geom2', :point, :srid => 4326, :geographic => true)
217
- t_.column('name', :string)
218
- end
219
- assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
220
- cols_ = klass_.columns
221
- assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
222
- assert_equal(4326, cols_[-3].srid)
223
- assert_equal(::RGeo::Feature::Point, cols_[-2].geometric_type)
224
- assert_equal(4326, cols_[-2].srid)
225
- assert_equal(true, cols_[-2].geographic?)
226
- assert_nil(cols_[-1].geometric_type)
227
- end
228
-
229
-
230
- def test_drop_geometry_column
231
- klass_ = create_ar_class
232
- klass_.connection.create_table(:spatial_test) do |t_|
233
- t_.column('latlon', :geometry)
234
- t_.column('geom2', :point, :srid => 4326)
235
- end
236
- klass_.connection.change_table(:spatial_test) do |t_|
237
- t_.remove('geom2')
238
- end
239
- assert_equal(1, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
240
- cols_ = klass_.columns
241
- assert_equal(::RGeo::Feature::Geometry, cols_[-1].geometric_type)
242
- assert_equal('latlon', cols_[-1].name)
243
- assert_equal(4326, cols_[-1].srid)
244
- assert_equal(false, cols_[-1].geographic?)
245
- end
246
-
247
-
248
- def test_drop_geography_column
249
- klass_ = create_ar_class
250
- klass_.connection.create_table(:spatial_test) do |t_|
251
- t_.column('latlon', :geometry)
252
- t_.column('geom2', :point, :srid => 4326, :geographic => true)
253
- t_.column('geom3', :point, :srid => 4326)
254
- end
255
- klass_.connection.change_table(:spatial_test) do |t_|
256
- t_.remove('geom2')
257
- end
258
- assert_equal(2, klass_.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
259
- cols_ = klass_.columns
260
- assert_equal(::RGeo::Feature::Point, cols_[-1].geometric_type)
261
- assert_equal('geom3', cols_[-1].name)
262
- assert_equal(false, cols_[-1].geographic?)
263
- assert_equal(::RGeo::Feature::Geometry, cols_[-2].geometric_type)
264
- assert_equal('latlon', cols_[-2].name)
265
- assert_equal(false, cols_[-2].geographic?)
266
- end
267
-
268
-
269
- end
270
-
271
- else
272
- puts "WARNING: Couldn't find postgis in database.yml. Skipping those tests."
273
- puts " See tests/active_record/readme.txt for more info."
274
- end
275
-
276
-
277
- end
278
-
279
- end
280
-
281
- end
282
- end