Skip to content

Instantly share code, notes, and snippets.

@efwe
Created January 7, 2016 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efwe/675f2d2d56470933aaa5 to your computer and use it in GitHub Desktop.
Save efwe/675f2d2d56470933aaa5 to your computer and use it in GitHub Desktop.
def hull_for(min_distance, max_distance)
client = TrackPoint.mongo_client
points = []
client.command({geoNear: 'track_points', near: [20.459423, 50.799929] , spherical: true, num: 15000, minDistance: min_distance, maxDistance: max_distance, distanceMultiplier: EARTH_RADIUS}).each { |document|
document['results'].each do |point|
points << point['obj']['location']
end
}
result = []
if points.empty?
Rails.logger.warn 'no hull for no points - returning empty hull[]'
else
hull_polygon = HullCalc.convex_hull points
Rails.logger.info "calculated hull polygon with #{hull_polygon.size} points from a total of #{points.size} points"
result = hull_polygon
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment