public static String relate(Geometry arg0, Geometry arg1) { if (arg0 == null || arg1 == null) return null; Geometry _this = arg0; return _this.relate(arg1).toString(); }
public static SpatialRelation intersectionMatrixToSpatialRelation(IntersectionMatrix matrix) { //As indicated in SpatialRelation javadocs, Spatial4j CONTAINS & WITHIN are // OGC's COVERS & COVEREDBY if (matrix.isCovers()) return SpatialRelation.CONTAINS; else if (matrix.isCoveredBy()) return SpatialRelation.WITHIN; else if (matrix.isDisjoint()) return SpatialRelation.DISJOINT; return SpatialRelation.INTERSECTS; }
/** * Returns <code>true</code> if this <code>IntersectionMatrix</code> is * FT*******, F**T***** or F***T****. * *@param dimensionOfGeometryA the dimension of the first <code>Geometry</code> *@param dimensionOfGeometryB the dimension of the second <code>Geometry</code> *@return <code>true</code> if the two <code>Geometry</code> * s related by this <code>IntersectionMatrix</code> touch; Returns false * if both <code>Geometry</code>s are points. */ public boolean isTouches(int dimensionOfGeometryA, int dimensionOfGeometryB) { if (dimensionOfGeometryA > dimensionOfGeometryB) { //no need to get transpose because pattern matrix is symmetrical return isTouches(dimensionOfGeometryB, dimensionOfGeometryA); } if ((dimensionOfGeometryA == Dimension.A && dimensionOfGeometryB == Dimension.A) || (dimensionOfGeometryA == Dimension.L && dimensionOfGeometryB == Dimension.L) || (dimensionOfGeometryA == Dimension.L && dimensionOfGeometryB == Dimension.A) || (dimensionOfGeometryA == Dimension.P && dimensionOfGeometryB == Dimension.A) || (dimensionOfGeometryA == Dimension.P && dimensionOfGeometryB == Dimension.L)) { return matrix[Location.INTERIOR][Location.INTERIOR] == Dimension.FALSE && (isTrue(matrix[Location.INTERIOR][Location.BOUNDARY]) || isTrue(matrix[Location.BOUNDARY][Location.INTERIOR]) || isTrue(matrix[Location.BOUNDARY][Location.BOUNDARY])); } return false; }
/** * Tests if each of the actual dimension symbols in a matrix string satisfies the * corresponding required dimension symbol in a pattern string. * *@param actualDimensionSymbols nine dimension symbols to validate. * Possible values are <code>{T, F, * , 0, 1, 2}</code>. *@param requiredDimensionSymbols nine dimension symbols to validate * against. Possible values are <code>{T, F, * , 0, 1, 2}</code>. *@return true if each of the required dimension * symbols encompass the corresponding actual dimension symbol */ public static boolean matches(String actualDimensionSymbols, String requiredDimensionSymbols) { IntersectionMatrix m = new IntersectionMatrix(actualDimensionSymbols); return m.matches(requiredDimensionSymbols); }
public void runTests() { if (testCase.getGeometry(0) != null && testCase.getGeometry(1) != null) { IntersectionMatrix im = testCase.getIM(); IntersectionMatrix imBA = new IntersectionMatrix(im); imBA.transpose(); setRelateLabel(relateII, im.get(Location.INTERIOR, Location.INTERIOR)); setRelateLabel(relateIB, im.get(Location.INTERIOR, Location.BOUNDARY)); setRelateLabel(relateIE, im.get(Location.INTERIOR, Location.EXTERIOR)); setRelateLabel(relateBI, im.get(Location.BOUNDARY, Location.INTERIOR)); setRelateLabel(relateBB, im.get(Location.BOUNDARY, Location.BOUNDARY)); setRelateLabel(relateBE, im.get(Location.BOUNDARY, Location.EXTERIOR)); setRelateLabel(relateEI, im.get(Location.EXTERIOR, Location.INTERIOR)); setRelateLabel(relateEB, im.get(Location.EXTERIOR, Location.BOUNDARY)); setRelateLabel(relateEE, im.get(Location.EXTERIOR, Location.EXTERIOR)); txtAB.setText(im.toString()); txtBA.setText(imBA.toString()); setPredicate(equalsAB, im.isEquals(dimA, dimB)); setPredicate(disjointAB, im.isDisjoint()); setPredicate(intersectsAB, im.isIntersects()); setPredicate(touchesAB, im.isTouches(dimA, dimB)); setPredicate(crossesAB, im.isCrosses(dimA, dimB)); setPredicate(withinAB, im.isWithin()); setPredicate(containsAB, im.isContains()); setPredicate(overlapsAB, im.isOverlaps(dimA, dimB)); setPredicate(coversAB, im.isCovers()); setPredicate(coveredByAB, im.isCoveredBy());
public void doPredicates(Geometry a, Geometry b) throws Exception { assertTrue( a.contains(b) == a.relate(b).isContains() ); assertTrue( a.crosses(b) == a.relate(b).isCrosses(a.getDimension(), b.getDimension()) ); assertTrue( a.disjoint(b) == a.relate(b).isDisjoint() ); assertTrue( a.equals(b) == a.relate(b).isEquals(a.getDimension(), b.getDimension()) ); assertTrue( a.intersects(b) == a.relate(b).isIntersects() ); assertTrue( a.overlaps(b) == a.relate(b).isOverlaps(a.getDimension(), b.getDimension()) ); assertTrue( a.touches(b) == a.relate(b).isTouches(a.getDimension(), b.getDimension()) ); assertTrue( a.within(b) == a.relate(b).isWithin() ); }
private void runRectanglePredicates(Geometry rect, Geometry testGeom) { boolean intersectsValue = rect.intersects(testGeom); boolean relateIntersectsValue = rect.relate(testGeom).isIntersects(); boolean intersectsOK = intersectsValue == relateIntersectsValue; boolean containsValue = rect.contains(testGeom); boolean relateContainsValue = rect.relate(testGeom).isContains(); boolean containsOK = containsValue == relateContainsValue; //System.out.println(testGeom); if (! intersectsOK || ! containsOK) { System.out.println(testGeom); } assertTrue(intersectsOK); assertTrue(containsOK); }
public void testToString() throws Exception { IntersectionMatrix i = new IntersectionMatrix(); i.set("012*TF012"); assertEquals("012*TF012", i.toString()); IntersectionMatrix c = new IntersectionMatrix(i); assertEquals("012*TF012", c.toString()); }
public void testTranspose() { IntersectionMatrix x = new IntersectionMatrix("012*TF012"); IntersectionMatrix i = new IntersectionMatrix(x); IntersectionMatrix j = i.transpose(); assertSame(i, j); assertEquals("0*01T12F2", i.toString()); assertEquals("012*TF012", x.toString()); }
public void testIsTouches() { assertTrue((new IntersectionMatrix("FT*******")).isTouches(P,A)); assertTrue((new IntersectionMatrix("FT*******")).isTouches(A,P)); assertTrue(! (new IntersectionMatrix("FT*******")).isTouches(P,P)); }
public void testIsIntersects() { assertTrue(! (new IntersectionMatrix("FF*FF****")).isIntersects()); assertTrue(! (new IntersectionMatrix("FF1FF2T*0")).isIntersects()); assertTrue((new IntersectionMatrix("*F*FF****")).isIntersects()); }
public void testIsOverlaps() { assertTrue((new IntersectionMatrix("2*2***2**")).isOverlaps(P,P)); assertTrue((new IntersectionMatrix("2*2***2**")).isOverlaps(A,A)); assertTrue(! (new IntersectionMatrix("2*2***2**")).isOverlaps(P,A)); assertTrue(! (new IntersectionMatrix("2*2***2**")).isOverlaps(L,L)); assertTrue((new IntersectionMatrix("1*2***2**")).isOverlaps(L,L)); assertTrue(! (new IntersectionMatrix("0FFFFFFF2")).isOverlaps(P,P)); assertTrue(! (new IntersectionMatrix("1FFF0FFF2")).isOverlaps(L,L)); assertTrue(! (new IntersectionMatrix("2FFF1FFF2")).isOverlaps(A,A)); }
public void testIsDisjoint() { assertTrue((new IntersectionMatrix("FF*FF****")).isDisjoint()); assertTrue((new IntersectionMatrix("FF1FF2T*0")).isDisjoint()); assertTrue(! (new IntersectionMatrix("*F*FF****")).isDisjoint()); }
public void testIsContains() { assertTrue(! (new IntersectionMatrix("T0F00F000")).isContains()); assertTrue((new IntersectionMatrix("T00000FF0")).isContains()); }
public void testIsCrosses() { assertTrue((new IntersectionMatrix("TFTFFFFFF")).isCrosses(P,L)); assertTrue(! (new IntersectionMatrix("TFTFFFFFF")).isCrosses(L,P)); assertTrue(! (new IntersectionMatrix("TFFFFFTFF")).isCrosses(P,L)); assertTrue((new IntersectionMatrix("TFFFFFTFF")).isCrosses(L,P)); assertTrue((new IntersectionMatrix("0FFFFFFFF")).isCrosses(L,L)); assertTrue(! (new IntersectionMatrix("1FFFFFFFF")).isCrosses(L,L)); }
/** * Returns whether the elements of this <code>IntersectionMatrix</code> * satisfies the required dimension symbols. * *@param requiredDimensionSymbols nine dimension symbols with which to * compare the elements of this <code>IntersectionMatrix</code>. Possible * values are <code>{T, F, * , 0, 1, 2}</code>. *@return <code>true</code> if this <code>IntersectionMatrix</code> * matches the required dimension symbols */ public boolean matches(String requiredDimensionSymbols) { if (requiredDimensionSymbols.length() != 9) { throw new IllegalArgumentException("Should be length 9: " + requiredDimensionSymbols); } for (int ai = 0; ai < 3; ai++) { for (int bi = 0; bi < 3; bi++) { if (!matches(matrix[ai][bi], requiredDimensionSymbols.charAt(3 * ai + bi))) { return false; } } } return true; }
public void testIsEquals() { assertTrue((new IntersectionMatrix("0FFFFFFF2")).isEquals(P,P)); assertTrue((new IntersectionMatrix("1FFF0FFF2")).isEquals(L,L)); assertTrue((new IntersectionMatrix("2FFF1FFF2")).isEquals(A,A)); assertTrue(! (new IntersectionMatrix("0F0FFFFF2")).isEquals(P,P)); assertTrue( (new IntersectionMatrix("1FFF1FFF2")).isEquals(L,L)); assertTrue(! (new IntersectionMatrix("2FFF1*FF2")).isEquals(A,A)); assertTrue(! (new IntersectionMatrix("0FFFFFFF2")).isEquals(P,L)); assertTrue(! (new IntersectionMatrix("1FFF0FFF2")).isEquals(L,A)); assertTrue(! (new IntersectionMatrix("2FFF1FFF2")).isEquals(A,P)); }
@Override public <P extends C2D> boolean intersects(final Geometry<P> geometry, final Geometry<P> other) { if (geometry.isEmpty() || other.isEmpty()) return Boolean.FALSE; checkCompatibleCRS(geometry, other); if (!envelopeIntersect(geometry, other)) return Boolean.FALSE; RelateOp relateOp = new RelateOp(JTS.to(geometry), JTS.to(other)); return relateOp.getIntersectionMatrix().isIntersects(); }
/** * Tests whether this geometry crosses the * argument geometry. * <p> * The <code>crosses</code> predicate has the following equivalent definitions: * <ul> * <li>The geometries have some but not all interior points in common. * <li>The DE-9IM Intersection Matrix for the two geometries matches * one of the following patterns: * <ul> * <li><code>[T*T******]</code> (for P/L, P/A, and L/A situations) * <li><code>[T*****T**]</code> (for L/P, A/P, and A/L situations) * <li><code>[0********]</code> (for L/L situations) * </ul> * </ul> * For any other combination of dimensions this predicate returns <code>false</code>. * <p> * The SFS defined this predicate only for P/L, P/A, L/L, and L/A situations. * In order to make the relation symmetric, * JTS extends the definition to apply to L/P, A/P and A/L situations as well. * *@param g the <code>Geometry</code> with which to compare this <code>Geometry</code> *@return <code>true</code> if the two <code>Geometry</code>s cross. */ public boolean crosses(Geometry g) { // short-circuit test if (! getEnvelopeInternal().intersects(g.getEnvelopeInternal())) return false; return relate(g).isCrosses(getDimension(), g.getDimension()); }