public Coordinate getCentre() { return extent.centre(); }
private static Coordinate envelopeCentre(Geometry g) { return g.getEnvelopeInternal().centre(); }
public Point createMidPoint(Envelope bbox, GeometryFactory geometryFactory) { return geometryFactory.createPoint(bbox.centre()); }
/** * Create the OSM map link based on the bounding box of the geometry. * * @param geom the input geometry. * @param withMarker true to place a marker on the center of the BBox. * @return */ public static String generateLink(Geometry geom, boolean withMarker) { if (geom == null) { return null; } Envelope env = geom.getEnvelopeInternal(); StringBuilder sb = new StringBuilder("http://www.openstreetmap.org/?"); sb.append("minlon=").append(env.getMinX()); sb.append("&minlat=").append(env.getMinY()); sb.append("&maxlon=").append(env.getMaxX()); sb.append("&maxlat=").append(env.getMaxY()); if (withMarker) { Coordinate centre = env.centre(); sb.append("&mlat=").append(centre.y); sb.append("&mlon=").append(centre.x); } return sb.toString(); } }
/** * Rotates a geometry by a given angle (in radians) about the center * of the geometry's envelope. * * @param geom Geometry * @param theta Angle * @return The geometry rotated about the center of its envelope */ public static Geometry rotate(Geometry geom, double theta) { if (geom != null) { Coordinate center = geom.getEnvelopeInternal().centre(); return rotate(geom, theta, center.x, center.y); } else { return null; } }
private static AffineTransformation viewportTrans(Envelope srcEnv, Envelope viewEnv) { // works even if W or H are zero, thanks to Java infinity value. double scaleW = viewEnv.getWidth() / srcEnv.getWidth(); double scaleH = viewEnv.getHeight() / srcEnv.getHeight(); // choose minimum scale to ensure source fits viewport double scale = Math.min(scaleW, scaleH); Coordinate centre = srcEnv.centre(); Coordinate viewCentre = viewEnv.centre(); // isotropic scaling AffineTransformation trans = AffineTransformation.scaleInstance(scale, scale, centre.x, centre.y); // translate using envelope centres trans.translate(viewCentre.x - centre.x, viewCentre.y - centre.y); return trans; }
public static Geometry randomLineString(Geometry g, int nPts) { Envelope env = FunctionsUtil.getEnvelopeOrDefault(g); GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g); double width = env.getWidth(); double hgt = env.getHeight(); Coordinate[] pts = new Coordinate[nPts]; for (int i = 0; i < nPts; i++) { double xLen = width * Math.random(); double yLen = hgt * Math.random(); pts[i] = randomPtInRectangleAround(env.centre(), xLen, yLen); } return geomFact.createLineString(pts); }
public @Test void testCollapse() { final Envelope deepestQuadBounds = support.quadBounds(NE, NE, NE, NE); final Envelope point = new Envelope(deepestQuadBounds.centre()); System.err.println(deepestQuadBounds); System.err.println(point); }
if (ga != null) env.expandToInclude(ga.getEnvelopeInternal()); if (gb != null) env.expandToInclude(gb.getEnvelopeInternal()); Coordinate centre = env.centre();
public void setEnvelope(Envelope env) { this.width = env.getWidth(); this.height = env.getHeight(); this.base = new Coordinate(env.getMinX(), env.getMinY()); this.centre = new Coordinate(env.centre()); }
public static Geometry randomRectilinearWalk(Geometry g, int nPts) { Envelope env = FunctionsUtil.getEnvelopeOrDefault(g); GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g); double xLen = env.getWidth(); double yLen = env.getHeight(); Coordinate[] pts = new Coordinate[nPts]; boolean xory = true; for (int i = 0; i < nPts; i++) { Coordinate pt = null; if (i == 0) { pt = randomPtInRectangleAround(env.centre(), xLen, yLen); } else { double dist = xLen * (Math.random() - 0.5); double x = pts[i-1].x; double y = pts[i-1].y; if (xory) { x += dist; } else { y += dist; } // switch orientation xory = ! xory; pt = new Coordinate(x, y); } pts[i] = pt; } return geomFact.createLineString(pts); }
public static Polygon star(Envelope env, int nSeg, GeometryFactory geomFact) { Coordinate[] pts = new Coordinate[nSeg + 1]; Coordinate centre = env.centre(); double len = 0.5 * Math.min(env.getHeight(), env.getWidth()); double angInc = Math.PI + 2 * Math.PI / nSeg; double ang = 0; for (int i = 0; i < nSeg; i++) { double x = centre.x + len * Math.cos(ang); double y = centre.x + len * Math.sin(ang); pts[i] = new Coordinate(x, y); ang += angInc; } pts[nSeg] = new Coordinate(pts[0]); return geomFact.createPolygon(pts); } }
public static MultiPolygon crossedComb(Envelope env, int size, GeometryFactory geomFact) { Polygon comb1 = comb(env, size, geomFact); Coordinate centre = env.centre(); AffineTransformation trans = AffineTransformation.rotationInstance(0.5 * Math.PI, centre.x, centre.y); Polygon comb2 = (Polygon) trans.transform(comb1); MultiPolygon mp = geomFact.createMultiPolygon(new Polygon[] { comb1, comb2 } ); return mp; }
public @Test void testComputeQuadrantPointOnQuadEdge() { Envelope quadBounds = new Envelope(testMaxBounds); for (int depthIndex = 0; depthIndex < testMaxDepth; depthIndex++) { Envelope centerPoint = new Envelope(quadBounds.centre()); // the point is at the exact center of the quad.The evaluation is performed in // clockwise order so SW should win assertEquals(SW, quad.computeQuadrant(centerPoint, depthIndex)); Envelope middleEastPoint = new Envelope(quadBounds.getMaxX(), quadBounds.getMaxX(), quadBounds.centre().y, quadBounds.centre().y); // the point is the eastmost shared point between NE and SE. NE should win assertEquals(NE, quad.computeQuadrant(middleEastPoint, depthIndex)); quadBounds = SW.slice(quadBounds); } }
public static int findMaxDepth(Envelope maxBounds, final int absoluteMaxDepth) { // choose the quad that tends to the biggest abs value maxBounds = RevObjects.makePrecise(maxBounds); final Quadrant testQuad = findBiggestMagnitudeQuad(maxBounds); Envelope parent = new Envelope(maxBounds); Envelope child = new Envelope(); Envelope float32Center = new Envelope(); for (int d = 0; d < absoluteMaxDepth; d++) { testQuad.slice(parent, child); Coordinate center = child.centre(); toFloat32(center, float32Center); if (!child.contains(float32Center)) { return d; } parent.init(child); } return absoluteMaxDepth; }
public static Geometry sineStar(Geometry g, @Metadata(title="Arm count") int nArms, @Metadata(title="Point count") int nPts) { Envelope env = FunctionsUtil.getEnvelopeOrDefault(g); GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g); double size = Math.min(env.getHeight(), env.getWidth()); SineStarFactory shape = new SineStarFactory(geomFact); shape.setCentre(env.centre()); shape.setSize(size); shape.setNumPoints(nPts); shape.setNumArms(nArms); shape.setArmLengthRatio(0.5); return shape.createSineStar(); }
private void testSliceMaxDepth(final Envelope maxBounds) { final int maxDepth = Quadrant.findMaxDepth(maxBounds, ABSOLUTE_MAX_DEPTH); Envelope parent = RevObjects.makePrecise(maxBounds); Envelope[] qbounds; for (int d = 0; d < maxDepth; d++) { qbounds = assertSlice(parent); Envelope sw = qbounds[0]; Envelope minimalEnv = RevObjects.makePrecise(new Envelope(sw.centre())); assertTrue("at index " + d, sw.contains(minimalEnv)); parent = sw; } }
public Envelope getQuadCenter(Quadrant... quadrants) { Envelope quadBounds = getMaxBounds(); if (quadrants != null) { for (Quadrant quad : quadrants) { quadBounds = quad.slice(quadBounds); } } Coordinate center = quadBounds.centre(); Envelope nodeBounds = RevObjects.makePrecise(new Envelope(center)); if (!quadBounds.contains(nodeBounds)) { GeometryFactory gf = new GeometryFactory(); Polygon qgeom = JTS.toGeometry(quadBounds, gf); ArrayList<Geometry> pointGeoms = Lists.newArrayList(gf.createPoint(center), JTS.toGeometry(nodeBounds, gf)); Geometry point = gf.buildGeometry(pointGeoms); String msg = qgeom + " does not contain " + point; Assert.fail(msg); } return nodeBounds; }
@Test public void testTinyRasterBboxContained() throws Exception { CoverageInfo coverageInfo = addRasterToMap(MockData.TASMANIA_DEM); Envelope env = coverageInfo.boundingBox(); Coordinate center = env.centre(); GridEnvelope range = coverageInfo.getGrid().getGridRange(); double offset = (env.getMaxX() - env.getMinX()) / range.getSpan(0) / 10.0; Rectangle imageBounds = produceMap( center.x + offset, center.x + 2 * offset, center.y + offset, center.y + 2 * offset); assertNotBlank("testTinyRasterBboxContained", this.image); assertEquals("Mosaic", this.op.getOperationName()); Rectangle roiBounds = getRoiBounds(); assertTrue( "Expected " + imageBounds + " to contain " + roiBounds, imageBounds.contains(roiBounds)); }