/** * Tests the interior vertices (if any) * defined by an areal Geometry for the best inside point. * If a component Geometry is not of dimension 2 it is not tested. * * @param geom the geometry to add */ private void add(Geometry geom) { if (geom instanceof Polygon) { addPolygon(geom); } else if (geom instanceof GeometryCollection) { GeometryCollection gc = (GeometryCollection) geom; for (int i = 0; i < gc.getNumGeometries(); i++) { add(gc.getGeometryN(i)); } } }
/** * Finds a reasonable point at which to label a Geometry. * @param geometry the geometry to analyze */ public void addPolygon(Geometry geometry) { LineString bisector = horizontalBisector(geometry); Geometry intersections = bisector.intersection(geometry); Geometry widestIntersection = widestGeometry(intersections); double width = widestIntersection.getEnvelopeInternal().getWidth(); if (interiorPoint == null || width > maxWidth) { interiorPoint = centre(widestIntersection.getEnvelopeInternal()); maxWidth = width; } }
/** * Computes an interior point of this <code>Geometry</code>. * An interior point is guaranteed to lie in the interior of the Geometry, * if it possible to calculate such a point exactly. Otherwise, * the point may lie on the boundary of the geometry. * <p> * The interior point of an empty geometry is <code>POINT EMPTY</code>. * * @return a {@link Point} which is in the interior of this Geometry */ public Point getInteriorPoint() { if (isEmpty()) return factory.createPoint((Coordinate) null); Coordinate interiorPt = null; int dim = getDimension(); if (dim == 0) { InteriorPointPoint intPt = new InteriorPointPoint(this); interiorPt = intPt.getInteriorPoint(); } else if (dim == 1) { InteriorPointLine intPt = new InteriorPointLine(this); interiorPt = intPt.getInteriorPoint(); } else { InteriorPointArea intPt = new InteriorPointArea(this); interiorPt = intPt.getInteriorPoint(); } return createPointFromInternalCoord(interiorPt, this); }
public InteriorPointArea(Geometry g) { factory = g.getFactory(); add(g); } public Coordinate getInteriorPoint()
protected Geometry widestGeometry(Geometry geometry) { if (!(geometry instanceof GeometryCollection)) { return geometry; } return widestGeometry((GeometryCollection) geometry); }
/** * @return an interior point of this geometry */ public Point getInteriorPoint() { Coordinate coord = new InteriorPointArea( getJTSGeometry() ).getInteriorPoint(); return new GeometryFactory().createPoint( null, coord.x, coord.y, crs ); }
/** * Creates a new interior point finder * for an areal geometry. * * @param g an areal geometry */ public InteriorPointArea(Geometry g) { factory = g.getFactory(); add(g); }
private Geometry widestGeometry(Geometry geometry) { if (!(geometry instanceof GeometryCollection)) { return geometry; } return widestGeometry((GeometryCollection) geometry); }
/** * Computes an interior point of this <code>Geometry</code>. * An interior point is guaranteed to lie in the interior of the Geometry, * if it possible to calculate such a point exactly. Otherwise, * the point may lie on the boundary of the geometry. * <p> * The interior point of an empty geometry is <code>POINT EMPTY</code>. * * @return a {@link Point} which is in the interior of this Geometry */ public Point getInteriorPoint() { if (isEmpty()) return factory.createPoint((Coordinate) null); Coordinate interiorPt = null; int dim = getDimension(); if (dim == 0) { InteriorPointPoint intPt = new InteriorPointPoint(this); interiorPt = intPt.getInteriorPoint(); } else if (dim == 1) { InteriorPointLine intPt = new InteriorPointLine(this); interiorPt = intPt.getInteriorPoint(); } else { InteriorPointArea intPt = new InteriorPointArea(this); interiorPt = intPt.getInteriorPoint(); } return createPointFromInternalCoord(interiorPt, this); }
/** * Finds an interior point of a Polygon. * @param geometry the geometry to analyze */ private void addPolygon(Geometry geometry) { if (geometry.isEmpty()) return; Coordinate intPt; double width = 0; LineString bisector = horizontalBisector(geometry); if (bisector.getLength() == 0.0) { width = 0; intPt = bisector.getCoordinate(); } else { Geometry intersections = bisector.intersection(geometry); Geometry widestIntersection = widestGeometry(intersections); width = widestIntersection.getEnvelopeInternal().getWidth(); intPt = centre(widestIntersection.getEnvelopeInternal()); } if (interiorPoint == null || width > maxWidth) { interiorPoint = intPt; maxWidth = width; } }
/** * Tests the interior vertices (if any) * defined by an areal Geometry for the best inside point. * If a component Geometry is not of dimension 2 it is not tested. * * @param geom the geometry to add */ private void add(Geometry geom) { if (geom instanceof Polygon) { addPolygon(geom); } else if (geom instanceof GeometryCollection) { GeometryCollection gc = (GeometryCollection) geom; for (int i = 0; i < gc.getNumGeometries(); i++) { add(gc.getGeometryN(i)); } } }
protected LineString horizontalBisector(Geometry geometry) { Envelope envelope = geometry.getEnvelopeInternal(); // Assert: for areas, minx <> maxx double avgY = avg(envelope.getMinY(), envelope.getMaxY()); return factory.createLineString(new Coordinate[] { new Coordinate(envelope.getMinX(), avgY), new Coordinate(envelope.getMaxX(), avgY) }); }