GeoNode
Geospatial data structure for location-based spatial entity analysis
Learn what it is
GeoNodePackage location
com.fractalworks.streams.processors.geospatial.structures
Class Definition
class GeoNode<T extends ReferenceData> implements Coordinates, ReferenceData
Constructors
// Default constructor
public GeoNode()
// Create a node with location details and add entity later
public GeoNode(double latitude, double longitude)
// Create a node with location details and a reference data type
public GeoNode(double latitude, double longitude, T entity)
Key Methods
Get coordinates
Tuple<Double, Double> getCoordinates();
Get entity unique key
Object getKey()
Get entity
T getValue()
Example
The example demonstrates using the GeoNode
class to store and query geospatial data.
This example demonstrates how to associate spatial data with entities and efficiently query nearby locations.
Friend class A
Friend
object stores details (ID, name) of a person.GeoNode instances Each
GeoNode<Friend>
links aFriend
to specific geographical coordinates (latitude, longitude).QuadTree The
GeoNode
instances are added to aQuadTree
, which indexes the locations for efficient querying.GeoFence A
GeoFence
is created around a specific location with a radius (2 units).Querying The
QuadTree
is queried forGeoNode
objects within theGeoFence
, returning nearby friends.Display results The nearby friends are printed to the console.
class Friend implements ReferenceData {
Integer id;
String name;
// Implementation
}
Friend bart = new Friend(1, "bart");
Friend billy = new Friend(2, "billy");
Friend cumin = new Friend(3, "cumin");
Friend john = new Friend(4, "john");
Friend stacey = new Friend(5, "stacey");
Friend bambi = new Friend(6, "bambi");
Friend gazza = new Friend(7, "gazza");
Friend kevin = new Friend(8, "kevin");
Friend lora = new Friend(9, "lora");
Friend rodney = new Friend(10, "rodney");
Friend arkan = new Friend(11, "arkan");
GeoNode<Friend>[] friendlocations = new GeoNode[]{
new GeoNode<>(51.456821f, -0.164746f, bart),
new GeoNode<>(51.456821f, -0.164746f, billy),
new GeoNode<>(51.457018f, -0.1622072f, cumin),
new GeoNode<>(51.457018f, -0.1622072f, john),
new GeoNode<>(51.467766f, -0.2987533f, stacey),
new GeoNode<>(51.467766f, -0.2987533f, bambi),
new GeoNode<>(51.467766f, -0.2987533f, gazza),
new GeoNode<>(51.457018f, -0.1622072f, kevin),
new GeoNode<>(51.457018f, -0.1622072f, lora),
new GeoNode<>(51.467766f, -0.2987533f, rodney),
new GeoNode<>(51.456821f, -0.164746f, arkan)
};
// Add friend locations to search tree
QuadTree<GeoNode<Friend>> friendsTree = new QuadTree<>(-180f, -90f, 360, 64800);
Arrays.stream(peoplePoints).forEach(friendsTree::insert);
// Perform a search of entites within a geofence
GeoFence currentLocation = new GeoFence(51.456821f, -0.164746f, 2);
Collection<GeoNode<Friend>> friendsNearby = friendsTree.query(currentLocation);
friendsNearby.forEach(System.out::println);
Last updated
Was this helpful?