Giter Site home page Giter Site logo

fesimplegeoprox's Introduction

README

FeProxiMap is a lightweight collection of user-supplied geographical points which supports fast proximity search by search within a radius or by rectangle.

By "lightweight" and "fast" here, I mean that it's midway between linear search (lightweight but slow: for a reasonable search, this is between 100 and 1000 times faster) and GeoRedis (which is blazingly fast but heavier weight). Also, the documentation on GeoRedis says that its answers are approximate, while these are precisely as exact as LatLng will give.

Makes use of SimpleLatLng by Tyler Coles (also published under the Apache license), so latitude and longitude are represented in that coordinate system.

  • Allows query within circle (radial distance from start point), and rectangle.

  • Lightweight. The two jars (this and SimpleLatLng) together total less than 100K.

  • Handles the poles properly.

  • LIMITATION: Changes to caller's view of the location of objects will not be reflected in search results. At this point, object locations must be held constant (or destroy the proximap and recreate with the new locations)

  • LIMITATION: Persistence is the responsibility of caller.

  • LIMITATION: Shares the limitations of LatLng: specifically it ignores elevation in calculating distance.

  • LIMITATION: Slower than GeoRedis

Performance

Being faster than brute force was pretty much the driving force behind this, so understanding the performance profile is essential: if you don't know its sweet spot, you don't know whether using it is a good idea.

From a sample database with a bit over a million points, the data from a series of requests (see the microbenchmarks in the tests folder for details) show a clear pattern: if the search is "large" enough that it's going to return roughly half the points in the world or more, brute force will be faster. But if the search is of a "reasonable" size (less than half), FeSimpleGeoProx outperforms brute force by a convincing margin.

PerformanceProfile.png

USAGE

Construct an instance of this and give it a collection of GeoObject instances (See GeoObject).
A GeoObject is a set of coordinates (LatLng) and a user-given object.

Example

  1. Obviously, as a prospective user of this, you already have a source (database, file, collection) of geographical objects, in some class you've written, and obviously they all have geographical coordinates.
  2. If needed, create a method to get the location in LatLng for each point
  3. Create a world instance holding those points;
#!java
		List<MapObjectHolder<YourGeographicalPointClass>> mapObjects = new ArrayList<>();
		for (YourGeographicalPointClass point: yourGeographicalObjects) {
			LatLng loc = getLatLngForYourGeographicalPointClass (point);
			mapObjects.add(new MapObjectHolder<YourGeographicalPointClass> (loc, point));
		}
		FeProxiMap<YourGeographicalPointClass> world = new FeProxiMap<YourGeographicalPointClass>(mapObjects);
  1. You're now ready to search. Given: a starting point (given in LatLng) a search radius (given as a double) the units of the radius (example: LengthUnit.MILE)
#!java

      Collection<MapObjectHolder<YourGeographicalPointClass>> pointsInRadius = world.find (start, radius, units);

fesimplegeoprox's People

Contributors

ccperkins avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.