Created
January 7, 2016 16:16
-
-
Save efwe/675f2d2d56470933aaa5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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