geos-extensions 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/Gemfile +17 -0
- data/Guardfile +17 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +19 -91
- data/Rakefile +1 -12
- data/geos-extensions.gemspec +1 -9
- data/lib/geos-extensions.rb +1 -9
- data/lib/geos/coordinate_sequence.rb +92 -0
- data/lib/geos/extensions/version.rb +1 -1
- data/lib/geos/geometry.rb +252 -0
- data/lib/geos/geometry_collection.rb +60 -0
- data/lib/geos/geos_helper.rb +86 -72
- data/lib/geos/google_maps.rb +1 -0
- data/lib/geos/google_maps/api_2.rb +9 -23
- data/lib/geos/google_maps/api_3.rb +10 -24
- data/lib/geos/google_maps/api_common.rb +41 -0
- data/lib/geos/line_string.rb +15 -0
- data/lib/geos/multi_line_string.rb +15 -0
- data/lib/geos/multi_point.rb +15 -0
- data/lib/geos/multi_polygon.rb +27 -0
- data/lib/geos/point.rb +120 -0
- data/lib/geos/polygon.rb +158 -0
- data/lib/geos/yaml.rb +30 -0
- data/lib/geos/yaml/psych.rb +18 -0
- data/lib/geos/yaml/syck.rb +41 -0
- data/lib/geos_extensions.rb +110 -711
- data/test/google_maps_api_2_tests.rb +54 -32
- data/test/google_maps_api_3_tests.rb +58 -36
- data/test/google_maps_polyline_encoder_tests.rb +1 -1
- data/test/helper_tests.rb +28 -0
- data/test/misc_tests.rb +130 -10
- data/test/reader_tests.rb +38 -1
- data/test/test_helper.rb +54 -146
- data/test/writer_tests.rb +329 -10
- data/test/yaml_tests.rb +203 -0
- metadata +26 -102
- data/app/models/geos/geometry_column.rb +0 -39
- data/app/models/geos/spatial_ref_sys.rb +0 -12
- data/lib/geos/active_record_extensions.rb +0 -12
- data/lib/geos/active_record_extensions/connection_adapters/postgresql_adapter.rb +0 -151
- data/lib/geos/active_record_extensions/spatial_columns.rb +0 -367
- data/lib/geos/active_record_extensions/spatial_scopes.rb +0 -493
- data/lib/geos/rails/engine.rb +0 -6
- data/lib/tasks/test.rake +0 -42
- data/test/adapter_tests.rb +0 -38
- data/test/database.yml +0 -17
- data/test/fixtures/foo3ds.yml +0 -16
- data/test/fixtures/foo_geographies.yml +0 -16
- data/test/fixtures/foos.yml +0 -16
- data/test/geography_columns_tests.rb +0 -176
- data/test/geometry_columns_tests.rb +0 -178
- data/test/spatial_scopes_geographies_tests.rb +0 -107
- data/test/spatial_scopes_tests.rb +0 -337
@@ -8,14 +8,23 @@ rescue LoadError
|
|
8
8
|
# do nothing
|
9
9
|
end
|
10
10
|
|
11
|
-
class GoogleMapsApi2Tests <
|
11
|
+
class GoogleMapsApi2Tests < MiniTest::Unit::TestCase
|
12
12
|
include TestHelper
|
13
13
|
|
14
|
+
def initialize(*args)
|
15
|
+
@point = Geos.read(POINT_WKT)
|
16
|
+
@polygon = Geos.read(POLYGON_WKT)
|
17
|
+
@linestring = Geos.read(LINESTRING_WKT)
|
18
|
+
@multipoint = Geos.read(MULTIPOINT_WKT)
|
19
|
+
@multipolygon = Geos.read(MULTIPOLYGON_WKT)
|
20
|
+
@multilinestring = Geos.read(MULTILINESTRING_WKT)
|
21
|
+
@geometrycollection = Geos.read(GEOMETRYCOLLECTION_WKT)
|
22
|
+
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
14
26
|
def setup
|
15
27
|
Geos::GoogleMaps.use_api(2)
|
16
|
-
|
17
|
-
@point = Geos.read(POINT_EWKB)
|
18
|
-
@polygon = Geos.read(POLYGON_EWKB)
|
19
28
|
end
|
20
29
|
|
21
30
|
def test_to_g_lat_lng
|
@@ -25,45 +34,58 @@ class GoogleMapsApi2Tests < Test::Unit::TestCase
|
|
25
34
|
|
26
35
|
def test_to_g_lat_lng_bounds_string
|
27
36
|
assert_equal('((10.0100000000,10.0000000000), (10.0100000000,10.0000000000))', @point.to_g_lat_lng_bounds_string)
|
28
|
-
assert_equal('((0.0000000000,0.0000000000), (
|
37
|
+
assert_equal('((0.0000000000,0.0000000000), (2.5000000000,5.0000000000))', @polygon.to_g_lat_lng_bounds_string)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_to_g_url_value_point
|
41
|
+
assert_equal('10.010000,10.000000', @point.to_g_url_value)
|
42
|
+
assert_equal('10.010,10.000', @point.to_g_url_value(3))
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_to_g_url_value_polygon
|
46
|
+
assert_equal('0.000000,0.000000,2.500000,5.000000', @polygon.to_g_url_value)
|
47
|
+
assert_equal('0.000,0.000,2.500,5.000', @polygon.to_g_url_value(3))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_to_g_url_value_line_string
|
51
|
+
assert_equal('0.000000,0.000000,10.000000,10.000000', @linestring.to_g_url_value)
|
52
|
+
assert_equal('0.000,0.000,10.000,10.000', @linestring.to_g_url_value(3))
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_to_g_url_value_multi_point
|
56
|
+
assert_equal('0.000000,0.000000,10.000000,10.000000', @multipoint.to_g_url_value)
|
57
|
+
assert_equal('0.000,0.000,10.000,10.000', @multipoint.to_g_url_value(3))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_to_g_url_value_multi_polygon
|
61
|
+
assert_equal('0.000000,0.000000,15.000000,15.000000', @multipolygon.to_g_url_value)
|
62
|
+
assert_equal('0.000,0.000,15.000,15.000', @multipolygon.to_g_url_value(3))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_to_g_url_value_multi_line_string
|
66
|
+
assert_equal('-20.000000,-20.000000,30.000000,30.000000', @multilinestring.to_g_url_value)
|
67
|
+
assert_equal('-20.000,-20.000,30.000,30.000', @multilinestring.to_g_url_value(3))
|
29
68
|
end
|
30
69
|
|
31
|
-
def
|
32
|
-
assert_equal(
|
33
|
-
|
34
|
-
:lat => 10.01,
|
35
|
-
:lng => 10.0
|
36
|
-
}, @point.to_jsonable)
|
37
|
-
|
38
|
-
assert_equal({
|
39
|
-
:type => "polygon",
|
40
|
-
:polylines => [{
|
41
|
-
:points => "??_ibE_ibE_~cH_~cH_hgN_hgN~po]~po]",
|
42
|
-
:bounds => {
|
43
|
-
:sw => [ 0.0, 0.0 ],
|
44
|
-
:ne => [ 5.0, 5.0 ]
|
45
|
-
},
|
46
|
-
:levels=>"BBBBB"
|
47
|
-
}],
|
48
|
-
:options => {},
|
49
|
-
:encoded => true
|
50
|
-
}, @polygon.to_jsonable)
|
70
|
+
def test_to_g_url_value_geometry_collection
|
71
|
+
assert_equal('0.000000,0.000000,14.000000,14.000000', @geometrycollection.to_g_url_value)
|
72
|
+
assert_equal('0.000,0.000,14.000,14.000', @geometrycollection.to_g_url_value(3))
|
51
73
|
end
|
52
74
|
|
53
75
|
if defined?(JSON)
|
54
76
|
def test_to_g_polygon
|
55
77
|
assert_equal(
|
56
|
-
"new google.maps.Polygon([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0,
|
78
|
+
"new google.maps.Polygon([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 0.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(2.5, 5.0), new google.maps.LatLng(0.0, 0.0)], null, null, null, null, null, null)",
|
57
79
|
@polygon.to_g_polygon
|
58
80
|
)
|
59
81
|
|
60
82
|
assert_equal(
|
61
|
-
"new GPolygon([new GLatLng(0.0, 0.0), new GLatLng(1.0,
|
83
|
+
"new GPolygon([new GLatLng(0.0, 0.0), new GLatLng(1.0, 0.0), new GLatLng(2.5, 2.5), new GLatLng(2.5, 5.0), new GLatLng(0.0, 0.0)], null, null, null, null, null, null)",
|
62
84
|
@polygon.to_g_polygon({}, :short_class => true)
|
63
85
|
)
|
64
86
|
|
65
87
|
assert_equal(
|
66
|
-
"new google.maps.Polygon([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0,
|
88
|
+
"new google.maps.Polygon([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 0.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(2.5, 5.0), new google.maps.LatLng(0.0, 0.0)], '#b00b1e', 5, 0.5, '#b00b1e', null, {\"mouseOutTolerence\":5})",
|
67
89
|
@polygon.to_g_polygon(
|
68
90
|
:stroke_color => '#b00b1e',
|
69
91
|
:stroke_weight => 5,
|
@@ -78,17 +100,17 @@ class GoogleMapsApi2Tests < Test::Unit::TestCase
|
|
78
100
|
|
79
101
|
def test_to_g_polyline
|
80
102
|
assert_equal(
|
81
|
-
"new google.maps.Polyline([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0,
|
103
|
+
"new google.maps.Polyline([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 0.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(2.5, 5.0), new google.maps.LatLng(0.0, 0.0)], null, null, null, null)",
|
82
104
|
@polygon.to_g_polyline
|
83
105
|
)
|
84
106
|
|
85
107
|
assert_equal(
|
86
|
-
"new GPolyline([new GLatLng(0.0, 0.0), new GLatLng(1.0,
|
108
|
+
"new GPolyline([new GLatLng(0.0, 0.0), new GLatLng(1.0, 0.0), new GLatLng(2.5, 2.5), new GLatLng(2.5, 5.0), new GLatLng(0.0, 0.0)], null, null, null, null)",
|
87
109
|
@polygon.to_g_polyline({}, :short_class => true)
|
88
110
|
)
|
89
111
|
|
90
112
|
assert_equal(
|
91
|
-
"new google.maps.Polyline([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0,
|
113
|
+
"new google.maps.Polyline([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 0.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(2.5, 5.0), new google.maps.LatLng(0.0, 0.0)], '#b00b1e', 5, 0.5, {\"mouseOutTolerence\":5})",
|
92
114
|
@polygon.to_g_polyline(
|
93
115
|
:color => '#b00b1e',
|
94
116
|
:weight => 5,
|
@@ -182,7 +204,7 @@ class GoogleMapsApi2Tests < Test::Unit::TestCase
|
|
182
204
|
|
183
205
|
def test_to_g_lat_lon_box
|
184
206
|
assert_equal(
|
185
|
-
{ :east => 5.0, :west => 0.0, :north => 5
|
207
|
+
{ :east => 5.0, :west => 0.0, :north => 2.5, :south => 0.0},
|
186
208
|
@polygon.to_g_lat_lon_box
|
187
209
|
)
|
188
210
|
end
|
@@ -8,14 +8,23 @@ rescue LoadError
|
|
8
8
|
# do nothing
|
9
9
|
end
|
10
10
|
|
11
|
-
class GoogleMapsApi3Tests <
|
11
|
+
class GoogleMapsApi3Tests < MiniTest::Unit::TestCase
|
12
12
|
include TestHelper
|
13
13
|
|
14
|
+
def initialize(*args)
|
15
|
+
@point = Geos.read(POINT_WKT)
|
16
|
+
@polygon = Geos.read(POLYGON_WKT)
|
17
|
+
@linestring = Geos.read(LINESTRING_WKT)
|
18
|
+
@multipoint = Geos.read(MULTIPOINT_WKT)
|
19
|
+
@multipolygon = Geos.read(MULTIPOLYGON_WKT)
|
20
|
+
@multilinestring = Geos.read(MULTILINESTRING_WKT)
|
21
|
+
@geometrycollection = Geos.read(GEOMETRYCOLLECTION_WKT)
|
22
|
+
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
14
26
|
def setup
|
15
27
|
Geos::GoogleMaps.use_api(3)
|
16
|
-
|
17
|
-
@point = Geos.read(POINT_EWKB)
|
18
|
-
@polygon = Geos.read(POLYGON_EWKB)
|
19
28
|
end
|
20
29
|
|
21
30
|
def test_to_g_lat_lng
|
@@ -25,34 +34,47 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
|
|
25
34
|
|
26
35
|
def test_to_g_lat_lng_bounds_string
|
27
36
|
assert_equal('((10.0100000000,10.0000000000), (10.0100000000,10.0000000000))', @point.to_g_lat_lng_bounds_string)
|
28
|
-
assert_equal('((0.0000000000,0.0000000000), (
|
37
|
+
assert_equal('((0.0000000000,0.0000000000), (2.5000000000,5.0000000000))', @polygon.to_g_lat_lng_bounds_string)
|
29
38
|
end
|
30
39
|
|
31
|
-
def
|
40
|
+
def test_to_g_geocoder_bounds
|
32
41
|
assert_equal('10.010000,10.000000|10.010000,10.000000', @point.to_g_geocoder_bounds)
|
33
|
-
assert_equal('0.000000,0.000000|
|
42
|
+
assert_equal('0.000000,0.000000|2.500000,5.000000', @polygon.to_g_geocoder_bounds)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_to_g_url_value_point
|
46
|
+
assert_equal('10.010000,10.000000', @point.to_g_url_value)
|
47
|
+
assert_equal('10.010,10.000', @point.to_g_url_value(3))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_to_g_url_value_polygon
|
51
|
+
assert_equal('0.000000,0.000000,2.500000,5.000000', @polygon.to_g_url_value)
|
52
|
+
assert_equal('0.000,0.000,2.500,5.000', @polygon.to_g_url_value(3))
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_to_g_url_value_line_string
|
56
|
+
assert_equal('0.000000,0.000000,10.000000,10.000000', @linestring.to_g_url_value)
|
57
|
+
assert_equal('0.000,0.000,10.000,10.000', @linestring.to_g_url_value(3))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_to_g_url_value_multi_point
|
61
|
+
assert_equal('0.000000,0.000000,10.000000,10.000000', @multipoint.to_g_url_value)
|
62
|
+
assert_equal('0.000,0.000,10.000,10.000', @multipoint.to_g_url_value(3))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_to_g_url_value_multi_polygon
|
66
|
+
assert_equal('0.000000,0.000000,15.000000,15.000000', @multipolygon.to_g_url_value)
|
67
|
+
assert_equal('0.000,0.000,15.000,15.000', @multipolygon.to_g_url_value(3))
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_to_g_url_value_multi_line_string
|
71
|
+
assert_equal('-20.000000,-20.000000,30.000000,30.000000', @multilinestring.to_g_url_value)
|
72
|
+
assert_equal('-20.000,-20.000,30.000,30.000', @multilinestring.to_g_url_value(3))
|
34
73
|
end
|
35
74
|
|
36
|
-
def
|
37
|
-
assert_equal(
|
38
|
-
|
39
|
-
:lat => 10.01,
|
40
|
-
:lng => 10.0
|
41
|
-
}, @point.to_jsonable)
|
42
|
-
|
43
|
-
assert_equal({
|
44
|
-
:type => "polygon",
|
45
|
-
:polylines => [{
|
46
|
-
:points => "??_ibE_ibE_~cH_~cH_hgN_hgN~po]~po]",
|
47
|
-
:bounds => {
|
48
|
-
:sw => [ 0.0, 0.0 ],
|
49
|
-
:ne => [ 5.0, 5.0 ]
|
50
|
-
},
|
51
|
-
:levels=>"BBBBB"
|
52
|
-
}],
|
53
|
-
:options => {},
|
54
|
-
:encoded => true
|
55
|
-
}, @polygon.to_jsonable)
|
75
|
+
def test_to_g_url_value_geometry_collection
|
76
|
+
assert_equal('0.000000,0.000000,14.000000,14.000000', @geometrycollection.to_g_url_value)
|
77
|
+
assert_equal('0.000,0.000,14.000,14.000', @geometrycollection.to_g_url_value(3))
|
56
78
|
end
|
57
79
|
|
58
80
|
if defined?(JSON)
|
@@ -67,7 +89,7 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
|
|
67
89
|
def test_to_g_polygon
|
68
90
|
poly_tester('Polygon', {
|
69
91
|
"paths" => [
|
70
|
-
[0.0, 0.0], [1.0,
|
92
|
+
[0.0, 0.0], [1.0, 0.0], [2.5, 2.5], [2.5, 5.0], [0.0, 0.0]
|
71
93
|
]
|
72
94
|
}, @polygon.to_g_polygon)
|
73
95
|
|
@@ -78,11 +100,11 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
|
|
78
100
|
'fillColor' => '#b00b1e',
|
79
101
|
'map' => 'map',
|
80
102
|
'paths' => [
|
81
|
-
[
|
82
|
-
[
|
83
|
-
[
|
84
|
-
[
|
85
|
-
[
|
103
|
+
[0.0, 0.0],
|
104
|
+
[1.0, 0.0],
|
105
|
+
[2.5, 2.5],
|
106
|
+
[2.5, 5.0],
|
107
|
+
[0.0, 0.0]
|
86
108
|
]
|
87
109
|
}, @polygon.to_g_polygon(
|
88
110
|
:stroke_color => '#b00b1e',
|
@@ -169,7 +191,7 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
|
|
169
191
|
def test_to_g_polyline
|
170
192
|
poly_tester("Polyline", {
|
171
193
|
"path" => [
|
172
|
-
[0.0, 0.0], [1.0,
|
194
|
+
[0.0, 0.0], [1.0, 0.0], [2.5, 2.5], [2.5, 5.0], [0.0, 0.0]
|
173
195
|
]
|
174
196
|
}, @polygon.to_g_polyline)
|
175
197
|
|
@@ -179,7 +201,7 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
|
|
179
201
|
"strokeOpacity" => 0.5,
|
180
202
|
"map" => "map",
|
181
203
|
"path" => [
|
182
|
-
[0.0, 0.0], [1.0,
|
204
|
+
[0.0, 0.0], [1.0, 0.0], [2.5, 2.5], [2.5, 5.0], [0.0, 0.0]
|
183
205
|
]
|
184
206
|
}, @polygon.to_g_polyline(
|
185
207
|
:stroke_color => '#b00b1e',
|
@@ -241,7 +263,7 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
|
|
241
263
|
|
242
264
|
def test_to_g_lat_lon_box
|
243
265
|
assert_equal(
|
244
|
-
{ :east => 5.0, :west => 0.0, :north => 5
|
266
|
+
{ :east => 5.0, :west => 0.0, :north => 2.5, :south => 0.0},
|
245
267
|
@polygon.to_g_lat_lon_box
|
246
268
|
)
|
247
269
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
$: << File.dirname(__FILE__)
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class HelperTests
|
6
|
+
class ArrayWrapTests < MiniTest::Unit::TestCase
|
7
|
+
include TestHelper
|
8
|
+
|
9
|
+
def test_array
|
10
|
+
ary = %w(foo bar)
|
11
|
+
assert_same ary, Geos::Helper.array_wrap(ary)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_nil
|
15
|
+
assert_equal [], Geos::Helper.array_wrap(nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_object
|
19
|
+
o = Object.new
|
20
|
+
assert_equal [ o ], Geos::Helper.array_wrap(o)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_string
|
24
|
+
assert_equal [ "foo" ], Geos::Helper.array_wrap("foo")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/test/misc_tests.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class GeosMiscTests <
|
5
|
+
class GeosMiscTests < MiniTest::Unit::TestCase
|
6
6
|
include TestHelper
|
7
7
|
|
8
8
|
def initialize(*args)
|
@@ -15,25 +15,55 @@ class GeosMiscTests < Test::Unit::TestCase
|
|
15
15
|
g.to_wkt(:rounding_precision => 0)
|
16
16
|
end
|
17
17
|
|
18
|
+
def test_sanity_of_test_geometries
|
19
|
+
%w{
|
20
|
+
POINT_WKT
|
21
|
+
POINT_EWKT
|
22
|
+
POINT_WKB
|
23
|
+
POINT_WKB_BIN
|
24
|
+
POINT_EWKB
|
25
|
+
POINT_EWKB_BIN
|
26
|
+
POINT_G_LAT_LNG
|
27
|
+
POINT_G_LAT_LNG_URL_VALUE
|
28
|
+
POLYGON_WKT
|
29
|
+
POLYGON_EWKT
|
30
|
+
POLYGON_WKB
|
31
|
+
POLYGON_WKB_BIN
|
32
|
+
POLYGON_EWKB
|
33
|
+
POLYGON_EWKB_BIN
|
34
|
+
POLYGON_WITH_INTERIOR_RING
|
35
|
+
LINESTRING_WKT
|
36
|
+
GEOMETRYCOLLECTION_WKT
|
37
|
+
MULTIPOINT_WKT
|
38
|
+
MULTIPOLYGON_WKT
|
39
|
+
MULTILINESTRING_WKT
|
40
|
+
BOUNDS_G_LAT_LNG
|
41
|
+
BOUNDS_G_LAT_LNG_URL_VALUE
|
42
|
+
}.each do |constant_name|
|
43
|
+
geom = Geos.read(self.class.const_get(constant_name))
|
44
|
+
assert_equal("Valid Geometry", geom.valid_reason)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
18
48
|
def test_upper_left
|
19
|
-
assert_equal('POINT (0
|
49
|
+
assert_equal('POINT (0 2)', write(@polygon.upper_left))
|
20
50
|
assert_equal('POINT (10 10)', write(@point.upper_left))
|
21
51
|
|
22
|
-
assert_equal('POINT (0
|
52
|
+
assert_equal('POINT (0 2)', write(@polygon.northwest))
|
23
53
|
assert_equal('POINT (10 10)', write(@point.northwest))
|
24
54
|
|
25
|
-
assert_equal('POINT (0
|
55
|
+
assert_equal('POINT (0 2)', write(@polygon.nw))
|
26
56
|
assert_equal('POINT (10 10)', write(@point.nw))
|
27
57
|
end
|
28
58
|
|
29
59
|
def test_upper_right
|
30
|
-
assert_equal('POINT (5
|
60
|
+
assert_equal('POINT (5 2)', write(@polygon.upper_right))
|
31
61
|
assert_equal('POINT (10 10)', write(@point.upper_right))
|
32
62
|
|
33
|
-
assert_equal('POINT (5
|
63
|
+
assert_equal('POINT (5 2)', write(@polygon.northeast))
|
34
64
|
assert_equal('POINT (10 10)', write(@point.northeast))
|
35
65
|
|
36
|
-
assert_equal('POINT (5
|
66
|
+
assert_equal('POINT (5 2)', write(@polygon.ne))
|
37
67
|
assert_equal('POINT (10 10)', write(@point.ne))
|
38
68
|
end
|
39
69
|
|
@@ -60,13 +90,13 @@ class GeosMiscTests < Test::Unit::TestCase
|
|
60
90
|
end
|
61
91
|
|
62
92
|
def test_top
|
63
|
-
assert_equal(5
|
93
|
+
assert_equal(2.5, @polygon.top)
|
64
94
|
assert_equal(10.01, @point.top)
|
65
95
|
|
66
|
-
assert_equal(5
|
96
|
+
assert_equal(2.5, @polygon.north)
|
67
97
|
assert_equal(10.01, @point.north)
|
68
98
|
|
69
|
-
assert_equal(5
|
99
|
+
assert_equal(2.5, @polygon.n)
|
70
100
|
assert_equal(10.01, @point.n)
|
71
101
|
end
|
72
102
|
|
@@ -102,4 +132,94 @@ class GeosMiscTests < Test::Unit::TestCase
|
|
102
132
|
assert_equal(5.0, @polygon.e)
|
103
133
|
assert_equal(10.0, @point.e)
|
104
134
|
end
|
135
|
+
|
136
|
+
def test_lat_lng
|
137
|
+
linestring = Geos.read('LINESTRING(0 0, 20 25)')
|
138
|
+
|
139
|
+
%w{
|
140
|
+
lat_lng
|
141
|
+
latlng
|
142
|
+
latlong
|
143
|
+
lat_lon
|
144
|
+
latlon
|
145
|
+
}.each do |m|
|
146
|
+
assert_equal([ 10.01, 10.0 ], @point.send(m))
|
147
|
+
assert_equal([ 12.5, 10.0 ], linestring.envelope.send(m))
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_lng_lat
|
152
|
+
linestring = Geos.read('LINESTRING(0 0, 20 25)')
|
153
|
+
|
154
|
+
%w{
|
155
|
+
long_lat
|
156
|
+
lnglat
|
157
|
+
longlat
|
158
|
+
lon_lat
|
159
|
+
lonlat
|
160
|
+
}.each do |m|
|
161
|
+
assert_equal([ 10.0, 10.01 ], @point.send(m))
|
162
|
+
assert_equal([ 10.0, 12.5 ], linestring.envelope.send(m))
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_to_bbox_with_point
|
167
|
+
point_bbox = @point.to_bbox
|
168
|
+
|
169
|
+
assert_equal(10.01, point_bbox[:north])
|
170
|
+
assert_equal(10.0, point_bbox[:east])
|
171
|
+
assert_equal(10.01, point_bbox[:south])
|
172
|
+
assert_equal(10, point_bbox[:west])
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_to_bbox_with_point_with_explicit_long_names
|
176
|
+
point_bbox = @point.to_bbox(:long)
|
177
|
+
|
178
|
+
assert_equal(10.01, point_bbox[:north])
|
179
|
+
assert_equal(10.0, point_bbox[:east])
|
180
|
+
assert_equal(10.01, point_bbox[:south])
|
181
|
+
assert_equal(10, point_bbox[:west])
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_to_bbox_with_point_with_short_names
|
185
|
+
point_bbox = @point.to_bbox(:short)
|
186
|
+
|
187
|
+
assert_equal(10.01, point_bbox[:n])
|
188
|
+
assert_equal(10.0, point_bbox[:e])
|
189
|
+
assert_equal(10.01, point_bbox[:s])
|
190
|
+
assert_equal(10, point_bbox[:w])
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_to_bbox_with_polygon
|
194
|
+
polygon_bbox = @polygon.to_bbox
|
195
|
+
|
196
|
+
assert_equal(2.5, polygon_bbox[:north])
|
197
|
+
assert_equal(5.0, polygon_bbox[:east])
|
198
|
+
assert_equal(0, polygon_bbox[:south])
|
199
|
+
assert_equal(0, polygon_bbox[:west])
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_to_bbox_with_polygon_explicit_long_names
|
203
|
+
polygon_bbox = @polygon.to_bbox(:long)
|
204
|
+
|
205
|
+
assert_equal(2.5, polygon_bbox[:north])
|
206
|
+
assert_equal(5.0, polygon_bbox[:east])
|
207
|
+
assert_equal(0, polygon_bbox[:south])
|
208
|
+
assert_equal(0, polygon_bbox[:west])
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_to_bbox_with_polygon_with_short_names
|
212
|
+
polygon_bbox = @polygon.to_bbox(:short)
|
213
|
+
|
214
|
+
assert_equal(2.5, polygon_bbox[:n])
|
215
|
+
assert_equal(5.0, polygon_bbox[:e])
|
216
|
+
assert_equal(0, polygon_bbox[:s])
|
217
|
+
assert_equal(0, polygon_bbox[:w])
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_to_bbox_with_invalid_long_or_short_value
|
221
|
+
assert_raises(ArgumentError) do
|
222
|
+
@point.to_bbox(:blart)
|
223
|
+
end
|
224
|
+
end
|
105
225
|
end
|