/** * Computes the boundary of this geometry * * @return a lineal geometry (which may be empty) * @see Geometry#getBoundary */ public Geometry getBoundary() { if (isEmpty()) { return getFactory().createMultiLineString(null); } LinearRing[] rings = new LinearRing[holes.length + 1]; rings[0] = shell; for (int i = 0; i < holes.length; i++) { rings[i + 1] = holes[i]; } // create LineString or MultiLineString as appropriate if (rings.length <= 1) return getFactory().createLinearRing(rings[0].getCoordinateSequence()); return getFactory().createMultiLineString(rings); }
/** * Constructs a <code>Polygon</code> with the given exterior boundary and * interior boundaries. * *@param shell the outer boundary of the new <code>Polygon</code>, * or <code>null</code> or an empty <code>LinearRing</code> if the empty * geometry is to be created. *@param holes the inner boundaries of the new <code>Polygon</code> * , or <code>null</code> or empty <code>LinearRing</code>s if the empty * geometry is to be created. */ public Polygon(LinearRing shell, LinearRing[] holes, GeometryFactory factory) { super(factory); if (shell == null) { shell = getFactory().createLinearRing((CoordinateSequence)null); } if (holes == null) { holes = new LinearRing[]{}; } if (hasNullElements(holes)) { throw new IllegalArgumentException("holes must not contain null elements"); } if (shell.isEmpty() && hasNonEmptyElements(holes)) { throw new IllegalArgumentException("shell is empty but holes are not"); } this.shell = shell; this.holes = holes; }
public GeometryFactory getFactory() { return polygon.getFactory(); }
/** * Create a new polygon without hole. * * @param polygon * @return */ public static Polygon removeHolesPolygon(Polygon polygon) { return new Polygon((LinearRing) polygon.getExteriorRing(), null, polygon.getFactory()); } }
/** * Create a new polygon without hole. * * @param polygon * @return */ public static Polygon removeHolePolygon(Polygon polygon) { return new Polygon((LinearRing) polygon.getExteriorRing(), null, polygon.getFactory()); }
/** * Create a new polygon without hole. * * @param polygon * @return */ public static Polygon removeHolesPolygon(Polygon polygon) { return new Polygon((LinearRing) polygon.getExteriorRing(), null, polygon.getFactory()); } }
/** * Computes the boundary of this geometry * * @return a lineal geometry (which may be empty) * @see Geometry#getBoundary */ public Geometry getBoundary() { if (isEmpty()) { return getFactory().createMultiLineString(null); } LinearRing[] rings = new LinearRing[holes.length + 1]; rings[0] = shell; for (int i = 0; i < holes.length; i++) { rings[i + 1] = holes[i]; } // create LineString or MultiLineString as appropriate if (rings.length <= 1) return getFactory().createLinearRing(rings[0].getCoordinateSequence()); return getFactory().createMultiLineString(rings); }
protected static Polygon transformPolygon(CoordinateTransform ct, Polygon polygon) { return polygon.getFactory().createPolygon(transformCoordinates(ct, polygon.getCoordinates())); }
protected static Polygon transformPolygon(CoordinateTransform ct, Polygon polygon) { return polygon.getFactory().createPolygon(transformCoordinates(ct, polygon.getCoordinates())); }
protected static Polygon transformPolygon(CoordinateTransform ct, Polygon polygon) { return polygon.getFactory().createPolygon(transformCoordinates(ct, polygon.getCoordinates())); }
private Geometry removeHoles(Polygon polygon) { GeometryFactory factory = polygon.getFactory(); LineString exteriorRing = polygon.getExteriorRing(); Geometry finalGeom = factory.createPolygon((LinearRing) exteriorRing, null); finalGeom.setUserData(polygon.getUserData()); return finalGeom; } }
private Geometry removeHoles(Polygon polygon) { GeometryFactory factory = polygon.getFactory(); LineString exteriorRing = polygon.getExteriorRing(); Geometry finalGeom = factory.createPolygon((LinearRing) exteriorRing, null); finalGeom.setUserData(polygon.getUserData()); return finalGeom; }
/** * Clips a polygon using the Liang-Barsky helper routine. Does not generate, in general, * valid polygons (but still does generate polygons good enough for rendering) * @param polygon * @return */ private Geometry clipPolygon(Polygon polygon) { final GeometryFactory gf = polygon.getFactory(); LinearRing exterior = (LinearRing) polygon.getExteriorRing(); LinearRing shell = polygonClip(exterior); if(shell == null || shell.isEmpty()) { return null; } List<LinearRing> holes = new ArrayList<LinearRing>(); for (int i = 0; i < polygon.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) polygon.getInteriorRingN(i); hole = polygonClip(hole); if(hole != null && !hole.isEmpty()) { holes.add(hole); } } return gf.createPolygon(shell, (LinearRing[]) holes.toArray(new LinearRing[holes.size()])); }
/** * Drape a polygon on a set of triangles * @param p * @param triangles * @param sTRtree * @return */ public static Geometry drapePolygon(Polygon p, Geometry triangles, STRtree sTRtree) { GeometryFactory factory = p.getFactory(); //Split the triangles in lines to perform all intersections Geometry triangleLines = LinearComponentExtracter.getGeometry(triangles, true); Polygon splittedP = processPolygon(p, triangleLines, factory); CoordinateSequenceFilter drapeFilter = new DrapeFilter(sTRtree); splittedP.apply(drapeFilter); return splittedP; }
private Geometry removeSmallHoles(Polygon polygon, double areaTolerance) { GeometryFactory factory = polygon.getFactory(); LineString exteriorRing = polygon.getExteriorRing(); // check interior rings List<LinearRing> interiorRingList = new ArrayList<LinearRing>(); for (int index = 0; index < polygon.getNumInteriorRing(); index++) { LineString interiorRing = polygon.getInteriorRingN(index); if (interiorRing.isRing()) { if (Math.abs(interiorRing.getArea()) >= areaTolerance) { interiorRingList.add((LinearRing) interiorRing); } } } LinearRing[] holes = null; if (interiorRingList.size() > 0) { holes = GeometryFactory.toLinearRingArray(interiorRingList); } Geometry finalGeom = factory.createPolygon((LinearRing) exteriorRing, holes); finalGeom.setUserData(polygon.getUserData()); return finalGeom; } }
/** * Add ordinates for polygon - with hole support. * * <p> * Ensure ordinates are added in the correct orientation as External or * Internal polygons. * </p> * * @param list List to add coordiantes to * @param polygon Polygon to be encoded */ private static void addCoordinatesInterpretation1(List list, Polygon polygon) { int holes = polygon.getNumInteriorRing(); addCoordinates(list, counterClockWise(polygon.getFactory().getCoordinateSequenceFactory(), polygon.getExteriorRing().getCoordinateSequence())); for (int i = 0; i < holes; i++) { addCoordinates(list, clockWise(polygon.getFactory().getCoordinateSequenceFactory(), polygon.getInteriorRingN(i).getCoordinateSequence())); } }
/** * Reverse the polygon to be oriented clockwise * @param polygon * @return */ private static Polygon extractFloor(final Polygon polygon) { GeometryFactory factory = polygon.getFactory(); final LinearRing shell = factory.createLinearRing(getClockWise( polygon.getExteriorRing()).getCoordinates()); final int nbOfHoles = polygon.getNumInteriorRing(); final LinearRing[] holes = new LinearRing[nbOfHoles]; for (int i = 0; i < nbOfHoles; i++) { holes[i] = factory.createLinearRing(getCounterClockWise( polygon.getInteriorRingN(i)).getCoordinates()); } return factory.createPolygon(shell, holes); }
/** * Reverse the polygon to be oriented clockwise * @param polygon * @return */ private static Polygon extractFloor(final Polygon polygon) { GeometryFactory factory = polygon.getFactory(); final LinearRing shell = factory.createLinearRing(getClockWise( polygon.getExteriorRing()).getCoordinates()); final int nbOfHoles = polygon.getNumInteriorRing(); final LinearRing[] holes = new LinearRing[nbOfHoles]; for (int i = 0; i < nbOfHoles; i++) { holes[i] = factory.createLinearRing(getCounterClockWise( polygon.getInteriorRingN(i)).getCoordinates()); } return factory.createPolygon(shell, holes); }
/** * Extract the roof of a polygon * * @param polygon * @param height * @return */ public static Polygon extractRoof(Polygon polygon, double height) { GeometryFactory factory = polygon.getFactory(); Polygon roofP = (Polygon) polygon.clone(); roofP.apply(new TranslateCoordinateSequenceFilter(height)); final LinearRing shell = factory.createLinearRing(getCounterClockWise(roofP.getExteriorRing()).getCoordinates()); final int nbOfHoles = roofP.getNumInteriorRing(); final LinearRing[] holes = new LinearRing[nbOfHoles]; for (int i = 0; i < nbOfHoles; i++) { holes[i] = factory.createLinearRing(getClockWise( roofP.getInteriorRingN(i)).getCoordinates()); } return factory.createPolygon(shell, holes); }
/** * Extract the roof of a polygon * * @param polygon * @param height * @return */ public static Polygon extractRoof(Polygon polygon, double height) { GeometryFactory factory = polygon.getFactory(); Polygon roofP = (Polygon) polygon.clone(); roofP.apply(new TranslateCoordinateSequenceFilter(height)); final LinearRing shell = factory.createLinearRing(getCounterClockWise(roofP.getExteriorRing()).getCoordinates()); final int nbOfHoles = roofP.getNumInteriorRing(); final LinearRing[] holes = new LinearRing[nbOfHoles]; for (int i = 0; i < nbOfHoles; i++) { holes[i] = factory.createLinearRing(getClockWise( roofP.getInteriorRingN(i)).getCoordinates()); } return factory.createPolygon(shell, holes); }