/** * Adds an index to this class internally to compute spatial relations faster. In JTS this * is called a {@link org.locationtech.jts.geom.prep.PreparedGeometry}. This * isn't done by default because it takes some time to do the optimization, and it uses more * memory. Calling this method isn't thread-safe so be careful when this is done. If it was * already indexed then nothing happens. */ public void index() { if (preparedGeometry == null) preparedGeometry = PreparedGeometryFactory.prepare(geom); }
@Override public boolean evaluateInternal(Geometry left, Geometry right) { switch (literals) { case BOTH: return cacheValue; case RIGHT: { return rightPreppedGeom.intersects(left); } case LEFT: { return leftPreppedGeom.intersects(right); } default: { return basicEvaluate(left, right); } } }
PreparedGeometry pg = PreparedGeometryFactory.prepare(geometry); Envelope geometryEnvelope = geometry.getEnvelopeInternal(); if (geometryEnvelope.intersects(tileBBox.getEnvelopeInternal()) && pg.intersects(tileBBox)) // geometry partially covers the tile: draw it if (pg.contains(tileBBox)) // geometry fully covers the tile?
protected SpatialRelation relate(Geometry oGeom) { //see http://docs.geotools.org/latest/userguide/library/jts/dim9.html#preparedgeometry if (oGeom instanceof org.locationtech.jts.geom.Point) { if (preparedGeometry != null) return preparedGeometry.disjoint(oGeom) ? SpatialRelation.DISJOINT : SpatialRelation.CONTAINS; return geom.disjoint(oGeom) ? SpatialRelation.DISJOINT : SpatialRelation.CONTAINS; } if (preparedGeometry == null) return intersectionMatrixToSpatialRelation(geom.relate(oGeom)); else if (preparedGeometry.covers(oGeom)) return SpatialRelation.CONTAINS; else if (preparedGeometry.coveredBy(oGeom)) return SpatialRelation.WITHIN; else if (preparedGeometry.intersects(oGeom)) return SpatialRelation.INTERSECTS; return SpatialRelation.DISJOINT; }
@Override public boolean evaluateInternal(Geometry left, Geometry right) { switch (literals) { case BOTH: return cacheValue; case RIGHT: { // if the right contains left then left is within right return rightPreppedGeom.contains(left); } case LEFT: { // since within does not have an optimization with prepared geometries // there is nothing to be gained in this case so use the normal check return basicEvaluate(leftPreppedGeom.getGeometry(), right); } default: { return basicEvaluate(left, right); } } }
public static boolean intersects(Geometry g1, Geometry g2) { PreparedGeometryFactory pgFact = new PreparedGeometryFactory(); PreparedGeometry prepGeom = pgFact.create(g1); return prepGeom.intersects(g2); } public static boolean contains(Geometry g1, Geometry g2)
private boolean preppedEvaluate(PreparedGeometry prepped, Geometry other) { Envelope envLeft = prepped.getGeometry().getEnvelopeInternal(); Envelope envRight = other.getEnvelopeInternal(); if (envRight.intersects(envLeft)) { return prepped.intersects(other); } else { return false; } // Note that this is a pretty permissive logic // if the type has somehow been mis-set (can't happen externally) // then true is returned in all cases }
@Override public boolean evaluateInternal(Geometry left, Geometry right) { switch (literals) { case BOTH: return cacheValue; case RIGHT: { // since it is left contains right there is no // benefit of having a prepared geometry for the right side return basicEvaluate(left, right); } case LEFT: { return leftPreppedGeom.contains(right); } default: { return basicEvaluate(left, right); } } }
< painter.getLabel().getGoodnessOfFit()) { if (textStyle.flipRotation(pg.getGeometry())) { tempTransform.setTransform(original); setupPointTransform(tempTransform, centroid, textStyle, painter); || goodnessOfFit(painter, tempTransform, pg) < painter.getLabel().getGoodnessOfFit()) { textStyle.flipRotation(pg.getGeometry()); return false;
protected AbstractPreparedGeometryFilter(Expression e1, Expression e2) { super(e1, e2); pGeomFac = new PreparedGeometryFactory(); if (e1 != null) setExpression1(e1); if (e2 != null) setExpression2(e2); }
public boolean containsProperly(Geometry g) { // short-circuit test if (! envelopeCovers(g)) return false; return PreparedPolygonContainsProperly.containsProperly(this, g); }
if (representativeGeom.getGeometry() instanceof Point) { return 1.0; if (representativeGeom.getGeometry() instanceof LineString) { return 1.0; if (representativeGeom.getGeometry() instanceof Polygon) { Rectangle2D glyphBounds = painter.getFullLabelBounds(); try { if (representativeGeom.contains(pp)) { count++; Geometry g = representativeGeom.getGeometry(); g.geometryChanged(); Envelope ePoly = g.getEnvelopeInternal();
validArea.getEnvelopeInternal(), DefaultGeographicCRS.WGS84); this.validArea = validArea; this.validaAreaTester = PreparedGeometryFactory.prepare(validArea);
if (validaAreaTester.contains(JTS.toGeometry(geWGS84))) { return geometry;
protected AbstractPreparedGeometryFilter( Expression e1, Expression e2, MatchAction matchAction) { super(e1, e2, matchAction); pGeomFac = new PreparedGeometryFactory(); if (e1 != null) setExpression1(e1); if (e2 != null) setExpression2(e2); }
/** * Stop gap measure to get a ROI that can scale up to massive images, until ROIGeometry gets * fixed to be a good ROIShape replacement * * @param theGeom * @return */ private static ROI getAsROI(Geometry theGeom) { org.locationtech.jts.geom.Envelope env = theGeom.getEnvelopeInternal(); int x = (int) Math.floor(env.getMinX()); int y = (int) Math.floor(env.getMinY()); int w = (int) Math.ceil(env.getMaxX()) - x; int h = (int) Math.ceil(env.getMaxY()) - y; ParameterBlockJAI pb = new ParameterBlockJAI("VectorBinarize"); pb.setParameter("minx", x); pb.setParameter("miny", y); pb.setParameter("width", w); pb.setParameter("height", h); pb.setParameter("geometry", PreparedGeometryFactory.prepare(theGeom)); pb.setParameter("antiAliasing", true); RenderedImage roiImage = JAI.create("VectorBinarize", pb, null); return new ROI(roiImage); } }