geos-extensions 0.1.2 → 0.1.3

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -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.2"
8
+ s.version = "0.1.3"
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-11}
12
+ s.date = %q{2011-07-12}
13
13
  s.description = %q{Extensions for the GEOS library.}
14
14
  s.email = %q{code@zoocasa.com}
15
15
  s.extra_rdoc_files = [
@@ -235,7 +235,7 @@ module Geos
235
235
  end
236
236
  end
237
237
 
238
- def assert_arguments_length(args, min, max)
238
+ def assert_arguments_length(args, min, max = (1.0 / 0.0))
239
239
  raise ArgumentError.new("wrong number of arguments (#{args.length} for #{min}-#{max})") unless
240
240
  args.length.between?(min, max)
241
241
  end
@@ -270,6 +270,19 @@ module Geos
270
270
  ]
271
271
  }
272
272
  })
273
+
274
+ send(SCOPE_METHOD, :st_geometry_type, lambda { |*args|
275
+ assert_arguments_length(args, 1)
276
+ options = args.extract_options!
277
+ types = args
278
+
279
+ {
280
+ :conditions => [
281
+ "#{build_function_call('GeometryType', nil, options)} IN (?)",
282
+ types
283
+ ]
284
+ }
285
+ })
273
286
  end
274
287
 
275
288
  ZERO_ARGUMENT_MEASUREMENTS.each do |measurement|
@@ -1,6 +1,30 @@
1
1
 
2
2
  module Geos::GoogleMaps::Api2
3
3
  module Geometry
4
+ # Spit out Google's JSON geocoder Point format. The extra 0 is added
5
+ # on as Google's format seems to like including the Z coordinate.
6
+ def to_g_json_point_api2
7
+ {
8
+ :coordinates => (self.centroid.to_a << 0)
9
+ }
10
+ end
11
+
12
+ # Spit out Google's JSON geocoder ExtendedData LatLonBox format.
13
+ def to_g_lat_lon_box_api2
14
+ {
15
+ :north => self.north,
16
+ :east => self.east,
17
+ :south => self.south,
18
+ :west => self.west
19
+ }
20
+ end
21
+
22
+ # Spit out Google's toUrlValue format.
23
+ def to_g_url_value_api2(precision = 6)
24
+ c = self.centroid
25
+ "#{Geos::Helper.number_with_precision(c.lat, precision)},#{Geos::Helper.number_with_precision(c.lng, precision)}"
26
+ end
27
+
4
28
  # Returns a new GLatLngBounds object with the proper GLatLngs in place
5
29
  # for determining the geometry bounds.
6
30
  def to_g_lat_lng_bounds_api2(options = {})
@@ -15,7 +39,7 @@ module Geos::GoogleMaps::Api2
15
39
 
16
40
  # Returns a String in Google Maps' GLatLngBounds#toString() format.
17
41
  def to_g_lat_lng_bounds_string_api2(precision = 10)
18
- "((#{self.lower_left.to_g_url_value_api2(precision)}), (#{self.upper_right.to_g_url_value_api2(precision)}))"
42
+ "((#{self.lower_left.to_g_url_value(precision)}), (#{self.upper_right.to_g_url_value(precision)}))"
19
43
  end
20
44
 
21
45
  # Returns a new GPolyline.
@@ -26,15 +26,44 @@ module Geos::GoogleMaps
26
26
  end
27
27
 
28
28
  module Api3::Geometry
29
+ # Spit out Google's JSON geocoder Point format. The extra 0 is added
30
+ # on as Google's format seems to like including the Z coordinate.
31
+ def to_g_json_point_api3
32
+ {
33
+ :coordinates => (self.centroid.to_a << 0)
34
+ }
35
+ end
36
+
37
+ # Spit out Google's JSON geocoder ExtendedData LatLonBox format.
38
+ def to_g_lat_lon_box_api3
39
+ {
40
+ :north => self.north,
41
+ :east => self.east,
42
+ :south => self.south,
43
+ :west => self.west
44
+ }
45
+ end
46
+
47
+ # Spit out Google's toUrlValue format.
48
+ def to_g_url_value_api3(precision = 6)
49
+ c = self.centroid
50
+ "#{Geos::Helper.number_with_precision(c.lat, precision)},#{Geos::Helper.number_with_precision(c.lng, precision)}"
51
+ end
52
+
29
53
  # Returns a new LatLngBounds object with the proper LatLngs in place
30
54
  # for determining the geometry bounds.
31
55
  def to_g_lat_lng_bounds_api3(options = {})
32
56
  "new google.maps.LatLngBounds(#{self.lower_left.to_g_lat_lng_api3(options)}, #{self.upper_right.to_g_lat_lng_api3(options)})"
33
57
  end
34
58
 
59
+ # Returns a bounds parameter for the Google Maps API 3 geocoder service.
60
+ def to_g_geocoder_bounds_api3(precision = 6)
61
+ "#{self.lower_left.to_g_url_value_api3(precision)}|#{self.upper_right.to_g_url_value_api3(precision)}"
62
+ end
63
+
35
64
  # Returns a String in Google Maps' LatLngBounds#toString() format.
36
65
  def to_g_lat_lng_bounds_string_api3(precision = 10)
37
- "((#{self.lower_left.to_g_url_value_api3(precision)}), (#{self.upper_right.to_g_url_value_api3(precision)}))"
66
+ "((#{self.lower_left.to_g_url_value(precision)}), (#{self.upper_right.to_g_url_value(precision)}))"
38
67
  end
39
68
 
40
69
  # Returns a new Polyline.
@@ -295,30 +295,6 @@ module Geos
295
295
  alias :w :left
296
296
  alias :west :left
297
297
 
298
- # Spit out Google's JSON geocoder Point format. The extra 0 is added
299
- # on as Google's format seems to like including the Z coordinate.
300
- def to_g_json_point
301
- {
302
- :coordinates => (self.centroid.to_a << 0)
303
- }
304
- end
305
-
306
- # Spit out Google's JSON geocoder ExtendedData LatLonBox format.
307
- def to_g_lat_lon_box
308
- {
309
- :north => self.north,
310
- :east => self.east,
311
- :south => self.south,
312
- :west => self.west
313
- }
314
- end
315
-
316
- # Spit out Google's toUrlValue format.
317
- def to_g_url_value(precision = 6)
318
- c = self.centroid
319
- "#{Geos::Helper.number_with_precision(c.lat, precision)},#{Geos::Helper.number_with_precision(c.lng, precision)}"
320
- end
321
-
322
298
  # Spits out a bounding box the way Flickr likes it. You can set the
323
299
  # precision of the rounding using the :precision option. In order to
324
300
  # ensure that the box is indeed a box and not merely a point, the
@@ -67,6 +67,12 @@ if ENV['TEST_ACTIVERECORD']
67
67
  ids_tester(:st_dwithin, [ 'POINT(5 5)', 10 ], [ 1, 2, 3 ])
68
68
  end
69
69
 
70
+ def test_geometry_type
71
+ ids_tester(:st_geometry_type, 'ST_Point', [ 1, 2 ])
72
+ ids_tester(:st_geometry_type, [ 'ST_Point', 'ST_Polygon' ], [ 1, 2, 3 ])
73
+ ids_tester(:st_geometry_type, [ 'ST_MultiLineString' ], [])
74
+ end
75
+
70
76
  def test_allow_null
71
77
  begin
72
78
  foo = Foo.create(:name => 'four')
@@ -23,6 +23,11 @@ class GoogleMapsApi2Tests < Test::Unit::TestCase
23
23
  assert_equal("new GLatLng(10.01, 10.0)", @point.to_g_lat_lng(:short_class => true))
24
24
  end
25
25
 
26
+ def test_to_g_lat_lng_bounds_string
27
+ assert_equal('((10.0100000000,10.0000000000), (10.0100000000,10.0000000000))', @point.to_g_lat_lng_bounds_string)
28
+ assert_equal('((0.0000000000,0.0000000000), (5.0000000000,5.0000000000))', @polygon.to_g_lat_lng_bounds_string)
29
+ end
30
+
26
31
  def test_to_jsonable
27
32
  assert_equal({
28
33
  :type => "point",
@@ -23,6 +23,16 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
23
23
  assert_equal("new google.maps.LatLng(10.01, 10.0, true)", @point.to_g_lat_lng(:no_wrap => true))
24
24
  end
25
25
 
26
+ def test_to_g_lat_lng_bounds_string
27
+ assert_equal('((10.0100000000,10.0000000000), (10.0100000000,10.0000000000))', @point.to_g_lat_lng_bounds_string)
28
+ assert_equal('((0.0000000000,0.0000000000), (5.0000000000,5.0000000000))', @polygon.to_g_lat_lng_bounds_string)
29
+ end
30
+
31
+ def test_to_g_geocoder_bounds_api3
32
+ assert_equal('10.010000,10.000000|10.010000,10.000000', @point.to_g_geocoder_bounds)
33
+ assert_equal('0.000000,0.000000|5.000000,5.000000', @polygon.to_g_geocoder_bounds)
34
+ end
35
+
26
36
  def test_to_jsonable
27
37
  assert_equal({
28
38
  :type => "point",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geos-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-11 00:00:00.000000000Z
12
+ date: 2011-07-12 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Extensions for the GEOS library.
15
15
  email: code@zoocasa.com