/** * Returns the ROI as a JTS {@code Geometry}. * * @return the geometry */ public Geometry getAsGeometry() { return theGeom.getGeometry(); }
/** * Gets a new {@link Shape} representing this ROI. * * @return the shape */ @Override public Shape getAsShape() { return new ShapeWriter().toShape(theGeom.getGeometry()); }
@Override public ROI subtract(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { return new ROIGeometry(theGeom.getGeometry().difference(geom)); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
/** * Returns a new instance which is the exclusive OR of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to add * @return the union as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI exclusiveOr(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { return new ROIGeometry(theGeom.getGeometry().symDifference(geom)); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
/** * Returns a new instance which is the union of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to add * @return the union as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI add(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { Geometry union = geom.union(theGeom.getGeometry()); // Geometry fixed = PRECISE_FACTORY.createGeometry(union); // Coordinate[] coords = fixed.getCoordinates(); // for (Coordinate coord : coords) { // Coordinate cc1 = coord; // PRECISION.makePrecise(cc1); // } // union = fixed; return new ROIGeometry(union); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
/** * Returns a new instance which is the intersection of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to intersect with * @return the intersection as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI intersect(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { Geometry intersect = geom.intersection(theGeom.getGeometry()); // Geometry fixed = PRECISE_FACTORY.createGeometry(intersect); // Coordinate[] coords = fixed.getCoordinates(); // for (Coordinate coord : coords) { // Coordinate cc1 = coord; // PRECISION.makePrecise(cc1); // } // intersect = fixed; return new ROIGeometry(intersect); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
public static Point getRandomPointInGeometry(final PreparedGeometry geometry) { return getRandomPointInEnvelope(p -> geometry.contains(p), geometry.getGeometry().getEnvelopeInternal()); }
/** * Gets the enclosing rectangle of this ROI. * * @return a new rectangle */ @Override public Rectangle getBounds() { Envelope env = theGeom.getGeometry().getEnvelopeInternal(); return new Rectangle((int)env.getMinX(), (int)env.getMinY(), (int)env.getWidth(), (int)env.getHeight()); }
/** * Gets the enclosing double-precision rectangle of this ROI. * * @return a new rectangle */ @Override public Rectangle2D getBounds2D() { Envelope env = theGeom.getGeometry().getEnvelopeInternal(); return new Rectangle2D.Double(env.getMinX(), env.getMinY(), env.getWidth(), env.getHeight()); }
public Rect mbr() { // TODO assumes that shapefile is using WGS84? load(); Rect r = null; for (PreparedGeometry g : geometries) { Coordinate[] v = g.getGeometry().getEnvelope().getCoordinates(); System.out.println(Arrays.toString(v)); Rect rect = new Rect(v[0].y, v[0].x, v[2].y, v[2].x); if (r == null) r = rect; else r = r.add(rect); } return r; }
@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); } } }
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 }
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 { Geometry g = representativeGeom.getGeometry(); g.geometryChanged(); Envelope ePoly = g.getEnvelopeInternal();
/** * Constructor. * * @param sm the {@code SampleModel} used to create tiles * @param configuration rendering hints * @param minX origin X ordinate * @param minY origin Y ordinate * @param width image width * @param height image height * @param geom reference polygonal geometry * @param coordType type of coordinates to use when testing pixel inclusion * (corner or center) */ public VectorBinarizeOpImage(SampleModel sm, Map configuration, int minX, int minY, int width, int height, PreparedGeometry geom, PixelCoordType coordType, final boolean antiAliasing) { super(buildLayout(minX, minY, width, height, sm), configuration, sm, minX, minY, width, height); this.geom = geom; this.shape = new ShapeWriter().toShape(geom.getGeometry()); this.coordType = coordType; this.antiAliasing = antiAliasing; GeometryFactory gf = new GeometryFactory(); testPointCS = new CoordinateSequence2D(1); testPoint = gf.createPoint(testPointCS); testRectCS = new CoordinateSequence2D(5); testRect = gf.createPolygon(gf.createLinearRing(testRectCS), null); }
|| goodnessOfFit(painter, tempTransform, pg) < painter.getLabel().getGoodnessOfFit()) { if(textStyle.flipRotation(pg.getGeometry())) { tempTransform.setTransform(original); setupPointTransform(tempTransform, centroid, textStyle, painter); && glyphs.labelsWithinDistance(transformed, labelItem.getSpaceAround())) || goodnessOfFit(painter, tempTransform, pg) < painter.getLabel().getGoodnessOfFit()) { textStyle.flipRotation(pg.getGeometry()); return false;
/** * Gets an image representation of this ROI using the {@code VectorBinarize} * operation. For an ROI with very large bounds but simple shape(s) the * resulting image has a small memory footprint. * * @return a new image representing this ROI * @see jaitools.media.jai.vectorbinarize.VectorBinarizeDescriptor */ @Override public PlanarImage getAsImage() { if(roiImage == null) { Envelope env = theGeom.getGeometry().getEnvelopeInternal(); int x = (int) Math.floor(env.getMinX()); int y = (int) Math.floor(env.getMinY()); int w = (int) Math.ceil(env.getWidth()); int h = (int) Math.ceil(env.getHeight()); ParameterBlockJAI pb = new ParameterBlockJAI("VectorBinarize"); pb.setParameter("minx", x); pb.setParameter("miny", y); pb.setParameter("width", w); pb.setParameter("height", h); pb.setParameter("geometry", theGeom); pb.setParameter("coordtype", coordType); pb.setParameter("antiAliasing", useAntialiasing); roiImage = JAI.create("VectorBinarize", pb); } return roiImage; }
operation.setBoundsSource(boundsSource); if (boundsGeometry != null) { operation.setGeometryBoundary(boundsGeometry.getGeometry());
/** * Returns a new ROI created by applying the given transform to * this ROI. * * @param at the transform * * @return the new ROI */ @Override public ROI transform(AffineTransform at) { Geometry cloned = (Geometry) theGeom.getGeometry().clone(); cloned.apply(new AffineTransformation(at.getScaleX(), at.getShearX(), at.getTranslateX(), at.getShearY(), at.getScaleY(), at.getTranslateY())); if (useFixedPrecision){ Geometry fixed = PRECISE_FACTORY.createGeometry(cloned); Coordinate[] coords = fixed.getCoordinates(); for (Coordinate coord : coords) { Coordinate precise = coord; PRECISION.makePrecise(precise); } cloned = fixed; } return new ROIGeometry(cloned); }