Skip to content

Instantly share code, notes, and snippets.

@josephwegner
Last active August 29, 2015 14:01
Show Gist options
  • Save josephwegner/4582ee8faa303c57c94b to your computer and use it in GitHub Desktop.
Save josephwegner/4582ee8faa303c57c94b to your computer and use it in GitHub Desktop.
A method for generating geofences

Given a list of coordinates, I need to generate a (shorter) list of coordinates that, when connected, will create a geographical fence that contains all of the remaining coordinates.

  1. Find the relative center of all the points
  2. Sort all points by distance from center, descending. We will call this list allPoints.
  3. Create a new empty list called boundaries
  4. Iterate through allPoints, starting from the greatest distance, following this process:
  5. Check if the point is contained in the geofence defined by boundaries. If it is, skip this point. If not, continue.
  6. Insert the coordinate into boundaries.
  7. Sort boundaries so that each point is the shortest possible distance from its surrounding points (yes, this sort will happen a lot of times)
  8. boundaries is now your geofence defintion, and will contain all coordinates in allPoints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment