public boolean isEmpty() { return shell.isEmpty(); }
@Test public void linearRingZ() throws Exception { LinearRing ring = builder.linearRingZ(); assertTrue(ring.isEmpty()); assertEquals(3, ring.getCoordinateSequence().getDimension()); }
@Test public void linearRing() throws Exception { LinearRing ring = builder.linearRing(); assertTrue(ring.isEmpty()); assertEquals(2, ring.getCoordinateSequence().getDimension()); }
if (ring == null || ring.isEmpty()) { return null;
/** * Tests whether this ring is closed. * Empty rings are closed by definition. * * @return true if this ring is closed */ public boolean isClosed() { if (isEmpty()) { // empty LinearRings are closed by definition return true; } return super.isClosed(); }
/** * 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(); } 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; }
private void validateConstruction() { if (!isEmpty() && ! super.isClosed()) { throw new IllegalArgumentException("Points of LinearRing do not form a closed linestring"); } if (getCoordinateSequence().size() >= 1 && getCoordinateSequence().size() < MINIMUM_VALID_SIZE) { throw new IllegalArgumentException("Invalid number of points in LinearRing (found " + getCoordinateSequence().size() + " - must be 0 or >= 4)"); } }
private void checkClosedRing(LinearRing ring) { if (ring.isEmpty()) return; if (! ring.isClosed() ) { Coordinate pt = null; if (ring.getNumPoints() >= 1) pt = ring.getCoordinateN(0); validErr = new TopologyValidationError( TopologyValidationError.RING_NOT_CLOSED, pt); } }
private Polygon editPolygon(Polygon polygon) { Polygon newPolygon = (Polygon) operation.edit(polygon, targetFactory); // create one if needed if (newPolygon == null) { newPolygon = targetFactory.createPolygon((CoordinateSequence) null); return newPolygon; } /** * If geometry was modified, return it */ if (newPolygon != polygon) { return newPolygon; } LinearRing shell = (LinearRing) edit(newPolygon.getExteriorRing()); if (shell == null || shell.isEmpty()) { return targetFactory.createPolygon(null, null); } ArrayList holes = new ArrayList(); for (int i = 0; i < newPolygon.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) edit(newPolygon.getInteriorRingN(i)); if (hole == null || hole.isEmpty()) { continue; } holes.add(hole); } return targetFactory.createPolygon(shell, (LinearRing[]) holes.toArray(new LinearRing[] { })); }
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[] { })); }
private void normalize(LinearRing ring, boolean clockwise) { if (ring.isEmpty()) { return; } CoordinateSequence seq = ring.getCoordinateSequence(); int minCoordinateIndex = CoordinateSequences.minCoordinateIndex(seq, 0, seq.size()-2); CoordinateSequences.scroll(seq, minCoordinateIndex, true); if (Orientation.isCCW(seq) == clockwise) CoordinateSequences.reverse(seq); }
if (lr.isEmpty()) return;
/** * Tests that no hole is nested inside another hole. * This routine assumes that the holes are disjoint. * To ensure this, holes have previously been tested * to ensure that: * <ul> * <li>they do not partially overlap * (checked by <code>checkRelateConsistency</code>) * <li>they are not identical * (checked by <code>checkRelateConsistency</code>) * </ul> */ private void checkHolesNotNested(Polygon p, GeometryGraph graph) { IndexedNestedRingTester nestedTester = new IndexedNestedRingTester(graph); //SimpleNestedRingTester nestedTester = new SimpleNestedRingTester(arg[0]); //SweeplineNestedRingTester nestedTester = new SweeplineNestedRingTester(arg[0]); for (int i = 0; i < p.getNumInteriorRing(); i++) { LinearRing innerHole = p.getInteriorRingN(i); if (innerHole.isEmpty()) continue; nestedTester.add(innerHole); } boolean isNonNested = nestedTester.isNonNested(); if ( ! isNonNested ) { validErr = new TopologyValidationError( TopologyValidationError.NESTED_HOLES, nestedTester.getNestedPoint()); } }
if (polyShell.isEmpty()) return; Coordinate[] polyPts = polyShell.getCoordinates(); Coordinate shellPt = findPtNotNode(shellPts, polyShell, graph);
public void testIsClosed() throws Exception { LineString l = (LineString) reader.read("LINESTRING EMPTY"); assertTrue(l.isEmpty()); assertTrue(! l.isClosed()); LinearRing r = geometryFactory.createLinearRing((CoordinateSequence)null); assertTrue(r.isEmpty()); assertTrue(r.isClosed()); MultiLineString m = geometryFactory.createMultiLineString( new LineString[] {l, r}); assertTrue(! m.isClosed()); MultiLineString m2 = geometryFactory.createMultiLineString( new LineString[] {r}); assertTrue(! m2.isClosed()); }
public void testCreateEmptyGeometry() throws Exception { assertTrue(geometryFactory.createPoint((Coordinate)null).isEmpty()); assertTrue(geometryFactory.createLinearRing(new Coordinate[] { }).isEmpty()); assertTrue(geometryFactory.createLineString(new Coordinate[] { }).isEmpty()); assertTrue(geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { }), new LinearRing[] { }).isEmpty()); assertTrue(geometryFactory.createMultiPoint(new Point[] { }).getBoundary().isEmpty()); assertTrue(geometryFactory.createLinearRing((CoordinateSequence)null).isEmpty()); assertTrue(geometryFactory.createLineString((Coordinate[])null).isEmpty()); assertTrue(geometryFactory.createPolygon(null, null).isEmpty());