geos-extensions 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/geos-extensions.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{geos-extensions}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{J Smith}]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-11}
|
13
13
|
s.description = %q{Extensions for the GEOS library.}
|
14
14
|
s.email = %q{code@zoocasa.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
"lib/geos/rails/engine.rb",
|
37
37
|
"lib/geos_extensions.rb",
|
38
38
|
"lib/tasks/test.rake",
|
39
|
+
"test/adapter_test.rb",
|
39
40
|
"test/fixtures/foos.yml",
|
40
41
|
"test/geometry_columns_test.rb",
|
41
42
|
"test/geospatial_scopes_test.rb",
|
@@ -11,6 +11,17 @@ module ActiveRecord
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
class PostgreSQLColumn < Column
|
15
|
+
def simplified_type_with_geometry_type(field_type)
|
16
|
+
if field_type == 'geometry'
|
17
|
+
:geometry
|
18
|
+
else
|
19
|
+
simplified_type_without_geometry_type(field_type)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
alias_method_chain :simplified_type, :geometry_type
|
23
|
+
end
|
24
|
+
|
14
25
|
class PostgreSQLAdapter < AbstractAdapter
|
15
26
|
# Returns the geometry columns for the table.
|
16
27
|
def geometry_columns(table_name, name = nil)
|
@@ -1,6 +1,9 @@
|
|
1
1
|
|
2
|
-
module Geos::GoogleMaps
|
3
|
-
module
|
2
|
+
module Geos::GoogleMaps
|
3
|
+
module Api3
|
4
|
+
end
|
5
|
+
|
6
|
+
module Api3Constants
|
4
7
|
UNESCAPED_MARKER_OPTIONS = %w{
|
5
8
|
icon
|
6
9
|
map
|
@@ -9,6 +12,20 @@ module Geos::GoogleMaps::Api3
|
|
9
12
|
shape
|
10
13
|
}.freeze
|
11
14
|
|
15
|
+
UNESCAPED_POLY_OPTIONS = %w{
|
16
|
+
clickable
|
17
|
+
fillOpacity
|
18
|
+
geodesic
|
19
|
+
map
|
20
|
+
path
|
21
|
+
paths
|
22
|
+
strokeOpacity
|
23
|
+
strokeWeight
|
24
|
+
zIndex
|
25
|
+
}.freeze
|
26
|
+
end
|
27
|
+
|
28
|
+
module Api3::Geometry
|
12
29
|
# Returns a new LatLngBounds object with the proper LatLngs in place
|
13
30
|
# for determining the geometry bounds.
|
14
31
|
def to_g_lat_lng_bounds_api3(options = {})
|
@@ -42,25 +59,13 @@ module Geos::GoogleMaps::Api3
|
|
42
59
|
|
43
60
|
opts = Geos::Helper.camelize_keys(marker_options)
|
44
61
|
opts[:position] = self.centroid.to_g_lat_lng(options[:lat_lng_options])
|
45
|
-
json = Geos::Helper.escape_json(opts, UNESCAPED_MARKER_OPTIONS - options[:escape])
|
62
|
+
json = Geos::Helper.escape_json(opts, Geos::GoogleMaps::Api3Constants::UNESCAPED_MARKER_OPTIONS - options[:escape])
|
46
63
|
|
47
64
|
"new google.maps.Marker(#{json})"
|
48
65
|
end
|
49
66
|
end
|
50
67
|
|
51
|
-
module CoordinateSequence
|
52
|
-
UNESCAPED_POLY_OPTIONS = %w{
|
53
|
-
clickable
|
54
|
-
fillOpacity
|
55
|
-
geodesic
|
56
|
-
map
|
57
|
-
path
|
58
|
-
paths
|
59
|
-
strokeOpacity
|
60
|
-
strokeWeight
|
61
|
-
zIndex
|
62
|
-
}.freeze
|
63
|
-
|
68
|
+
module Api3::CoordinateSequence
|
64
69
|
# Returns a Ruby Array of LatLngs.
|
65
70
|
def to_g_lat_lng_api3(options = {})
|
66
71
|
self.to_a.collect do |p|
|
@@ -89,7 +94,7 @@ module Geos::GoogleMaps::Api3
|
|
89
94
|
|
90
95
|
opts = Geos::Helper.camelize_keys(polyline_options)
|
91
96
|
opts[:path] = "[#{self.to_g_lat_lng_api3(options[:lat_lng_options]).join(', ')}]"
|
92
|
-
json = Geos::Helper.escape_json(opts, UNESCAPED_POLY_OPTIONS - options[:escape])
|
97
|
+
json = Geos::Helper.escape_json(opts, Geos::GoogleMaps::Api3Constants::UNESCAPED_POLY_OPTIONS - options[:escape])
|
93
98
|
|
94
99
|
"new google.maps.Polyline(#{json})"
|
95
100
|
end
|
@@ -115,13 +120,13 @@ module Geos::GoogleMaps::Api3
|
|
115
120
|
|
116
121
|
opts = Geos::Helper.camelize_keys(polygon_options)
|
117
122
|
opts[:paths] = "[#{self.to_g_lat_lng_api3(options[:lat_lng_options]).join(', ')}]"
|
118
|
-
json = Geos::Helper.escape_json(opts, UNESCAPED_POLY_OPTIONS - options[:escape])
|
123
|
+
json = Geos::Helper.escape_json(opts, Geos::GoogleMaps::Api3Constants::UNESCAPED_POLY_OPTIONS - options[:escape])
|
119
124
|
|
120
125
|
"new google.maps.Polygon(#{json})"
|
121
126
|
end
|
122
127
|
end
|
123
128
|
|
124
|
-
module Point
|
129
|
+
module Api3::Point
|
125
130
|
# Returns a new LatLng.
|
126
131
|
def to_g_lat_lng_api3(options = {})
|
127
132
|
no_wrap = if options[:no_wrap]
|
@@ -137,7 +142,7 @@ module Geos::GoogleMaps::Api3
|
|
137
142
|
end
|
138
143
|
end
|
139
144
|
|
140
|
-
module Polygon
|
145
|
+
module Api3::Polygon
|
141
146
|
# Returns a Polyline of the exterior ring of the Polygon. This does
|
142
147
|
# not take into consideration any interior rings the Polygon may
|
143
148
|
# have.
|
@@ -153,7 +158,7 @@ module Geos::GoogleMaps::Api3
|
|
153
158
|
end
|
154
159
|
end
|
155
160
|
|
156
|
-
module GeometryCollection
|
161
|
+
module Api3::GeometryCollection
|
157
162
|
# Returns a Ruby Array of Polylines for each geometry in the
|
158
163
|
# collection.
|
159
164
|
def to_g_polyline_api3(polyline_options = {}, options = {})
|
@@ -161,14 +166,39 @@ module Geos::GoogleMaps::Api3
|
|
161
166
|
p.to_g_polyline_api3(polyline_options, options)
|
162
167
|
end
|
163
168
|
end
|
169
|
+
alias :to_g_polylines_api3 :to_g_polyline_api3
|
164
170
|
|
165
171
|
# Returns a Ruby Array of Polygons for each geometry in the
|
166
|
-
# collection.
|
172
|
+
# collection. If the :single option is set, a single Polygon object will
|
173
|
+
# be returned with all of the geometries set in the Polygon's "path"
|
174
|
+
# attribute. You can also use to_g_polygon_single for the same effect.
|
167
175
|
def to_g_polygon_api3(polygon_options = {}, options = {})
|
168
|
-
|
169
|
-
|
176
|
+
if options[:single]
|
177
|
+
self.to_g_polygon_single_api3(polygon_options, options)
|
178
|
+
else
|
179
|
+
self.collect do |p|
|
180
|
+
p.to_g_polygon_api3(polygon_options, options)
|
181
|
+
end
|
170
182
|
end
|
171
183
|
end
|
184
|
+
|
185
|
+
# Behaves the same as to_g_polygon_api3 with the :single option set, where
|
186
|
+
# a single Google Maps Polygon will be returned with all of the Polygons
|
187
|
+
# set in the Polygon's "path" attribute.
|
188
|
+
def to_g_polygon_single_api3(polygon_options = {}, options = {})
|
189
|
+
options = {
|
190
|
+
:escape => [],
|
191
|
+
:lat_lng_options => {}
|
192
|
+
}.merge(options)
|
193
|
+
|
194
|
+
opts = Geos::Helper.camelize_keys(polygon_options)
|
195
|
+
opts[:paths] = %{[#{self.collect { |p|
|
196
|
+
"[#{p.exterior_ring.coord_seq.to_g_lat_lng_api3(options[:lat_lng_options]).join(', ')}]"
|
197
|
+
}.join(', ')}]}
|
198
|
+
json = Geos::Helper.escape_json(opts, Geos::GoogleMaps::Api3Constants::UNESCAPED_POLY_OPTIONS - options[:escape])
|
199
|
+
|
200
|
+
"new google.maps.Polygon(#{json})"
|
201
|
+
end
|
172
202
|
end
|
173
203
|
end
|
174
204
|
|
@@ -0,0 +1,23 @@
|
|
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
|
+
end
|
23
|
+
end
|
@@ -53,7 +53,7 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
|
|
53
53
|
)
|
54
54
|
|
55
55
|
assert_equal(
|
56
|
-
"new google.maps.Polygon({\"strokeColor\": \"#b00b1e\", \"paths\": [new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)]
|
56
|
+
"new google.maps.Polygon({\"strokeColor\": \"#b00b1e\", \"strokeWeight\": 5, \"strokeOpacity\": 0.5, \"fillColor\": \"#b00b1e\", \"map\": map, \"paths\": [new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)]})",
|
57
57
|
@polygon.to_g_polygon(
|
58
58
|
:stroke_color => '#b00b1e',
|
59
59
|
:stroke_weight => 5,
|
@@ -64,6 +64,60 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
|
|
64
64
|
)
|
65
65
|
end
|
66
66
|
|
67
|
+
def test_to_g_polygon_with_multi_polygon
|
68
|
+
multi_polygon = Geos.read(
|
69
|
+
'MULTIPOLYGON(
|
70
|
+
((0 0, 0 5, 5 5, 5 0, 0 0)),
|
71
|
+
((10 10, 10 15, 15 15, 15 10, 10 10)),
|
72
|
+
((20 20, 20 25, 25 25, 25 20, 20 20))
|
73
|
+
)'
|
74
|
+
)
|
75
|
+
options = {
|
76
|
+
:stroke_color => '#b00b1e',
|
77
|
+
:stroke_weight => 5,
|
78
|
+
:stroke_opacity => 0.5,
|
79
|
+
:fill_color => '#b00b1e',
|
80
|
+
:map => 'map'
|
81
|
+
}
|
82
|
+
|
83
|
+
assert_equal(
|
84
|
+
["new google.maps.Polygon({\"strokeColor\": \"#b00b1e\", \"strokeWeight\": 5, \"strokeOpacity\": 0.5, \"fillColor\": \"#b00b1e\", \"map\": map, \"paths\": [new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(5.0, 0.0), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 5.0), new google.maps.LatLng(0.0, 0.0)]})",
|
85
|
+
"new google.maps.Polygon({\"strokeColor\": \"#b00b1e\", \"strokeWeight\": 5, \"strokeOpacity\": 0.5, \"fillColor\": \"#b00b1e\", \"map\": map, \"paths\": [new google.maps.LatLng(10.0, 10.0), new google.maps.LatLng(15.0, 10.0), new google.maps.LatLng(15.0, 15.0), new google.maps.LatLng(10.0, 15.0), new google.maps.LatLng(10.0, 10.0)]})",
|
86
|
+
"new google.maps.Polygon({\"strokeColor\": \"#b00b1e\", \"strokeWeight\": 5, \"strokeOpacity\": 0.5, \"fillColor\": \"#b00b1e\", \"map\": map, \"paths\": [new google.maps.LatLng(20.0, 20.0), new google.maps.LatLng(25.0, 20.0), new google.maps.LatLng(25.0, 25.0), new google.maps.LatLng(20.0, 25.0), new google.maps.LatLng(20.0, 20.0)]})"],
|
87
|
+
multi_polygon.to_g_polygon(
|
88
|
+
:stroke_color => '#b00b1e',
|
89
|
+
:stroke_weight => 5,
|
90
|
+
:stroke_opacity => 0.5,
|
91
|
+
:fill_color => '#b00b1e',
|
92
|
+
:map => 'map'
|
93
|
+
)
|
94
|
+
)
|
95
|
+
|
96
|
+
assert_equal(
|
97
|
+
"new google.maps.Polygon({\"strokeColor\": \"#b00b1e\", \"strokeWeight\": 5, \"strokeOpacity\": 0.5, \"fillColor\": \"#b00b1e\", \"map\": map, \"paths\": [[new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(5.0, 0.0), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 5.0), new google.maps.LatLng(0.0, 0.0)], [new google.maps.LatLng(10.0, 10.0), new google.maps.LatLng(15.0, 10.0), new google.maps.LatLng(15.0, 15.0), new google.maps.LatLng(10.0, 15.0), new google.maps.LatLng(10.0, 10.0)], [new google.maps.LatLng(20.0, 20.0), new google.maps.LatLng(25.0, 20.0), new google.maps.LatLng(25.0, 25.0), new google.maps.LatLng(20.0, 25.0), new google.maps.LatLng(20.0, 20.0)]]})",
|
98
|
+
multi_polygon.to_g_polygon({
|
99
|
+
:stroke_color => '#b00b1e',
|
100
|
+
:stroke_weight => 5,
|
101
|
+
:stroke_opacity => 0.5,
|
102
|
+
:fill_color => '#b00b1e',
|
103
|
+
:map => 'map'
|
104
|
+
}, {
|
105
|
+
:single => true
|
106
|
+
})
|
107
|
+
)
|
108
|
+
|
109
|
+
assert_equal(
|
110
|
+
"new google.maps.Polygon({\"strokeColor\": \"#b00b1e\", \"strokeWeight\": 5, \"strokeOpacity\": 0.5, \"fillColor\": \"#b00b1e\", \"map\": map, \"paths\": [[new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(5.0, 0.0), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 5.0), new google.maps.LatLng(0.0, 0.0)], [new google.maps.LatLng(10.0, 10.0), new google.maps.LatLng(15.0, 10.0), new google.maps.LatLng(15.0, 15.0), new google.maps.LatLng(10.0, 15.0), new google.maps.LatLng(10.0, 10.0)], [new google.maps.LatLng(20.0, 20.0), new google.maps.LatLng(25.0, 20.0), new google.maps.LatLng(25.0, 25.0), new google.maps.LatLng(20.0, 25.0), new google.maps.LatLng(20.0, 20.0)]]})",
|
111
|
+
multi_polygon.to_g_polygon_single(
|
112
|
+
:stroke_color => '#b00b1e',
|
113
|
+
:stroke_weight => 5,
|
114
|
+
:stroke_opacity => 0.5,
|
115
|
+
:fill_color => '#b00b1e',
|
116
|
+
:map => 'map'
|
117
|
+
)
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
67
121
|
def test_to_g_polyline
|
68
122
|
assert_equal(
|
69
123
|
"new google.maps.Polyline({\"path\": [new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)]})",
|
@@ -71,7 +125,7 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
|
|
71
125
|
)
|
72
126
|
|
73
127
|
assert_equal(
|
74
|
-
"new google.maps.Polyline({\"path\": [new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)]
|
128
|
+
"new google.maps.Polyline({\"strokeColor\": \"#b00b1e\", \"strokeWeight\": 5, \"strokeOpacity\": 0.5, \"map\": map, \"path\": [new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)]})",
|
75
129
|
@polygon.to_g_polyline(
|
76
130
|
:stroke_color => '#b00b1e',
|
77
131
|
:stroke_weight => 5,
|
metadata
CHANGED
@@ -1,32 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: geos-extensions
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 0.1.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- J Smith
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-07-06 00:00:00 Z
|
12
|
+
date: 2011-07-11 00:00:00.000000000Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: Extensions for the GEOS library.
|
22
15
|
email: code@zoocasa.com
|
23
16
|
executables: []
|
24
|
-
|
25
17
|
extensions: []
|
26
|
-
|
27
|
-
extra_rdoc_files:
|
18
|
+
extra_rdoc_files:
|
28
19
|
- README.rdoc
|
29
|
-
files:
|
20
|
+
files:
|
30
21
|
- MIT-LICENSE
|
31
22
|
- README.rdoc
|
32
23
|
- Rakefile
|
@@ -47,6 +38,7 @@ files:
|
|
47
38
|
- lib/geos/rails/engine.rb
|
48
39
|
- lib/geos_extensions.rb
|
49
40
|
- lib/tasks/test.rake
|
41
|
+
- test/adapter_test.rb
|
50
42
|
- test/fixtures/foos.yml
|
51
43
|
- test/geometry_columns_test.rb
|
52
44
|
- test/geospatial_scopes_test.rb
|
@@ -57,36 +49,26 @@ files:
|
|
57
49
|
- test/writer_test.rb
|
58
50
|
homepage: http://github.com/zoocasa/geos-extensions
|
59
51
|
licenses: []
|
60
|
-
|
61
52
|
post_install_message:
|
62
53
|
rdoc_options: []
|
63
|
-
|
64
|
-
require_paths:
|
54
|
+
require_paths:
|
65
55
|
- lib
|
66
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
57
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
|
73
|
-
- 0
|
74
|
-
version: "0"
|
75
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
63
|
none: false
|
77
|
-
requirements:
|
78
|
-
- -
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
|
81
|
-
segments:
|
82
|
-
- 0
|
83
|
-
version: "0"
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
84
68
|
requirements: []
|
85
|
-
|
86
69
|
rubyforge_project:
|
87
70
|
rubygems_version: 1.8.5
|
88
71
|
signing_key:
|
89
72
|
specification_version: 3
|
90
73
|
summary: Extensions for the GEOS library.
|
91
74
|
test_files: []
|
92
|
-
|