Joule provides implementation of a spatial Index based on the Quad Tree data structure and algorithm. The search area is divided in to rectangle and thus the world is flattened from a sphere in to a rectangle spatial index.
This feature is provided as a service which can be embedded within custom processors and has its own DSL.
DSL Example
The below example creates a search tree of the world as flattened rectangle.
spatial index:
top left coordinates: [-180f,-90f]
width: 360
area: 64800
max levels: 24
preferred max elements: 50
Attributes
API Example
This example demonstrates how to query initialise the spatial index and query it thereafter within a custom processor.
privateQuadTree<GeoFence> geoFenceSearchTree;@Overridepublicvoidinitialize(Properties prop) throws ProcessorException { super.initialize(prop);geoFenceSearchTree.initialise();// Other custom initialization}/*** Query the geoFenceSearchTree with passed location information ** @param event* @param entityLatitude* @param entityLongitude*/private GeoTrackingInfo queryGeospace(final StreamEvent event, final double entityLatitude, final double entityLongitude){
// Perform geofence searchCollection<GeoFence> foundGeoFences =geoFenceSearchTree.query(newTuple<>(entityLatitude, entityLongitude));Object trackingKey =event.getValue(trackingEventKey);// Update stateful trackingGeoTrackingInfo info =state.get(trackingKey);info.setCurrentLatLng(entityLatitude, entityLongitude,event.getEventTime());info.setCurrentGeofenceIds(foundGeoFences);return info; }/*** Set QuadTree for processor** @param geoFenceSearchTree*/@JsonProperty(value ="spatial index")publicvoidsetGeoFenceSearchTree(QuadTree<GeoFence> geoFenceSearchTree) {this.geoFenceSearchTree= geoFenceSearchTree;}