# Determine if point is within bounding box

Hi,

Using georuby, how would you determine if a given point is within a
given bounding box?

require ‘geo_ruby’

denver = GeoRuby::SimpleFeatures::Point.from_x_y(-105.0, 39.7188)
seattle = GeoRuby::SimpleFeatures::Point.from_x_y(-122.23, 47.547)
boise = GeoRuby::SimpleFeatures::Point.from_x_y(-116.06, 43.53)
kcity = GeoRuby::SimpleFeatures::Point.from_x_y(-94.42, 38.94)

Using the above examples, I would expect boise to be in a bounding box
between denver and seattle, but not kansas city. In theory I’d like to
be able to do something like this:

ls = GeoRuby::SimpleFeatures::LineString.from_points([seattle,
denver], 4326)
ls.include?(boise) # => true
ls.include?(kcity) # => false

I poked around the API a bit, but didn’t see how to do that. Any
suggestions?

Regards,

Dan

On Sep 1, 2:14 pm, Daniel B. [email protected] wrote:

Using georuby, how would you determine if a given point is within a
given bounding box?

I’ve never used GeoRuby, but looking at the implementation of
bounding_box for various classes, how about:

# untested

class GeoRuby::SimpleFeatures::Geometry
def point_in_bounds?( point )
min, max = bounding_box
point.x >= min.x && point.x <= max.x &&
point.y >= min.y && point.y <= max.y &&
min.z && point.z >= min.z && point.z <= max.z
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs