I need to know if a point is in a polygon or not, in my rails app, in order to to that I wan to use rgeo gem.
To install this geme i folowed the instructions on rgeo git
Then I'm sure that GEOS and Proj4 are properly installed.
I also added this gem 'ffi-geos', no particular reason, only following rgeo doc
Finally I made a test on rails console to check if is working
More info: rails version 5.1.2 ide c9 os ubuntu
if someone has a solution, thanks in advance, I'm also open to use another gem, or whatever, my goal is to solve my point / polygon problem.
You could use Geokit, just include gem 'geokit'
in your Gemfile.
Then you will need to create an array of points, where each point is a Geokit::LatLng
.
For example:
points = []
points << Geokit::LatLng.new("-34.8922513", "-56.1468951")
points << Geokit::LatLng.new("-34.905204", "-56.1848322")
points << Geokit::LatLng.new("-34.9091105", "-56.170756")
polygon = Geokit::Polygon.new(points)
polygon.contains? polygon.centroid #this should return true
Don't worry about whether or not the first point is the same as the last, the new
already takes care of that as it is explained here in the source code.