public boolean isEmpty() { return polygon.isEmpty(); }
/** * Converts a <code>Polygon</code> to <Polygon Text> format, then appends it to the * writer. * * @param polygon the <code>Polygon</code> to process * @param writer the output writer to append to */ private void appendPolygonText(Polygon polygon, int level, boolean indentFirst, Writer writer) throws IOException { if (polygon.isEmpty()) { writer.write("EMPTY"); } else { if (indentFirst) indent(level, writer); writer.write("("); appendLineStringText(polygon.getExteriorRing(), level, false, writer); for (int i = 0; i < polygon.getNumInteriorRing(); i++) { writer.write(", "); appendLineStringText(polygon.getInteriorRingN(i), level + 1, true, writer); } writer.write(")"); } }
private static void addElemInfo( List elemInfoList, MultiPolygon polys, final int STARTING_OFFSET, final int GTYPE) { Polygon poly; int offset = STARTING_OFFSET; int LEN = D(GTYPE) + L(GTYPE); for (int i = 0; i < polys.getNumGeometries(); i++) { poly = (Polygon) polys.getGeometryN(i); if (poly != null && !poly.isEmpty()) { addElemInfo(elemInfoList, poly, offset, GTYPE); if (isRectangle(poly)) { offset += (2 * LEN); } else { offset += (poly.getNumPoints() * LEN); } } } }
/** * Add ordinates for polygon - with hole support. * * <p>Ensure ordinates are added in the correct orientation as External or Internal polygons. * * @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(); if (!polygon.isEmpty()) { 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())); } } }
/** * Simplifies a polygon, fixing it if required. */ protected Geometry transformPolygon(Polygon geom, Geometry parent) { // empty geometries are simply removed if (geom.isEmpty()) return null; Geometry rawGeom = super.transformPolygon(geom, parent); // don't try and correct if the parent is going to do this if (parent instanceof MultiPolygon) { return rawGeom; } return createValidArea(rawGeom); }
/** * Simplifies a polygon, fixing it if required. */ protected Geometry transformPolygon(Polygon geom, Geometry parent) { // empty geometries are simply removed if (geom.isEmpty()) return null; Geometry rawGeom = super.transformPolygon(geom, parent); // don't try and correct if the parent is going to do this if (parent instanceof MultiPolygon) { return rawGeom; } return createValidArea(rawGeom); }
public Coordinate[] getCoordinates() { if (isEmpty()) { return new Coordinate[]{}; } Coordinate[] coordinates = new Coordinate[getNumPoints()]; int k = -1; Coordinate[] shellCoordinates = shell.getCoordinates(); for (int x = 0; x < shellCoordinates.length; x++) { k++; coordinates[k] = shellCoordinates[x]; } for (int i = 0; i < holes.length; i++) { Coordinate[] childCoordinates = holes[i].getCoordinates(); for (int j = 0; j < childCoordinates.length; j++) { k++; coordinates[k] = childCoordinates[j]; } } return coordinates; }
throws IOException if (polygon.isEmpty()) { writer.write("EMPTY");
private int locateInPolygon(Coordinate p, Polygon poly) { if (poly.isEmpty()) return Location.EXTERIOR; LinearRing shell = poly.getExteriorRing(); int shellLoc = locateInPolygonRing(p, shell); if (shellLoc == Location.EXTERIOR) return Location.EXTERIOR; if (shellLoc == Location.BOUNDARY) return Location.BOUNDARY; // now test if the point lies in or on the holes for (int i = 0; i < poly.getNumInteriorRing(); i++) { LinearRing hole = poly.getInteriorRingN(i); int holeLoc = locateInPolygonRing(p, hole); if (holeLoc == Location.INTERIOR) return Location.EXTERIOR; if (holeLoc == Location.BOUNDARY) return Location.BOUNDARY; } return Location.INTERIOR; }
private Polygon editPolygon(Polygon polygon, GeometryEditorOperation operation) { Polygon newPolygon = (Polygon) operation.edit(polygon, factory); // create one if needed if (newPolygon == null) newPolygon = factory.createPolygon(); if (newPolygon.isEmpty()) { //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return newPolygon; } LinearRing shell = (LinearRing) edit(newPolygon.getExteriorRing(), operation); if (shell == null || shell.isEmpty()) { //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return factory.createPolygon(); } ArrayList holes = new ArrayList(); for (int i = 0; i < newPolygon.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) edit(newPolygon.getInteriorRingN(i), operation); if (hole == null || hole.isEmpty()) { continue; } holes.add(hole); } return factory.createPolygon(shell, (LinearRing[]) holes.toArray(new LinearRing[] { })); }
if (poly.isEmpty()) return Location.EXTERIOR; LinearRing shell = poly.getExteriorRing(); int shellLoc = locatePointInRing(p, shell);
/** * 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(); } 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); }
@SuppressWarnings("unchecked") private static <P extends Position> org.geolatte.geom.Polygon<P> from(Polygon jtsGeometry, CoordinateReferenceSystem<P> crs) { if (jtsGeometry.isEmpty()) { return new org.geolatte.geom.Polygon<P>(crs); } org.geolatte.geom.LinearRing<P>[] rings = new org.geolatte.geom.LinearRing[jtsGeometry.getNumInteriorRing() + 1]; org.geolatte.geom.LineString<P> extRing = from(jtsGeometry.getExteriorRing(), crs); rings[0] = new org.geolatte.geom.LinearRing(extRing.getPositions(), extRing.getCoordinateReferenceSystem()); for (int i = 1; i < rings.length; i++) { org.geolatte.geom.LineString intRing = from(jtsGeometry.getInteriorRingN(i - 1), crs); rings[i] = new org.geolatte.geom.LinearRing(intRing); } return new org.geolatte.geom.Polygon(rings); }
private void writeMultiPolygon( MultiPolygon multiPolygon, PrecisionWriter precision, DataOutput output) throws IOException { Varint.writeUnsignedVarInt(multiPolygon.getNumGeometries(), output); for (int i = 0; i < multiPolygon.getNumGeometries(); i++) { Polygon polygon = (Polygon) multiPolygon.getGeometryN(i); if (polygon.isEmpty()) { Varint.writeUnsignedVarInt(0, output); continue; } Varint.writeUnsignedVarInt(polygon.getNumInteriorRing() + 1, output); precision.writePointArray(polygon.getExteriorRing().getCoordinates(), output); for (int j = 0; j < polygon.getNumInteriorRing(); j++) { precision.writePointArray(polygon.getInteriorRingN(j).getCoordinates(), output); } } }
assertTrue(geometryFactory.createLinearRing(new Coordinate[] { }).isEmpty()); assertTrue(geometryFactory.createLineString(new Coordinate[] { }).isEmpty()); assertTrue(geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { }), new LinearRing[] { }).isEmpty()); assertTrue(geometryFactory.createMultiPolygon(new Polygon[] { }).isEmpty()); assertTrue(geometryFactory.createMultiLineString(new LineString[] { }).isEmpty()); assertTrue(geometryFactory.createPolygon(null, null).isEmpty()); assertTrue(geometryFactory.createMultiPolygon(null).isEmpty()); assertTrue(geometryFactory.createMultiLineString(null).isEmpty());