AGGeospatialPolygons.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGGeospatialPolygons {
@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("geospatialpolygons", AGPaths.TRIPLE_STORES);
ts.registerNamespace("ex","http://example.org/");
GeoExtension geo = ts.getGeoExtension();
GeospatialSubtype subtype = geo.registerCartesianStriping(0,10,0,10,.1);
geo.addSubtype(subtype);
Polygon p1 = new Polygon(4);
p1.setSubject(ts.addPart("!ex:p1").queryAGId());
p1.addVertex(0,0);
p1.addVertex(0,10);
p1.addVertex(6,6);
p1.addVertex(10,0);
p1.setSubtype(subtype);
p1.add(ts);
Polygon p2 = new Polygon(4);
p2.setSubject(ts.addPart("!ex:p2").queryAGId());
p2.addVertex(0,0);
p2.addVertex(0,10);
p2.addVertex(4,4);
p2.addVertex(10,0);
p2.setSubtype(subtype);
p2.add(ts);
Polygon p3 = new Polygon(8);
p3.setSubject(ts.addPart("!ex:p3").queryAGId());
p3.addVertex(0,0);
p3.addVertex(0,10);
p3.addVertex(10,10);
p3.addVertex(6,6);
p3.addVertex(4,6);
p3.addVertex(4,4);
p3.addVertex(6,4);
p3.addVertex(0,10);
p3.setSubtype(subtype);
p3.add(ts);
AGUtils.indexAllTriplesWithTiming(ts);
Cursor cc = ts.getStatements(null,null,null);
AGUtils.showTriples("All triples:",cc);
System.out.println("Is the point (5,5) inside p1? " + p1.pointInside(5,5));
System.out.println("Is the point (5,5) inside p2? " + p2.pointInside(5,5));
System.out.println("Is the point (5,5) inside p3? " + p3.pointInside(5,5));
System.out.println("Is the point (0.5,0.5) inside p3? " + p3.pointInside(0.5,0.5));
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next