public boolean isEmpty() { for (LineString ls : components) { if (!ls.isEmpty()) { return false; } } return true; }
public boolean isEmpty() { return lineString.isEmpty(); }
/** * Removes collinear vertices from the provided {@link Polygon}. * * @param polygon the instance of a {@link Polygon} to remove collinear vertices from. * @return a new instance of the provided {@link Polygon} without collinear vertices. */ static Polygon removeCollinearVertices(final Polygon polygon) { if (polygon == null) { throw new NullPointerException("The provided Polygon is null"); } // reuse existing factory final GeometryFactory gf = polygon.getFactory(); // work on the exterior ring LineString exterior = polygon.getExteriorRing(); LineString shell = removeCollinearVertices(exterior); if ((shell == null) || shell.isEmpty()) { return null; } // work on the holes List<LineString> holes = new ArrayList<LineString>(); final int size = polygon.getNumInteriorRing(); for (int i = 0; i < size; i++) { LineString hole = polygon.getInteriorRingN(i); hole = removeCollinearVertices(hole); if ((hole != null) && !hole.isEmpty()) { holes.add(hole); } } return gf.createPolygon((LinearRing) shell, holes.toArray(new LinearRing[holes.size()])); }
/** * Converts a <code>LineString</code> to <LineString Text> format, then appends it to the * writer. * * @param lineString the <code>LineString</code> to process * @param writer the output writer to append to */ private void appendLineStringText( LineString lineString, int level, boolean doIndent, Writer writer) throws IOException { if (lineString.isEmpty()) { writer.write("EMPTY"); } else { if (doIndent) indent(level, writer); writer.write("("); for (int i = 0; i < lineString.getNumPoints(); i++) { if (i > 0) { writer.write(", "); if (coordsPerLine > 0 && i % coordsPerLine == 0) { indent(level + 1, writer); } } appendCoordinate(lineString.getCoordinateN(i), writer); } writer.write(")"); } }
} else { LineString converted = Converters.convert(source, LineString.class); if (converted.isEmpty()) { List<LineString> components = new ArrayList<>(); result =
@Test public void emptyLineString() throws Exception { LineString line = builder.lineString(); assertTrue(line.isEmpty()); assertEquals(2, line.getCoordinateSequence().getDimension()); }
public Coordinate getCoordinate() { if (isEmpty()) return null; return points.getCoordinate(0); }
public Point getStartPoint() { if (isEmpty()) { return null; } return getPointN(0); }
public Point getEndPoint() { if (isEmpty()) { return null; } return getPointN(getNumPoints() - 1); }
/** * Filters linear geometries. * * geom a geometry of any type */ public void filter(Geometry geom) { if (geom instanceof LineString) { LineString line = (LineString) geom; // skip empty geometries if (line.isEmpty()) return; int minSize = ((LineString) line).isClosed() ? 4 : 2; TaggedLineString taggedLine = new TaggedLineString((LineString) line, minSize); tps.linestringMap.put(line, taggedLine); } } }
protected Envelope computeEnvelopeInternal() { if (isEmpty()) { return new Envelope(); } return points.expandEnvelope(new Envelope()); }
/** * Removes collinear vertices from the provided {@link Polygon}. * @param polygon the instance of a {@link Polygon} to remove collinear vertices from. * @return a new instance of the provided {@link Polygon} without collinear vertices. */ public static Polygon removeCollinearVertices(final Polygon polygon) { if (polygon == null) { throw new NullPointerException("The provided Polygon is null"); } // reuse existing factory final GeometryFactory gf = polygon.getFactory(); // work on the exterior ring LineString exterior = polygon.getExteriorRing(); LineString shell = removeCollinearVertices(exterior); if (shell == null || shell.isEmpty()) { return null; } // work on the holes List<LineString> holes = new ArrayList<LineString>(); final int size = polygon.getNumInteriorRing(); for (int i = 0; i < size; i++) { LineString hole = polygon.getInteriorRingN(i); hole = removeCollinearVertices(hole); if (hole != null && !hole.isEmpty()) { holes.add(hole); } } return gf.createPolygon((LinearRing) shell, (LinearRing[]) holes.toArray(new LinearRing[holes.size()])); }
public boolean isClosed() { if (isEmpty()) { return false; } return getCoordinateN(0).equals2D(getCoordinateN(getNumPoints() - 1)); }
protected void paintLineString(LineString lineString, int lineType, Viewport viewport, Graphics2D graphics ) throws Exception { if (lineString.isEmpty()) { return; } paint(start ? lineString.getCoordinateN(0) : lineString.getCoordinateN(lineString.getNumPoints() - 1), start ? lineString.getCoordinateN(1) : lineString.getCoordinateN(lineString.getNumPoints() - 2), viewport, graphics); }
/** * Add a {@link LineString} forming an edge of the polygon graph. * @param line the line to add */ public void addEdge(LineString line) { if (line.isEmpty()) { return; } Coordinate[] linePts = CoordinateArrays.removeRepeatedPoints(line.getCoordinates()); if (linePts.length < 2) { return; } Coordinate startPt = linePts[0]; Coordinate endPt = linePts[linePts.length - 1]; Node nStart = getNode(startPt); Node nEnd = getNode(endPt); DirectedEdge de0 = new PolygonizeDirectedEdge(nStart, nEnd, linePts[1], true); DirectedEdge de1 = new PolygonizeDirectedEdge(nEnd, nStart, linePts[linePts.length - 2], false); Edge edge = new PolygonizeEdge(line); edge.setDirectedEdges(de0, de1); add(edge); }
/** * Adds an Edge, DirectedEdges, and Nodes for the given LineString representation * of an edge. * Empty lines or lines with all coordinates equal are not added. * * @param lineString the linestring to add to the graph */ public void addEdge(LineString lineString) { if (lineString.isEmpty()) { return; } Coordinate[] coordinates = CoordinateArrays.removeRepeatedPoints(lineString.getCoordinates()); // don't add lines with all coordinates equal if (coordinates.length <= 1) return; Coordinate startCoordinate = coordinates[0]; Coordinate endCoordinate = coordinates[coordinates.length - 1]; Node startNode = getNode(startCoordinate); Node endNode = getNode(endCoordinate); DirectedEdge directedEdge0 = new LineMergeDirectedEdge(startNode, endNode, coordinates[1], true); DirectedEdge directedEdge1 = new LineMergeDirectedEdge(endNode, startNode, coordinates[coordinates.length - 2], false); Edge edge = new LineMergeEdge(lineString); edge.setDirectedEdges(directedEdge0, directedEdge1); add(edge); }
private void visitInteriorRing(LineString ring, PlanarGraph graph) { if (ring.isEmpty()) return; Coordinate[] pts = ring.getCoordinates(); Coordinate pt0 = pts[0]; /** * Find first point in coord list different to initial point. * Need special check since the first point may be repeated. */ Coordinate pt1 = findDifferentPoint(pts, pt0); Edge e = graph.findEdgeInSameDirection(pt0, pt1); DirectedEdge de = (DirectedEdge) graph.findEdgeEnd(e); DirectedEdge intDe = null; if (de.getLabel().getLocation(0, Position.RIGHT) == Location.INTERIOR) { intDe = de; } else if (de.getSym().getLabel().getLocation(0, Position.RIGHT) == Location.INTERIOR) { intDe = de.getSym(); } Assert.isTrue(intDe != null, "unable to find dirEdge with Interior on RHS"); visitLinkedDirectedEdges(intDe); }
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()); }