Determine if point is within bounding box

D

Daniel Berger

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
 
P

Phrogz

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top