public static Geometry minimumRectangle(Geometry g) { if (g == null) return null; MinimumDiameter min = new MinimumDiameter(g); return min.getMinimumRectangle(); }
public static Geometry minimumDiameter(Geometry arg0) { if (arg0 == null) return null; MinimumDiameter minDiameter = new MinimumDiameter(arg0); return minDiameter.getDiameter(); }
computeMinimumDiameter(); double paraC = computeC(dx, dy, convexHullPts[i]); if (paraC > maxPara) maxPara = paraC; if (paraC < minPara) minPara = paraC; double perpC = computeC(-dy, dx, convexHullPts[i]); if (perpC > maxPerp) maxPerp = perpC; if (perpC < minPerp) minPerp = perpC; LineSegment maxPerpLine = computeSegmentForLine(-dx, -dy, maxPerp); LineSegment minPerpLine = computeSegmentForLine(-dx, -dy, minPerp); LineSegment maxParaLine = computeSegmentForLine(-dy, dx, maxPara); LineSegment minParaLine = computeSegmentForLine(-dy, dx, minPara);
private void computeWidthConvex(Geometry convexGeom) { //System.out.println("Input = " + geom); if (convexGeom instanceof Polygon) convexHullPts = ((Polygon) convexGeom).getExteriorRing().getCoordinates(); else convexHullPts = convexGeom.getCoordinates(); // special cases for lines or points or degenerate rings if (convexHullPts.length == 0) { minWidth = 0.0; minWidthPt = null; minBaseSeg = null; } else if (convexHullPts.length == 1) { minWidth = 0.0; minWidthPt = convexHullPts[0]; minBaseSeg.p0 = convexHullPts[0]; minBaseSeg.p1 = convexHullPts[0]; } else if (convexHullPts.length == 2 || convexHullPts.length == 3) { minWidth = 0.0; minWidthPt = convexHullPts[0]; minBaseSeg.p0 = convexHullPts[0]; minBaseSeg.p1 = convexHullPts[1]; } else computeConvexRingMinDiameter(convexHullPts); }
private Geometry getConflictBounds(Geometry bounds, int spaceAround) { // apply the space around (with a negative one we might end up with nothing as the result) Geometry conflictBounds = bounds; if (spaceAround != 0) { conflictBounds = bounds.buffer(spaceAround); if (conflictBounds.isEmpty() || conflictBounds.getArea() == 0) { conflictBounds = null; } else { conflictBounds = new MinimumDiameter(conflictBounds).getMinimumRectangle(); } } return conflictBounds; }
/** * Gets the length of the minimum diameter enclosing a geometry * @param geom the geometry * @return the length of the minimum diameter of the geometry */ public static Geometry getMinimumDiameter(Geometry geom) { return (new MinimumDiameter(geom)).getDiameter(); }
double calcPolygonAlignMBRAngle(Geometry geometry) { // use JTS MinimumDiameter class to calc MBR Geometry mbr = new MinimumDiameter(geometry).getMinimumRectangle(); // calc angle from the longest side of the MBR Coordinate[] coordinates = mbr.getCoordinates(); double dx, dy; if (coordinates[0].distance(coordinates[1]) > coordinates[1].distance(coordinates[2])) { dx = coordinates[1].x - coordinates[0].x; dy = coordinates[1].y - coordinates[0].y; } else { dx = coordinates[2].x - coordinates[1].x; dy = coordinates[2].y - coordinates[1].y; } double angle = Math.atan(dy / dx); // make sure we turn PI/2 into -PI/2, we don't want some labels looking straight up // and some others straight down, when almost vertical they should all be oriented // on the same side if (Math.abs(angle - Math.PI / 2) < Math.PI / 180.0) { angle = -Math.PI / 2 + Math.abs(angle - Math.PI / 2); } return angle; } }
public static Geometry minimumDiameter(Geometry g) { return (new MinimumDiameter(g)).getDiameter(); } public static double minimumDiameterLength(Geometry g) { return (new MinimumDiameter(g)).getDiameter().getLength(); }
private Geometry getGeometryBounds( Icon icon, Mark mark, Shape shape, double markSize, Object feature) { Geometry bounds; if (icon != null) { bounds = new GeometryBuilder().box(0, 0, icon.getIconWidth(), icon.getIconHeight()); } else { // the shape can be very complicated, go for the MBR. Wanted to use ShapeReader, but it // blindly assumes the shape is a polygon, while it may not be. Building a multipoint // instead AffineTransform at = AffineTransform.getScaleInstance(markSize, -markSize); Shape ts = at.createTransformedShape(shape); Geometry shapeGeometry = JTS.toGeometry(ts); bounds = new MinimumDiameter(shapeGeometry).getMinimumRectangle(); } // grow by the stroke size, if this is a mark if (icon == null && mark != null) { Stroke stroke = factory.getStroke(mark.getStroke(), feature); if (stroke instanceof BasicStroke) { float width = ((BasicStroke) stroke).getLineWidth() / 2 + 1; if (width > 0) { Geometry buffered = bounds.buffer(width); bounds = new MinimumDiameter(buffered).getMinimumRectangle(); } } } return bounds; }
public static LineString minimumDiameter(Geometry geometry){ if(geometry == null){ return null; } return new MinimumDiameter(geometry).getDiameter(); } }
/** * Gets the minimum rectangle enclosing a geometry. * * @param geom the geometry * @return the minimum rectangle enclosing the geometry */ public static Geometry getMinimumRectangle(Geometry geom) { return (new MinimumDiameter(geom)).getMinimumRectangle(); }
public static double minimumDiameterLength(Geometry g) { return (new MinimumDiameter(g)).getDiameter().getLength(); }
/** * Gets the minimum rectangular {@link Polygon} which encloses the input geometry. * @param geometry Input geometry * @return */ public static Geometry computeMinimumRectangle(Geometry geometry){ if(geometry == null){ return null; } return new MinimumDiameter(geometry).getMinimumRectangle(); } }
/** Test of evaluate method, of class FilterFunction_minimumDiameter. */ @Test public void testEvaluate() throws Exception { SimpleFeatureCollection featureCollection = FunctionTestFixture.polygons(); // Test the Function FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints()); Function exp = ff.function("minimumdiameter", ff.property("geom")); SimpleFeatureIterator iter = featureCollection.features(); while (iter.hasNext()) { SimpleFeature feature = iter.next(); Geometry geom = (Geometry) feature.getDefaultGeometry(); Geometry minimumDiameter = new MinimumDiameter(geom).getDiameter(); Object value = exp.evaluate(feature); assertTrue(value instanceof LineString); assertTrue(minimumDiameter.equalsExact((Geometry) value, 0.1)); } iter.close(); // Check for null safeness assertNull(exp.evaluate(null)); } }
public static Geometry minimumRectangle(Geometry g) { return (new MinimumDiameter(g)).getMinimumRectangle(); } public static Geometry minimumBoundingCircle(Geometry g) { return (new MinimumBoundingCircle(g)).getCircle(); }
private void doMinimumDiameterTest(boolean convex, String wkt, Coordinate c0, Coordinate c1) throws ParseException { Coordinate[] minimumDiameter = new MinimumDiameter(new WKTReader().read(wkt), convex).getDiameter().getCoordinates(); double tolerance = 1E-10; assertEquals(c0.x, minimumDiameter[0].x, tolerance); assertEquals(c0.y, minimumDiameter[0].y, tolerance); assertEquals(c1.x, minimumDiameter[1].x, tolerance); assertEquals(c1.y, minimumDiameter[1].y, tolerance); }
/** Test of evaluate method, of class FilterFunction_minimumCircle. */ @Test public void testEvaluate() throws Exception { SimpleFeatureCollection featureCollection = FunctionTestFixture.polygons(); // Test the Function FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints()); Function exp = ff.function("minrectangle", ff.property("geom")); SimpleFeatureIterator iter = featureCollection.features(); while (iter.hasNext()) { SimpleFeature feature = iter.next(); Geometry geom = (Geometry) feature.getDefaultGeometry(); Geometry rectangle = new MinimumDiameter(geom).getMinimumRectangle(); Object value = exp.evaluate(feature); assertTrue(value instanceof Polygon); assertTrue(rectangle.equals((Geometry) value)); } iter.close(); // Check for null safeness assertNull(exp.evaluate(null)); } }