/** * 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); }
PreparedGeometry pg = PreparedGeometryFactory.prepare(geometry);
validArea.getEnvelopeInternal(), DefaultGeographicCRS.WGS84); this.validArea = validArea; this.validaAreaTester = PreparedGeometryFactory.prepare(validArea);
/** * 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); } }
pg = PreparedGeometryFactory.prepare(geom);
PreparedGeometry pg = PreparedGeometryFactory.prepare(geom); if (!pg.contains(centroid)) {
public static boolean covers(Geometry g1, Geometry g2) { PreparedGeometry prepGeom = PreparedGeometryFactory.prepare(g1); return prepGeom.covers(g2); } }
public static boolean intersects(Geometry g1, Geometry g2) { PreparedGeometry prepGeom = PreparedGeometryFactory.prepare(g1); return prepGeom.intersects(g2); } public static boolean contains(Geometry g1, Geometry g2)
public static boolean contains(Geometry g1, Geometry g2) { PreparedGeometry prepGeom = PreparedGeometryFactory.prepare(g1); return prepGeom.contains(g2); } public static boolean containsProperly(Geometry g1, Geometry g2)
private PreparedGeometry getEnvelopeGeometry(GeometryFactory geomFactory) { if (envPrepGeom == null) { Geometry envGeom = geomFactory.toGeometry(env); envPrepGeom = PreparedGeometryFactory.prepare(envGeom); } return envPrepGeom; } }
public static boolean containsProperly(Geometry g1, Geometry g2) { PreparedGeometry prepGeom = PreparedGeometryFactory.prepare(g1); return prepGeom.containsProperly(g2); } public static boolean covers(Geometry g1, Geometry g2)
/** * Inserts a collection of Geometrys into the index. * * @param geoms a collection of Geometrys to insert */ public void insert(Collection geoms) { for (Iterator i = geoms.iterator(); i.hasNext(); ) { Geometry geom = (Geometry) i.next(); index.insert(geom.getEnvelopeInternal(), PreparedGeometryFactory.prepare(geom)); } }
public static void main(String[] args) throws Exception { Geometry circle = createCircle(); PreparedGeometry prepCircle = PreparedGeometryFactory.prepare(circle); int count = 0; int inCount = 0; for (int i = 0; i < MAX_ITER; i++) { count++; Point randPt = createRandomPoint(); if (prepCircle.intersects(randPt)) { inCount++; } //System.out.println("Approximation to PI: " + (4.0 * inCount / (double) count)); } double approxPi = 4.0 * inCount / (double) count; double approxDiffPct = 1.0 - approxPi/Math.PI; System.out.println("Approximation to PI: " + approxPi + " ( % difference from actual = " + 100 * approxDiffPct + " )" ); }
private void checkAllPrepOps(Geometry g1, Geometry g2) { PreparedGeometry prepGeom = PreparedGeometryFactory.prepare(g1); checkIntersects(prepGeom, g2); checkContains(prepGeom, g2); checkContainsProperly(prepGeom, g2); checkCovers(prepGeom, g2); }
public Polygon getResult() { GeometryFactory gf = poly.getFactory(); Polygon shell = gf.createPolygon(poly.getExteriorRing()); PreparedGeometry shellPrep = PreparedGeometryFactory.prepare(shell); List holes = new ArrayList(); for (int i = 0; i < poly.getNumInteriorRing(); i++) { LinearRing hole = poly.getInteriorRingN(i); if (shellPrep.covers(hole)) { holes.add(hole); } } // all holes valid, so return original if (holes.size() == poly.getNumInteriorRing()) return poly; // return new polygon with covered holes only Polygon result = gf.createPolygon(poly.getExteriorRing(), GeometryFactory.toLinearRingArray(holes)); return result; }
public void setup() { Geometry sinePoly = createSineStar(new Coordinate(0, 0), 100000.0, nPts); pg = PreparedGeometryFactory.prepare(sinePoly); g = createSineStar(new Coordinate(10, 10), 100000.0, 100); }
pg = PreparedGeometryFactory.prepare(g);
pg = PreparedGeometryFactory.prepare(g);
pg = PreparedGeometryFactory.prepare(g);
theGeom = PreparedGeometryFactory.prepare(cloned);