# Determine if point is within bounding box

**URL:** <https://www.ruby-forum.com/t/determine-if-point-is-within-bounding-box/194273>\
**Category:** Ruby\
**Created:** [September 1, 2010, 10:14pm UTC](https://www.ruby-forum.com/t/determine-if-point-is-within-bounding-box/194273 "2010-09-01T22:14:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [September 1, 2010, 10:14pm UTC](https://www.ruby-forum.com/t/determine-if-point-is-within-bounding-box/194273/1 "2010-09-01T22:14:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [September 2, 2010, 5:40am UTC](https://www.ruby-forum.com/t/determine-if-point-is-within-bounding-box/194273/2 "2010-09-02T05:40:26Z")

</div>

On Sep 1, 2:14 pm, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
