AGGeospatialHaversine.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGGeospatialHaversine {
@param
@throws
public static void main(String[] args) throws AllegroGraphException {
AllegroGraphConnection ags = new AllegroGraphConnection();
try {
ags.enable();
} catch (Exception e) {
throw new AllegroGraphException("Server connection problem", e);
}
AllegroGraph ts = ags.renew("geospatialhaversine", AGPaths.TRIPLE_STORES);
ts.registerNamespace("ex","http://example.org/");
GeoExtension geo = ts.getGeoExtension();
GeospatialSubtype subtype = geo.registerLatitudeStripingInMiles(50.0);
geo.addSubtype(subtype);
UPI upiA = geo.encodeUPI(subtype, -122, 37);
UPI upiB = geo.encodeUPI(subtype, -121, 37);
UPI upiC = geo.encodeUPI(subtype, -120, 37);
UPI upiD = geo.encodeUPI(subtype, -121, 36);
UPI upiE = geo.encodeUPI(subtype, -121, 38);
ts.addStatement("!ex:pointA", "!ex:location", upiA);
ts.addStatement("!ex:pointB", "!ex:location", upiB);
ts.addStatement("!ex:pointC", "!ex:location", upiC);
ts.addStatement("!ex:pointD", "!ex:location", upiD);
ts.addStatement("!ex:pointE", "!ex:location", upiE);
AGUtils.indexAllTriplesWithTiming(ts);
Cursor cc = ts.getStatements(null,null,null);
AGUtils.showTriples("All triples:",cc);
cc = geo.getStatementsInHMiles(subtype, "!ex:location", -121, 37, 110, false, false);
AGUtils.showTriples("Triples within a 110 mile radius:",cc);
cc = geo.getStatementsInHMiles(subtype, "!ex:location", -121, 37, 120, false, false);
AGUtils.showTriples("Triples within a 120 mile radius:",cc);
cc = geo.getStatementsInHKm(subtype, "!ex:location", -121, 37, 90, false, false);
AGUtils.showTriples("Triples within a 90 km radius:",cc);
cc = geo.getStatementsInHKm(subtype, "!ex:location", -121, 37, 120, false, false);
AGUtils.showTriples("Triples within a 120 km radius:",cc);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next