public int getDimension() { int dimension = Dimension.FALSE; for (int i = 0; i < geometries.length; i++) { dimension = Math.max(dimension, geometries[i].getDimension()); } return dimension; }
private static int resultDimension(int opCode, Geometry g0, Geometry g1) { int dim0 = g0.getDimension(); int dim1 = g1.getDimension(); int resultDimension = -1; switch (opCode) { case INTERSECTION: resultDimension = Math.min(dim0, dim1); break; case UNION: resultDimension = Math.max(dim0, dim1); break; case DIFFERENCE: resultDimension = dim0; break; case SYMDIFFERENCE: /** * This result is chosen because * <pre> * SymDiff = Union(Diff(A, B), Diff(B, A) * </pre> * and Union has the dimension of the highest-dimension argument. */ resultDimension = Math.max(dim0, dim1); break; } return resultDimension; } }
/** * Finds the index of the "most polygonal" input geometry. * This optimizes the computation of the best-fit plane, * since it is cached only for the left-hand geometry. * * @return the index of the most polygonal geometry */ private int mostPolygonalIndex() { int dim0 = geom[0].getDimension(); int dim1 = geom[1].getDimension(); if (dim0 >= 2 && dim1 >= 2) { if (geom[0].getNumPoints() > geom[1].getNumPoints()) return 0; return 1; } // no more than one is dim 2 if (dim0 >= 2) return 0; if (dim1 >= 2) return 1; // both dim <= 1 - don't flip return 0; }
private void checkExpectedEmpty() { // can't check areal features if (input.getDimension() >= 2) return; // can't check positive distances if (distance > 0.0) return; // at this point can expect an empty result if (! result.isEmpty()) { isValid = false; errorMsg = "Result is non-empty"; errorIndicator = result; } report("ExpectedEmpty"); }
if (geom.getDimension() == 1) return false; if (geom.getDimension() == 2 && prepLine.isAnyTargetComponentInTest(geom)) return true; if (geom.getDimension() == 0) return isAnyTestPointInTarget(geom);
/** * Tests whether this geometry overlaps the * specified geometry. * <p> * The <code>overlaps</code> predicate has the following equivalent definitions: * <ul> * <li>The geometries have at least one point each not shared by the other * (or equivalently neither covers the other), * they have the same dimension, * and the intersection of the interiors of the two geometries has * the same dimension as the geometries themselves. * <li>The DE-9IM Intersection Matrix for the two geometries matches * <code>[T*T***T**]</code> (for two points or two surfaces) * or <code>[1*T***T**]</code> (for two curves) * </ul> * If the geometries are of different dimension this predicate returns <code>false</code>. * *@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 overlap. */ public boolean overlaps(Geometry g) { // short-circuit test if (! getEnvelopeInternal().intersects(g.getEnvelopeInternal())) return false; return relate(g).isOverlaps(getDimension(), g.getDimension()); }
/** * Tests whether this geometry touches the * argument geometry. * <p> * The <code>touches</code> predicate has the following equivalent definitions: * <ul> * <li>The geometries have at least one point in common, but their interiors do not intersect. * <li>The DE-9IM Intersection Matrix for the two geometries matches * at least one of the following patterns * <ul> * <li><code>[FT*******]</code> * <li><code>[F**T*****]</code> * <li><code>[F***T****]</code> * </ul> * </ul> * If both geometries have dimension 0, this predicate returns <code>false</code>. * * *@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 touch; * Returns <code>false</code> if both <code>Geometry</code>s are points */ public boolean touches(Geometry g) { // short-circuit test if (! getEnvelopeInternal().intersects(g.getEnvelopeInternal())) return false; return relate(g).isTouches(getDimension(), g.getDimension()); }
/** * 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()); }
return relate(g).isEquals(getDimension(), g.getDimension());
/** * If the Geometries are disjoint, we need to enter their dimension and * boundary dimension in the Ext rows in the IM */ private void computeDisjointIM(IntersectionMatrix im) { Geometry ga = arg[0].getGeometry(); if (! ga.isEmpty()) { im.set(Location.INTERIOR, Location.EXTERIOR, ga.getDimension()); im.set(Location.BOUNDARY, Location.EXTERIOR, ga.getBoundaryDimension()); } Geometry gb = arg[1].getGeometry(); if (! gb.isEmpty()) { im.set(Location.EXTERIOR, Location.INTERIOR, gb.getDimension()); im.set(Location.EXTERIOR, Location.BOUNDARY, gb.getBoundaryDimension()); } }
if (geom.getDimension() == 2) {
/** * Label an isolated edge of a graph with its relationship to the target geometry. * If the target has dim 2 or 1, the edge can either be in the interior or the exterior. * If the target has dim 0, the edge must be in the exterior */ private void labelIsolatedEdge(Edge e, int targetIndex, Geometry target) { // this won't work for GeometryCollections with both dim 2 and 1 geoms if ( target.getDimension() > 0) { // since edge is not in boundary, may not need the full generality of PointLocator? // Possibly should use ptInArea locator instead? We probably know here // that the edge does not touch the bdy of the target Geometry int loc = ptLocator.locate(e.getCoordinate(), target); e.getLabel().setAllLocations(targetIndex, loc); } else { e.getLabel().setAllLocations(targetIndex, Location.EXTERIOR); } //System.out.println(e.getLabel()); }
private Geometry reducePointwise(Geometry geom) { GeometryEditor geomEdit; if (changePrecisionModel) { GeometryFactory newFactory = createFactory(geom.getFactory(), targetPM); geomEdit = new GeometryEditor(newFactory); } else // don't change geometry factory geomEdit = new GeometryEditor(); /** * For polygonal geometries, collapses are always removed, in order * to produce correct topology */ boolean finalRemoveCollapsed = removeCollapsed; if (geom.getDimension() >= 2) finalRemoveCollapsed = true; Geometry reduceGeom = geomEdit.edit(geom, new PrecisionReducerCoordinateOperation(targetPM, finalRemoveCollapsed)); return reduceGeom; }
/** * Computes an interior point of this <code>Geometry</code>. * An interior point is guaranteed to lie in the interior of the Geometry, * if it possible to calculate such a point exactly. Otherwise, * the point may lie on the boundary of the geometry. * <p> * The interior point of an empty geometry is <code>POINT EMPTY</code>. * * @return a {@link Point} which is in the interior of this Geometry */ public Point getInteriorPoint() { if (isEmpty()) return factory.createPoint((Coordinate) null); Coordinate interiorPt = null; int dim = getDimension(); if (dim == 0) { InteriorPointPoint intPt = new InteriorPointPoint(this); interiorPt = intPt.getInteriorPoint(); } else if (dim == 1) { InteriorPointLine intPt = new InteriorPointLine(this); interiorPt = intPt.getInteriorPoint(); } else { InteriorPointArea intPt = new InteriorPointArea(this); interiorPt = intPt.getInteriorPoint(); } return createPointFromInternalCoord(interiorPt, this); }
private void computeProperIntersectionIM(SegmentIntersector intersector, IntersectionMatrix im) int dimA = arg[0].getGeometry().getDimension(); int dimB = arg[1].getGeometry().getDimension(); boolean hasProper = intersector.hasProperIntersection(); boolean hasProperInterior = intersector.hasProperInteriorIntersection();
/** * @param geometry Geometry instance * @return Geometry dimension */ public static Integer getDimension(Geometry geometry) { if(geometry==null) { return null; } return geometry.getDimension(); } }
return factory.createPoint((Coordinate) null); Coordinate centPt = null; int dim = getDimension(); if (dim == 0) { CentroidPoint cent = new CentroidPoint();
private void feedDim(Geometry geometry) { final int geomDim = geometry.getDimension(); maxDim = Math.max(maxDim, geomDim); minDim = Math.min(minDim, geomDim); }
&& geom.getDimension() == 0) { boolean isAnyInTargetInterior = isAnyTestComponentInTargetInterior(geom); return isAnyInTargetInterior;
public int getDimension() { int dimension = Dimension.FALSE; final int n = getNumGeometries(); for (int i = 0; i < n; i++) { dimension = Math.max(dimension, getGeometryN(i).getDimension()); } return dimension; }