rgeo/activerecord-postgis-adapter

Find all records containing a point within a given polygon

Closed this issue · 1 comments

I'm new to rgeo but looking to do something that I thought would be a little easier to find! Appreciate the help of the community, in advance. I'm using rails 4.2.

I have a rails model (MyModel) that has a postgis column "point" column called latlon.

I'm looking to find all MyModel records that have a latlon point within a given polygon.

I'm creating a polygon from a linestring without issue like this:

factory = RGeo::Geographic.spherical_factory(:srid => 4326)
a = []
points = params[:polygon]
points.each do |point|
a << factory.point(point[0],point[1])
end
linestring = factory.line_string(a)
poly = factory.polygon(linestring)
What I would now like to get some help with is crafting the query that will find all MyModel instances that have a latlon point within this given polygon.

Hi !

This kind of question should be asked on StackOverflow or similar. This is not an issue about the gem.
Moreover, there are already answers about this on SO.