geos-extensions 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,145 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ begin
6
+ require 'json'
7
+ rescue LoadError
8
+ # do nothing
9
+ end
10
+
11
+ class GoogleMapsApi3Tests < Test::Unit::TestCase
12
+ include TestHelper
13
+
14
+ def setup
15
+ Geos::GoogleMaps.use_api(3)
16
+
17
+ @point = Geos.read(POINT_EWKB)
18
+ @polygon = Geos.read(POLYGON_EWKB)
19
+ end
20
+
21
+ def test_to_g_lat_lng
22
+ assert_equal("new google.maps.LatLng(10.01, 10.0)", @point.to_g_lat_lng)
23
+ assert_equal("new google.maps.LatLng(10.01, 10.0, true)", @point.to_g_lat_lng(:no_wrap => true))
24
+ end
25
+
26
+ def test_to_jsonable
27
+ assert_equal({
28
+ :type => "point",
29
+ :lat => 10.01,
30
+ :lng => 10.0
31
+ }, @point.to_jsonable)
32
+
33
+ assert_equal({
34
+ :type => "polygon",
35
+ :polylines => [{
36
+ :points => "??_ibE_ibE_~cH_~cH_hgN_hgN~po]~po]",
37
+ :bounds => {
38
+ :sw => [ 0.0, 0.0 ],
39
+ :ne => [ 5.0, 5.0 ]
40
+ },
41
+ :levels=>"BBBBB"
42
+ }],
43
+ :options => {},
44
+ :encoded => true
45
+ }, @polygon.to_jsonable)
46
+ end
47
+
48
+ if defined?(JSON)
49
+ def test_to_g_polygon
50
+ assert_equal(
51
+ "new google.maps.Polygon([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)], null, null, null, null, null, null)",
52
+ @polygon.to_g_polygon
53
+ )
54
+
55
+ assert_equal(
56
+ "new google.maps.Polygon([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)], '#b00b1e', 5, 0.5, '#b00b1e', null, {\"mouseOutTolerence\":5})",
57
+ @polygon.to_g_polygon(
58
+ :stroke_color => '#b00b1e',
59
+ :stroke_weight => 5,
60
+ :stroke_opacity => 0.5,
61
+ :fill_color => '#b00b1e',
62
+ :polygon_options => {
63
+ :mouse_out_tolerence => 5
64
+ }
65
+ )
66
+ )
67
+ end
68
+
69
+ def test_to_g_polyline
70
+ assert_equal(
71
+ "new google.maps.Polyline([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)], null, null, null, null)",
72
+ @polygon.to_g_polyline
73
+ )
74
+
75
+ assert_equal(
76
+ "new google.maps.Polyline([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)], '#b00b1e', 5, 0.5, {\"mouseOutTolerence\":5})",
77
+ @polygon.to_g_polyline(
78
+ :color => '#b00b1e',
79
+ :weight => 5,
80
+ :opacity => 0.5,
81
+ :polyline_options => {
82
+ :mouse_out_tolerence => 5
83
+ }
84
+ )
85
+ )
86
+ end
87
+
88
+ def test_to_g_marker_long
89
+ marker = @point.to_g_marker
90
+
91
+ lat, lng, json = if marker =~ /^new\s+
92
+ google\.maps\.Marker\(\{
93
+ "position":\s*
94
+ new\s+google\.maps\.LatLng\(
95
+ (\d+\.\d+),\s*
96
+ (\d+\.\d+)
97
+ \)
98
+ \}\)
99
+ /x
100
+ [ $1, $2, $3 ]
101
+ end
102
+
103
+ assert_in_delta(lng.to_f, 10.00, 0.000001)
104
+ assert_in_delta(lat.to_f, 10.01, 0.000001)
105
+ end
106
+
107
+
108
+ def test_to_g_marker_with_options
109
+ marker = @point.to_g_marker({
110
+ :raise_on_drag => true,
111
+ :cursor => 'test'
112
+ }, {
113
+ :escape => %w{ position }
114
+ })
115
+
116
+ json = if marker =~ /^new\s+
117
+ google\.maps\.Marker\((
118
+ \{[^}]+\}
119
+ )/x
120
+ $1
121
+ end
122
+
123
+ assert_equal(
124
+ { "raiseOnDrag" => true, "cursor" => 'test' },
125
+ JSON.load(json).reject { |k, v|
126
+ %w{ position }.include?(k)
127
+ }
128
+ )
129
+ end
130
+
131
+ def test_to_g_json_point
132
+ assert_equal(
133
+ { :coordinates => [ 10.0, 10.01, 0 ] },
134
+ @point.to_g_json_point
135
+ )
136
+ end
137
+
138
+ def test_to_g_lat_lon_box
139
+ assert_equal(
140
+ { :east => 5.0, :west => 0.0, :north => 5.0, :south => 0.0},
141
+ @polygon.to_g_lat_lon_box
142
+ )
143
+ end
144
+ end
145
+ end
data/test/test_helper.rb CHANGED
@@ -24,7 +24,9 @@ end
24
24
  require File.join(File.dirname(__FILE__), %w{ .. lib geos_extensions })
25
25
 
26
26
  puts "Ruby version #{RUBY_VERSION} - #{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
27
+ puts "Geos library version #{Geos::VERSION}" if defined?(Geos::VERSION)
27
28
  puts "GEOS version #{Geos::GEOS_VERSION}"
29
+ puts "GEOS extensions version #{Geos::GEOS_EXTENSIONS_VERSION}"
28
30
  if defined?(Geos::FFIGeos)
29
31
  puts "Using #{Geos::FFIGeos.geos_library_paths.join(', ')}"
30
32
  end
data/test/writer_test.rb CHANGED
@@ -2,12 +2,6 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- begin
6
- require 'json'
7
- rescue LoadError
8
- # do nothing
9
- end
10
-
11
5
  begin
12
6
  require 'builder'
13
7
  require 'stringio'
@@ -62,175 +56,10 @@ class GeosWriterTests < Test::Unit::TestCase
62
56
  assert_in_delta(lat, 10.01, 0.000001)
63
57
  end
64
58
 
65
- def test_to_g_lat_lng
66
- assert_equal("new google.maps.LatLng(10.01, 10.0)", @point.to_g_lat_lng)
67
- assert_equal("new GLatLng(10.01, 10.0)", @point.to_g_lat_lng(:short_class => true))
68
- end
69
-
70
59
  def test_to_flickr_bbox
71
60
  assert_equal('0.0,0.0,5.0,5.0', @polygon.to_flickr_bbox)
72
61
  end
73
62
 
74
- def test_to_jsonable
75
- assert_equal({
76
- :type => "point",
77
- :lat => 10.01,
78
- :lng => 10.0
79
- }, @point.to_jsonable)
80
-
81
- assert_equal({
82
- :type => "polygon",
83
- :polylines => [{
84
- :points => "??_ibE_ibE_~cH_~cH_hgN_hgN~po]~po]",
85
- :bounds => {
86
- :sw => [ 0.0, 0.0 ],
87
- :ne => [ 5.0, 5.0 ]
88
- },
89
- :levels=>"BBBBB"
90
- }],
91
- :options => {},
92
- :encoded => true
93
- }, @polygon.to_jsonable)
94
- end
95
-
96
- if defined?(JSON)
97
- def test_to_g_polygon
98
- assert_equal(
99
- "new google.maps.Polygon([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)], null, null, null, null, null, null)",
100
- @polygon.to_g_polygon
101
- )
102
-
103
- assert_equal(
104
- "new GPolygon([new GLatLng(0.0, 0.0), new GLatLng(1.0, 1.0), new GLatLng(2.5, 2.5), new GLatLng(5.0, 5.0), new GLatLng(0.0, 0.0)], null, null, null, null, null, null)",
105
- @polygon.to_g_polygon({}, :short_class => true)
106
- )
107
-
108
- assert_equal(
109
- "new google.maps.Polygon([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)], '#b00b1e', 5, 0.5, '#b00b1e', null, {\"mouseOutTolerence\":5})",
110
- @polygon.to_g_polygon(
111
- :stroke_color => '#b00b1e',
112
- :stroke_weight => 5,
113
- :stroke_opacity => 0.5,
114
- :fill_color => '#b00b1e',
115
- :polygon_options => {
116
- :mouse_out_tolerence => 5
117
- }
118
- )
119
- )
120
- end
121
-
122
- def test_to_g_polyline
123
- assert_equal(
124
- "new google.maps.Polyline([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)], null, null, null, null)",
125
- @polygon.to_g_polyline
126
- )
127
-
128
- assert_equal(
129
- "new GPolyline([new GLatLng(0.0, 0.0), new GLatLng(1.0, 1.0), new GLatLng(2.5, 2.5), new GLatLng(5.0, 5.0), new GLatLng(0.0, 0.0)], null, null, null, null)",
130
- @polygon.to_g_polyline({}, :short_class => true)
131
- )
132
-
133
- assert_equal(
134
- "new google.maps.Polyline([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)], '#b00b1e', 5, 0.5, {\"mouseOutTolerence\":5})",
135
- @polygon.to_g_polyline(
136
- :color => '#b00b1e',
137
- :weight => 5,
138
- :opacity => 0.5,
139
- :polyline_options => {
140
- :mouse_out_tolerence => 5
141
- }
142
- )
143
- )
144
- end
145
-
146
- def test_to_g_marker_long
147
- marker = @point.to_g_marker
148
-
149
- lat, lng, json = if marker =~ /^new\s+
150
- google\.maps\.Marker\(
151
- new\s+google\.maps\.LatLng\(
152
- (\d+\.\d+)\s*,\s*
153
- (\d+\.\d+)
154
- \),\s*
155
- ((\{\}))
156
- \)
157
- /x
158
- [ $1, $2, $3 ]
159
- end
160
-
161
- assert_in_delta(lng.to_f, 10.00, 0.000001)
162
- assert_in_delta(lat.to_f, 10.01, 0.000001)
163
- assert_equal(
164
- {},
165
- JSON.load(json)
166
- )
167
- end
168
-
169
- def test_to_g_marker_short_class
170
- marker = @point.to_g_marker({}, :short_class => true)
171
-
172
- lat, lng, json = if marker =~ /^new\s+
173
- GMarker\(
174
- new\s+GLatLng\(
175
- (\d+\.\d+)\s*,\s*
176
- (\d+\.\d+)
177
- \),\s*
178
- (\{\})
179
- \)
180
- /x
181
- [ $1, $2, $3 ]
182
- end
183
-
184
- assert_in_delta(lng.to_f, 10.00, 0.000001)
185
- assert_in_delta(lat.to_f, 10.01, 0.000001)
186
- assert_equal(
187
- {},
188
- JSON.load(json)
189
- )
190
- end
191
-
192
-
193
- def test_to_g_marker_with_options
194
- marker = @point.to_g_marker(
195
- :bounce_gravity => 1,
196
- :bouncy => true
197
- )
198
-
199
- lat, lng, json = if marker =~ /^new\s+
200
- google\.maps\.Marker\(
201
- new\s+google\.maps\.LatLng\(
202
- (\d+\.\d+)\s*,\s*
203
- (\d+\.\d+)
204
- \),\s*
205
- (\{[^}]+\})
206
- \)
207
- /x
208
- [ $1, $2, $3 ]
209
- end
210
-
211
- assert_in_delta(lng.to_f, 10.00, 0.000001)
212
- assert_in_delta(lat.to_f, 10.01, 0.000001)
213
- assert_equal(
214
- { "bounceGravity" => 1, "bouncy" => true },
215
- JSON.load(json)
216
- )
217
- end
218
-
219
- def test_to_g_json_point
220
- assert_equal(
221
- { :coordinates => [ 10.0, 10.01, 0 ] },
222
- @point.to_g_json_point
223
- )
224
- end
225
-
226
- def test_to_g_lat_lon_box
227
- assert_equal(
228
- { :east => 5.0, :west => 0.0, :north => 5.0, :south => 0.0},
229
- @polygon.to_g_lat_lon_box
230
- )
231
- end
232
- end
233
-
234
63
  if defined?(Builder::XmlMarkup)
235
64
  def test_to_kml_point
236
65
  out = StringIO.new
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geos-extensions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 7
10
- version: 0.0.7
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - J Smith
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-21 00:00:00 -04:00
19
- default_executable:
18
+ date: 2011-06-27 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description: Extensions for the GEOS library.
@@ -31,25 +30,31 @@ files:
31
30
  - MIT-LICENSE
32
31
  - README.rdoc
33
32
  - Rakefile
33
+ - VERSION
34
+ - app/models/geos/geometry_column.rb
35
+ - app/models/geos/spatial_ref_sys.rb
34
36
  - geos-extensions.gemspec
35
- - lib/active_record_extensions.rb
36
- - lib/active_record_extensions/connection_adapters/postgresql_adapter.rb
37
- - lib/active_record_extensions/geometry_columns.rb
38
- - lib/active_record_extensions/geospatial_scopes.rb
39
37
  - lib/geos-extensions.rb
38
+ - lib/geos/active_record_extensions.rb
39
+ - lib/geos/active_record_extensions/connection_adapters/postgresql_adapter.rb
40
+ - lib/geos/active_record_extensions/geometry_columns.rb
41
+ - lib/geos/active_record_extensions/geospatial_scopes.rb
42
+ - lib/geos/geos_helper.rb
43
+ - lib/geos/google_maps.rb
44
+ - lib/geos/google_maps/api_2.rb
45
+ - lib/geos/google_maps/api_3.rb
46
+ - lib/geos/google_maps/polyline_encoder.rb
47
+ - lib/geos/rails/engine.rb
40
48
  - lib/geos_extensions.rb
41
- - lib/geos_helper.rb
42
- - lib/google_maps.rb
43
- - lib/google_maps/polyline_encoder.rb
44
- - rails/railtie.rb
45
- - rails/tasks/test.rake
49
+ - lib/tasks/test.rake
46
50
  - test/fixtures/foos.yml
47
51
  - test/geometry_columns_test.rb
48
52
  - test/geospatial_scopes_test.rb
53
+ - test/google_maps_api_2_test.rb
54
+ - test/google_maps_api_3_test.rb
49
55
  - test/reader_test.rb
50
56
  - test/test_helper.rb
51
57
  - test/writer_test.rb
52
- has_rdoc: true
53
58
  homepage: http://github.com/zoocasa/geos-extensions
54
59
  licenses: []
55
60
 
@@ -79,13 +84,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
84
  requirements: []
80
85
 
81
86
  rubyforge_project:
82
- rubygems_version: 1.6.2
87
+ rubygems_version: 1.7.2
83
88
  signing_key:
84
89
  specification_version: 3
85
90
  summary: Extensions for the GEOS library.
86
- test_files:
87
- - test/geometry_columns_test.rb
88
- - test/geospatial_scopes_test.rb
89
- - test/reader_test.rb
90
- - test/test_helper.rb
91
- - test/writer_test.rb
91
+ test_files: []
92
+
@@ -1,8 +0,0 @@
1
-
2
- module Geos
3
- module ActiveRecord
4
- autoload :GeometryColumns, File.join(GEOS_EXTENSIONS_BASE, %w{ active_record_extensions geometry_columns })
5
- autoload :GeospatialScopes, File.join(GEOS_EXTENSIONS_BASE, %w{ active_record_extensions geospatial_scopes })
6
- end
7
- end
8
-
data/lib/geos_helper.rb DELETED
@@ -1,51 +0,0 @@
1
-
2
- module Geos::Helper
3
- JS_ESCAPE_MAP = {
4
- '\\' => '\\\\',
5
- '</' => '<\/',
6
- "\r\n" => '\n',
7
- "\n" => '\n',
8
- "\r" => '\n',
9
- '"' => '\\"',
10
- "'" => "\\'"
11
- }
12
-
13
- # Escape carrier returns and single and double quotes for JavaScript
14
- # segments. Borrowed from ActiveSupport.
15
- def self.escape_javascript(javascript) #:nodoc:
16
- if javascript
17
- javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { JS_ESCAPE_MAP[$1] }
18
- else
19
- ''
20
- end
21
- end
22
-
23
- def self.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = false)
24
- if first_letter_in_uppercase
25
- lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
26
- else
27
- lower_case_and_underscored_word.to_s[0..0].downcase + camelize(lower_case_and_underscored_word, true)[1..-1]
28
- end
29
- end
30
-
31
- def self.xml_options(*args) #:nodoc:
32
- xml = if Builder::XmlMarkup === args.first
33
- args.first
34
- else
35
- Builder::XmlMarkup.new(:indent => 4)
36
- end
37
-
38
- options = if Hash === args.last
39
- args.last
40
- else
41
- Hash.new
42
- end
43
-
44
- [ xml, options ]
45
- end
46
-
47
- def self.number_with_precision(number, precision = 6)
48
- rounded_number = (Float(number) * (10 ** precision)).round.to_f / 10 ** precision
49
- "%01.#{precision}f" % rounded_number
50
- end
51
- end
data/lib/google_maps.rb DELETED
@@ -1,7 +0,0 @@
1
-
2
- module Geos
3
- module GoogleMaps
4
- autoload :PolylineEncoder, File.join(GEOS_EXTENSIONS_BASE, *%w{ google_maps polyline_encoder })
5
- end
6
- end
7
-
data/rails/railtie.rb DELETED
@@ -1,11 +0,0 @@
1
-
2
- require "rails/railtie"
3
-
4
- module Geos
5
- class Railtie < ::Rails::Railtie
6
- rake_tasks do
7
- load File.join(File.dirname(__FILE__), %w{ tasks test.rake })
8
- end
9
- end
10
- end
11
-