public void run() throws ParseException { GeometryFactory fact = new GeometryFactory(); WKTReader wktRdr = new WKTReader(fact); String wktA = "POLYGON((40 100, 40 20, 120 20, 120 100, 40 100))"; String wktB = "LINESTRING(20 80, 80 60, 100 140)"; Geometry A = wktRdr.read(wktA); Geometry B = wktRdr.read(wktB); Geometry C = A.intersection(B); System.out.println("A = " + A); System.out.println("B = " + B); System.out.println("A intersection B = " + C); System.out.println("A relate C = " + A.relate(B)); }
/** * Returns a geometric object representing the Point set intersection of two geometries. * * @param node1 xml element containing gml object(s) * @param node2 xml element containing gml object(s) * @return intersection geometry as a gml element * @throws QueryException query exception */ @Deterministic public ANode intersection(final ANode node1, final ANode node2) throws QueryException { final Geometry geo1 = checkGeo(node1); final Geometry geo2 = checkGeo(node2); return gmlWriter(geo1.intersection(geo2)); }