area
has many coordinates
coordinate
model has two attributes: latitude
and longitude
Is there anyway to refactor this? Right now it works, but it does a kind of n+1 query:
areas.each_with_object([]) do |area, array|
geokit_lat_lngs = area.coordinates.order(sequence: :asc).map do |coordinate|
Geokit::LatLng.new(coordinate.latitude, coordinate.longitude)
end
polygon = Geokit::Polygon.new(geokit_lat_lngs)
point = Geokit::LatLng.new(latitude, longitude)
array << area.id if polygon.contains?(point)
end
Im trying to get all areas
that latitude
and longitude
fall under
Im using the Geokit gem, but happy to switch, if there is something more efficient that I should be doing