public
Description: A plugin for maps-based apps with 1) ActiveRecord extensions for geo-based finders (find within X miles); 2) geocoding through multiple providers with failover; 3) geo distance calculations; 4) IP-based location lookup; 5) before_filter for IP geocoder.; forked from official SVN repo to fix bugs
Homepage: http://geokit.rubyforge.org/
Clone URL: git://github.com/ptb/geokit.git
added bounds test and automatic bounding box on distance query

git-svn-id: http://geokit.rubyforge.org/svn/trunk@39 
9265c765-0211-4c68-b2df-6d1bd6e20c4d
lewisac (author)
Sun Jul 22 02:00:44 -0700 2007
commit  05c685ccbdf6e9fa3d3a9f5b344d2b59f0309895
tree    d1d1fe65de03f5975002f12c5115bc2b4163110b
parent  6fa95ad396d0998d40524f00635c7082698f8be2
...
204
205
206
 
 
207
208
209
...
245
246
247
 
 
 
 
 
 
 
 
 
 
 
 
248
249
250
...
204
205
206
207
208
209
210
211
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
0
@@ -204,6 +204,8 @@ module GeoKit
0
           units = extract_units_from_options(options)
0
           formula = extract_formula_from_options(options)
0
           bounds = extract_bounds_from_options(options)
0
+ # if no explicit bounds were given, try formulating them from the point and distance given
0
+ bounds = formulate_bounds_from_distance(options, origin, units) unless bounds
0
           # Apply select adjustments based upon action.
0
           add_distance_to_select(options, origin, units, formula) if origin && action == :find
0
           # Apply the conditions for a bounding rectangle if applicable
0
@@ -245,6 +247,18 @@ module GeoKit
0
           end
0
         end
0
         
0
+ # If it's a :within query, add a bounding box to improve performance.
0
+ # This only gets called if a :bounds argument is not otherwise supplied.
0
+ def formulate_bounds_from_distance(options, origin, units)
0
+ distance = options[:within] if options.has_key?(:within)
0
+ distance = options[:range].last-(options[:range].exclude_end?? 1 : 0) if options.has_key?(:range)
0
+ if distance
0
+ res=GeoKit::Bounds.from_point_and_radius(origin,distance,:units=>units)
0
+ else
0
+ nil
0
+ end
0
+ end
0
+
0
         # Replace :within, :beyond and :range distance tokens with the appropriate distance
0
         # where clauses. Removes these tokens from the options hash.
0
         def apply_distance_scope(options)
...
399
400
401
 
402
403
404
...
399
400
401
402
403
404
405
0
@@ -399,6 +399,7 @@ module GeoKit
0
       
0
       # returns an instance of bounds which completely encompases the given circle
0
       def from_point_and_radius(point,radius,options={})
0
+ point=LatLng.normalize(point)
0
         p0=point.endpoint(0,radius,options)
0
         p90=point.endpoint(90,radius,options)
0
         p180=point.endpoint(180,radius,options)
...
65
66
67
68
 
 
 
 
 
69
70
71
72
...
65
66
67
 
68
69
70
71
72
73
74
75
76
0
@@ -65,7 +65,11 @@ class BoundsTest < Test::Unit::TestCase #:nodoc: all
0
   end
0
   
0
   def test_creation_from_circle
0
- #TODO -- add this test
0
+ bounds=GeoKit::Bounds.from_point_and_radius([32.939829, -96.951176],2.5)
0
+ inside=GeoKit::LatLng.new 32.9695270000,-96.9901590000
0
+ outside=GeoKit::LatLng.new 32.8951550000,-96.9584440000
0
+ assert bounds.contains?(inside)
0
+ assert !bounds.contains?(outside)
0
   end
0
   
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.