geos-extensions 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +17 -0
  4. data/Guardfile +17 -0
  5. data/MIT-LICENSE +1 -1
  6. data/README.rdoc +19 -91
  7. data/Rakefile +1 -12
  8. data/geos-extensions.gemspec +1 -9
  9. data/lib/geos-extensions.rb +1 -9
  10. data/lib/geos/coordinate_sequence.rb +92 -0
  11. data/lib/geos/extensions/version.rb +1 -1
  12. data/lib/geos/geometry.rb +252 -0
  13. data/lib/geos/geometry_collection.rb +60 -0
  14. data/lib/geos/geos_helper.rb +86 -72
  15. data/lib/geos/google_maps.rb +1 -0
  16. data/lib/geos/google_maps/api_2.rb +9 -23
  17. data/lib/geos/google_maps/api_3.rb +10 -24
  18. data/lib/geos/google_maps/api_common.rb +41 -0
  19. data/lib/geos/line_string.rb +15 -0
  20. data/lib/geos/multi_line_string.rb +15 -0
  21. data/lib/geos/multi_point.rb +15 -0
  22. data/lib/geos/multi_polygon.rb +27 -0
  23. data/lib/geos/point.rb +120 -0
  24. data/lib/geos/polygon.rb +158 -0
  25. data/lib/geos/yaml.rb +30 -0
  26. data/lib/geos/yaml/psych.rb +18 -0
  27. data/lib/geos/yaml/syck.rb +41 -0
  28. data/lib/geos_extensions.rb +110 -711
  29. data/test/google_maps_api_2_tests.rb +54 -32
  30. data/test/google_maps_api_3_tests.rb +58 -36
  31. data/test/google_maps_polyline_encoder_tests.rb +1 -1
  32. data/test/helper_tests.rb +28 -0
  33. data/test/misc_tests.rb +130 -10
  34. data/test/reader_tests.rb +38 -1
  35. data/test/test_helper.rb +54 -146
  36. data/test/writer_tests.rb +329 -10
  37. data/test/yaml_tests.rb +203 -0
  38. metadata +26 -102
  39. data/app/models/geos/geometry_column.rb +0 -39
  40. data/app/models/geos/spatial_ref_sys.rb +0 -12
  41. data/lib/geos/active_record_extensions.rb +0 -12
  42. data/lib/geos/active_record_extensions/connection_adapters/postgresql_adapter.rb +0 -151
  43. data/lib/geos/active_record_extensions/spatial_columns.rb +0 -367
  44. data/lib/geos/active_record_extensions/spatial_scopes.rb +0 -493
  45. data/lib/geos/rails/engine.rb +0 -6
  46. data/lib/tasks/test.rake +0 -42
  47. data/test/adapter_tests.rb +0 -38
  48. data/test/database.yml +0 -17
  49. data/test/fixtures/foo3ds.yml +0 -16
  50. data/test/fixtures/foo_geographies.yml +0 -16
  51. data/test/fixtures/foos.yml +0 -16
  52. data/test/geography_columns_tests.rb +0 -176
  53. data/test/geometry_columns_tests.rb +0 -178
  54. data/test/spatial_scopes_geographies_tests.rb +0 -107
  55. data/test/spatial_scopes_tests.rb +0 -337
@@ -1,6 +0,0 @@
1
-
2
- module Geos
3
- class RailsEngine < Rails::Engine
4
- end
5
- end
6
-
@@ -1,42 +0,0 @@
1
-
2
- namespace :test do
3
- desc "Dumps data from the geometry_columns and spatial_ref_sys tables."
4
- task :postgis_dump do
5
- abcs = ActiveRecord::Base.configurations
6
- ENV['PGHOST'] = abcs[Rails.env]["host"] if abcs[Rails.env]["host"]
7
- ENV['PGPORT'] = abcs[Rails.env]["port"].to_s if abcs[Rails.env]["port"]
8
- ENV['PGPASSWORD'] = abcs[Rails.env]["password"].to_s if abcs[Rails.env]["password"]
9
- search_path = abcs[Rails.env]["schema_search_path"]
10
- unless search_path.blank?
11
- search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ")
12
- end
13
-
14
- tables = %w{ geometry_columns spatial_ref_sys }.select do |table|
15
- ActiveRecord::Base.connection.table_exists?(table)
16
- end
17
-
18
- unless tables.empty?
19
- `pg_dump -i -U "#{abcs[Rails.env]["username"]}" --data-only -t #{tables.join(' -t ')} -x -O -f db/#{Rails.env}_postgis_tables.sql #{search_path} #{abcs[Rails.env]["database"]}`
20
- else
21
- File.open("db/#{Rails.env}_postgis_tables.sql", 'w') do |fp|
22
- fp.puts "-- empty, do geometry_columns and spatial_ref_sys tables exist?"
23
- end
24
- end
25
- end
26
-
27
- desc "Loads the geometry_columns and spatial_ref_sys tables."
28
- task :postgis_load do
29
- abcs = ActiveRecord::Base.configurations
30
- ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
31
- ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
32
- ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
33
-
34
- `psql -U "#{abcs["test"]["username"]}" -f #{Rails.root}/db/#{Rails.env}_postgis_tables.sql #{abcs["test"]["database"]}`
35
- end
36
-
37
- desc "Dumps and loads the geometry_columns and spatial_ref_sys_tables."
38
- task :postgis_clone => [ :postgis_dump, :postgis_load ]
39
- end
40
-
41
- Rake::Task['test:prepare'].enhance(['test:postgis_clone'])
42
-
@@ -1,38 +0,0 @@
1
-
2
- $: << File.dirname(__FILE__)
3
- require 'test_helper'
4
-
5
- if ENV['TEST_ACTIVERECORD']
6
- class AdapterTests < ActiveRecord::TestCase
7
- include TestHelper
8
- include ActiveRecord::TestFixtures
9
-
10
- def test_simplified_type
11
- geometry_columns = Foo.columns.select do |c|
12
- c.type == :geometry
13
- end
14
-
15
- other_columns = Foo.columns.select do |c|
16
- c.type != :geometry
17
- end
18
-
19
- assert_equal(2, geometry_columns.length)
20
- assert_equal(2, other_columns.length)
21
- end
22
-
23
- if Geos::ActiveRecord.geography_columns?
24
- def test_simplified_type_geography
25
- geography_columns = FooGeography.columns.select do |c|
26
- c.type == :geography
27
- end
28
-
29
- other_columns = FooGeography.columns.select do |c|
30
- c.type != :geography
31
- end
32
-
33
- assert_equal(2, geography_columns.length)
34
- assert_equal(2, other_columns.length)
35
- end
36
- end
37
- end
38
- end
@@ -1,17 +0,0 @@
1
- ---
2
- # To modify the test database parameters, create a new file called
3
- # local_database.yml and go nuts with settings. The "jdbc" settings
4
- # are merged into the "arunit" settings as JDBC works over a TCP
5
- # socket and those sorts of connections generally require some user
6
- # credentials.
7
-
8
- arunit:
9
- adapter: "postgresql"
10
- database: "geos_extensions_unit_tests"
11
- min_messages: "warning"
12
- schema_search_path: "public"
13
-
14
- jdbc:
15
- host: "localhost"
16
- adapter: "jdbcpostgresql"
17
-
@@ -1,16 +0,0 @@
1
- ---
2
- one:
3
- id: 1
4
- name: "one"
5
- the_geom: 'POINT(0 0 0)'
6
- the_other_geom: 'SRID=4326; POINT(10 10 10)'
7
- two:
8
- id: 2
9
- name: "two"
10
- the_geom: 'POINT(10 10 10)'
11
- the_other_geom: 'SRID=4326; POINT(20 20 20)'
12
- three:
13
- id: 3
14
- name: "three"
15
- the_geom: 'POLYGON((-5 -5 -5, -5 5 5, 5 5 5, 5 -5 -5, -5 -5 -5))'
16
- the_other_geom: 'SRID=4326; POLYGON((5 5 5, 5 10 10, 10 10 10, 10 5 5, 5 5 5))'
@@ -1,16 +0,0 @@
1
- ---
2
- one:
3
- id: 1
4
- name: "one"
5
- the_geom: 'POINT(0 0)'
6
- the_other_geom: 'SRID=4326; POINT(10 10)'
7
- two:
8
- id: 2
9
- name: "two"
10
- the_geom: 'POINT(10 10)'
11
- the_other_geom: 'SRID=4326; POINT(20 20)'
12
- three:
13
- id: 3
14
- name: "three"
15
- the_geom: 'POLYGON((-5 -5, -5 5, 5 5, 5 -5, -5 -5))'
16
- the_other_geom: 'SRID=4326; POLYGON((5 5, 5 10, 10 10, 10 5, 5 5))'
@@ -1,16 +0,0 @@
1
- ---
2
- one:
3
- id: 1
4
- name: "one"
5
- the_geom: 'POINT(0 0)'
6
- the_other_geom: 'SRID=4326; POINT(10 10)'
7
- two:
8
- id: 2
9
- name: "two"
10
- the_geom: 'POINT(10 10)'
11
- the_other_geom: 'SRID=4326; POINT(20 20)'
12
- three:
13
- id: 3
14
- name: "three"
15
- the_geom: 'POLYGON((-5 -5, -5 5, 5 5, 5 -5, -5 -5))'
16
- the_other_geom: 'SRID=4326; POLYGON((5 5, 5 10, 10 10, 10 5, 5 5))'
@@ -1,176 +0,0 @@
1
-
2
- $: << File.dirname(__FILE__)
3
- require 'test_helper'
4
-
5
- if ENV['TEST_ACTIVERECORD']
6
- class GeographyColumnsTests < ActiveRecord::TestCase
7
- include TestHelper
8
- include ActiveRecord::TestFixtures
9
-
10
- self.fixture_path = File.join(File.dirname(__FILE__), 'fixtures')
11
- fixtures :foo_geographies
12
-
13
- def test_geography_columns_detected
14
- assert_equal(2, FooGeography.geography_columns.length)
15
-
16
- FooGeography.geography_columns.each do |column|
17
- assert_kind_of(ActiveRecord::ConnectionAdapters::PostgreSQLSpatialColumn, column)
18
- end
19
- end
20
-
21
- def test_srid_for
22
- assert_equal(0, FooGeography.srid_for(:the_geom))
23
- assert_equal(4326, FooGeography.srid_for(:the_other_geom))
24
- end
25
-
26
- def test_coord_dimension_for
27
- assert_equal(2, FooGeography.coord_dimension_for(:the_geom))
28
- assert_equal(2, FooGeography.coord_dimension_for(:the_other_geom))
29
- end
30
-
31
- def test_geography_column_by_name
32
- assert_kind_of(ActiveRecord::ConnectionAdapters::PostgreSQLSpatialColumn, FooGeography.geography_column_by_name(:the_geom))
33
- assert_kind_of(ActiveRecord::ConnectionAdapters::PostgreSQLSpatialColumn, FooGeography.geography_column_by_name(:the_other_geom))
34
- end
35
-
36
- def test_accessors
37
- foo = FooGeography.find(1)
38
-
39
- Geos::ActiveRecord::SpatialColumns::SPATIAL_COLUMN_OUTPUT_FORMATS.each do |format|
40
- assert(foo.respond_to?("the_geom_#{format}"))
41
- assert(foo.respond_to?("the_other_geom_#{format}"))
42
- end
43
- end
44
-
45
- def test_without_accessor
46
- foo = FooGeography.find(1)
47
- assert_kind_of(String, foo.the_geom)
48
- end
49
-
50
- def test_geos_accessor
51
- foo = FooGeography.find(1)
52
- assert_kind_of(Geos::Point, foo.the_geom_geos)
53
- end
54
-
55
- def test_wkt_accessor
56
- foo = FooGeography.find(1)
57
- assert_kind_of(String, foo.the_geom_wkt)
58
- assert_match(/^POINT\s*\(0\.0+\s+0\.0+\)$/, foo.the_geom_wkt)
59
- end
60
-
61
- def test_wkb_accessor
62
- foo = FooGeography.find(1)
63
- assert_kind_of(String, foo.the_geom_wkb)
64
- assert_match(/^[A-F0-9]+$/, foo.the_geom_wkb)
65
- end
66
-
67
- def test_ewkt_accessor
68
- foo = FooGeography.find(1)
69
- assert_kind_of(String, foo.the_geom_ewkt)
70
- assert_match(/^SRID=\d+;POINT\s*\(0\.0+\s+0\.0+\)$/, foo.the_geom_ewkt)
71
- end
72
-
73
- def test_ewkb_accessor
74
- foo = FooGeography.find(1)
75
- assert_kind_of(String, foo.the_geom_ewkb)
76
- assert(/^[A-F0-9]+$/, foo.the_geom_wkb)
77
- end
78
-
79
- def test_wkb_bin_accessor
80
- foo = FooGeography.find(1)
81
- assert_kind_of(String, foo.the_geom_wkb_bin)
82
- end
83
-
84
- def test_ewkb_bin_accessor
85
- foo = FooGeography.find(1)
86
- assert_kind_of(String, foo.the_geom_ewkb_bin)
87
- end
88
-
89
- def test_geos_create
90
- foo = FooGeography.create!(
91
- :name => 'test_geos_create',
92
- :the_geom => Geos.read(POINT_WKT)
93
- )
94
-
95
- foo.reload
96
- assert_saneness_of_point(foo.the_geom_geos)
97
- end
98
-
99
- def test_wkt_create
100
- foo = FooGeography.create!(
101
- :name => 'test_wkt_create',
102
- :the_geom => POINT_WKT
103
- )
104
-
105
- foo.reload
106
- assert_saneness_of_point(foo.the_geom_geos)
107
- end
108
-
109
- def test_wkb_create
110
- foo = FooGeography.create!(
111
- :name => 'test_wkb_create',
112
- :the_geom => POINT_WKB
113
- )
114
-
115
- foo.reload
116
- assert_saneness_of_point(foo.the_geom_geos)
117
- end
118
-
119
- def test_ewkt_create_with_srid_4326
120
- foo = FooGeography.create!(
121
- :name => 'test_ewkt_create_with_srid_4326',
122
- :the_other_geom => POINT_EWKT
123
- )
124
-
125
- foo.reload
126
- assert_saneness_of_point(foo.the_other_geom_geos)
127
- end
128
-
129
- def test_create_with_no_srid_converting_to_4326
130
- foo = FooGeography.create!(
131
- :name => 'test_ewkt_create_with_no_srid_converting_to_4326',
132
- :the_other_geom => POINT_WKT
133
- )
134
-
135
- foo.reload
136
- assert_saneness_of_point(foo.the_other_geom_geos)
137
- end
138
-
139
- def test_create_with_no_srid_converting_to_minus_1
140
- foo = FooGeography.create!(
141
- :name => 'test_ewkt_create_with_no_srid_converting_to_minus_1',
142
- :the_geom => POINT_EWKT
143
- )
144
-
145
- foo.reload
146
- assert_saneness_of_point(foo.the_geom_geos)
147
- end
148
-
149
- def test_create_with_converting_from_900913_to_4326
150
- FooGeography.create!(
151
- :name => 'test_create_with_converting_from_900913_to_4326',
152
- :the_other_geom => "SRID=900913; #{POINT_WKT}"
153
- )
154
- end
155
-
156
- def test_ewkt_create_with_srid_default
157
- foo = FooGeography.create!(
158
- :name => 'test_ewkt_create_with_srid_default',
159
- :the_other_geom => POINT_EWKT_WITH_DEFAULT
160
- )
161
-
162
- foo.reload
163
- assert_saneness_of_point(foo.the_other_geom_geos)
164
- end
165
-
166
- def test_ewkb_create
167
- foo = FooGeography.create!(
168
- :name => 'test_ewkb_create',
169
- :the_other_geom => POINT_EWKB
170
- )
171
-
172
- foo.reload
173
- assert_saneness_of_point(foo.the_other_geom_geos)
174
- end
175
- end
176
- end
@@ -1,178 +0,0 @@
1
-
2
- $: << File.dirname(__FILE__)
3
- require 'test_helper'
4
-
5
- if ENV['TEST_ACTIVERECORD']
6
- class GeometryColumnsTests < ActiveRecord::TestCase
7
- include TestHelper
8
- include ActiveRecord::TestFixtures
9
-
10
- self.fixture_path = File.join(File.dirname(__FILE__), 'fixtures')
11
- fixtures :foos
12
-
13
- def test_geometry_columns_detected
14
- assert_equal(2, Foo.geometry_columns.length)
15
-
16
- Foo.geometry_columns.each do |column|
17
- assert_kind_of(ActiveRecord::ConnectionAdapters::PostgreSQLGeometryColumn, column)
18
- end
19
- end
20
-
21
- def test_srid_for
22
- assert_equal(Geos::ActiveRecord.UNKNOWN_SRID, Foo.srid_for(:the_geom))
23
- assert_equal(4326, Foo.srid_for(:the_other_geom))
24
- end
25
-
26
- def test_coord_dimension_for
27
- assert_equal(2, Foo.coord_dimension_for(:the_geom))
28
- assert_equal(2, Foo.coord_dimension_for(:the_other_geom))
29
- end
30
-
31
- def test_geometry_column_by_name
32
- assert_kind_of(ActiveRecord::ConnectionAdapters::PostgreSQLGeometryColumn, Foo.geometry_column_by_name(:the_geom))
33
- assert_kind_of(ActiveRecord::ConnectionAdapters::PostgreSQLGeometryColumn, Foo.geometry_column_by_name(:the_other_geom))
34
- end
35
-
36
- def test_accessors
37
- foo = Foo.find(1)
38
-
39
- Geos::ActiveRecord::SpatialColumns::SPATIAL_COLUMN_OUTPUT_FORMATS.each do |format|
40
- assert(foo.respond_to?("the_geom_#{format}"))
41
- assert(foo.respond_to?("the_other_geom_#{format}"))
42
- end
43
- end
44
-
45
- def test_without_accessor
46
- foo = Foo.find(1)
47
- assert_kind_of(String, foo.the_geom)
48
- end
49
-
50
- def test_geos_accessor
51
- foo = Foo.find(1)
52
- assert_kind_of(Geos::Point, foo.the_geom_geos)
53
- end
54
-
55
- def test_wkt_accessor
56
- foo = Foo.find(1)
57
- assert_kind_of(String, foo.the_geom_wkt)
58
- assert_match(/^POINT\s*\(0\.0+\s+0\.0+\)$/, foo.the_geom_wkt)
59
- end
60
-
61
- def test_wkb_accessor
62
- foo = Foo.find(1)
63
- assert_kind_of(String, foo.the_geom_wkb)
64
- assert_match(/^[A-F0-9]+$/, foo.the_geom_wkb)
65
- end
66
-
67
- def test_ewkt_accessor
68
- foo = Foo.find(1)
69
- assert_kind_of(String, foo.the_geom_ewkt)
70
- assert_match(/^SRID=\d+;POINT\s*\(0\.0+\s+0\.0+\)$/, foo.the_geom_ewkt)
71
- end
72
-
73
- def test_ewkb_accessor
74
- foo = Foo.find(1)
75
- assert_kind_of(String, foo.the_geom_ewkb)
76
- assert(/^[A-F0-9]+$/, foo.the_geom_wkb)
77
- end
78
-
79
- def test_wkb_bin_accessor
80
- foo = Foo.find(1)
81
- assert_kind_of(String, foo.the_geom_wkb_bin)
82
- end
83
-
84
- def test_ewkb_bin_accessor
85
- foo = Foo.find(1)
86
- assert_kind_of(String, foo.the_geom_ewkb_bin)
87
- end
88
-
89
- def test_geos_create
90
- foo = Foo.create!(
91
- :name => 'test_geos_create',
92
- :the_geom => Geos.read(POINT_WKT)
93
- )
94
-
95
- foo.reload
96
- assert_saneness_of_point(foo.the_geom_geos)
97
- end
98
-
99
- def test_wkt_create
100
- foo = Foo.create!(
101
- :name => 'test_wkt_create',
102
- :the_geom => POINT_WKT
103
- )
104
-
105
- foo.reload
106
- assert_saneness_of_point(foo.the_geom_geos)
107
- end
108
-
109
- def test_wkb_create
110
- foo = Foo.create!(
111
- :name => 'test_wkb_create',
112
- :the_geom => POINT_WKB
113
- )
114
-
115
- foo.reload
116
- assert_saneness_of_point(foo.the_geom_geos)
117
- end
118
-
119
- def test_ewkt_create_with_srid_4326
120
- foo = Foo.create!(
121
- :name => 'test_ewkt_create_with_srid_4326',
122
- :the_other_geom => POINT_EWKT
123
- )
124
-
125
- foo.reload
126
- assert_saneness_of_point(foo.the_other_geom_geos)
127
- end
128
-
129
- def test_create_with_no_srid_converting_to_4326
130
- foo = Foo.create!(
131
- :name => 'test_ewkt_create_with_no_srid_converting_to_4326',
132
- :the_other_geom => POINT_WKT
133
- )
134
-
135
- foo.reload
136
- assert_saneness_of_point(foo.the_other_geom_geos)
137
- end
138
-
139
- def test_create_with_no_srid_converting_to_minus_1
140
- foo = Foo.create!(
141
- :name => 'test_ewkt_create_with_no_srid_converting_to_minus_1',
142
- :the_geom => POINT_EWKT
143
- )
144
-
145
- foo.reload
146
- assert_saneness_of_point(foo.the_geom_geos)
147
- end
148
-
149
- def test_create_with_converting_from_900913_to_4326
150
- assert_raise(Geos::ActiveRecord::GeometryColumns::CantConvertSRID) do
151
- Foo.create!(
152
- :name => 'test_create_with_converting_from_900913_to_4326',
153
- :the_other_geom => "SRID=900913; #{POINT_WKT}"
154
- )
155
- end
156
- end
157
-
158
- def test_ewkt_create_with_srid_default
159
- foo = Foo.create!(
160
- :name => 'test_ewkt_create_with_srid_default',
161
- :the_other_geom => POINT_EWKT_WITH_DEFAULT
162
- )
163
-
164
- foo.reload
165
- assert_saneness_of_point(foo.the_other_geom_geos)
166
- end
167
-
168
- def test_ewkb_create
169
- foo = Foo.create!(
170
- :name => 'test_ewkb_create',
171
- :the_other_geom => POINT_EWKB
172
- )
173
-
174
- foo.reload
175
- assert_saneness_of_point(foo.the_other_geom_geos)
176
- end
177
- end
178
- end