- # merge two conditions
- def cond_merge(a, b)
- if a and b
- a_str = a.shift
- b_str = b.shift
- return [ a_str + " AND " + b_str ] + a + b
- elsif a
- return a
- else b
- return b
- end
- end
-
- ##
- # if a bounding box was specified then parse it and do some sanity
- # checks. this is mostly the same as the map call, but without the
- # area restriction.
- def conditions_bbox(bbox)
- unless bbox.nil?
- raise OSM::APIBadUserInput.new("Bounding box should be min_lon,min_lat,max_lon,max_lat") unless bbox.count(',') == 3
- bbox = sanitise_boundaries(bbox.split(/,/))
- raise OSM::APIBadUserInput.new("Minimum longitude should be less than maximum.") unless bbox[0] <= bbox[2]
- raise OSM::APIBadUserInput.new("Minimum latitude should be less than maximum.") unless bbox[1] <= bbox[3]
- return ['min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?',
- (bbox[2] * GeoRecord::SCALE).to_i,
- (bbox[0] * GeoRecord::SCALE).to_i,
- (bbox[3] * GeoRecord::SCALE).to_i,
- (bbox[1] * GeoRecord::SCALE).to_i]
+ # if a bounding box was specified do some sanity checks.
+ # restrict changesets to those enclosed by a bounding box
+ # we need to return both the changesets and the bounding box
+ def conditions_bbox(changesets, bbox)
+ if bbox
+ bbox.check_boundaries
+ bbox = bbox.to_scaled
+ return changesets.where("min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?",
+ bbox.max_lon.to_i, bbox.min_lon.to_i,
+ bbox.max_lat.to_i, bbox.min_lat.to_i)