/// <summary> Tests whether a <see cref="Geometry"/> is sequenced correctly. /// <see cref="LineString"/>s are trivially sequenced. /// <see cref="MultiLineString"/>s are checked for correct sequencing. /// Otherwise, <code>isSequenced</code> is defined /// to be <see langword="true"/> for geometries that are not lineal. /// /// </summary> /// <param name="geom">the geometry to test /// </param> /// <returns> <see langword="true"/> if the geometry is sequenced or is not lineal /// </returns> public static bool IsSequenced(Geometry geom) { if (!(geom is MultiLineString)) { return(true); } MultiLineString mls = (MultiLineString)geom; // the nodes in all subgraphs which have been completely scanned //TODO--PAUL 'java.util.TreeSet' was converted to ListSet ListSet prevSubgraphNodes = new ListSet(); Coordinate lastNode = null; IList currNodes = new ArrayList(); for (int i = 0; i < mls.NumGeometries; i++) { LineString line = (LineString)mls.GetGeometry(i); Coordinate startNode = line.GetCoordinate(0); Coordinate endNode = line.GetCoordinate(line.NumPoints - 1); // If this linestring is connected to a previous subgraph, // geom is not sequenced if (prevSubgraphNodes.Contains(startNode)) { return(false); } if (prevSubgraphNodes.Contains(endNode)) { return(false); } if (lastNode != null) { if (!startNode.Equals(lastNode)) { // start new connected sequence prevSubgraphNodes.AddAll(currNodes); currNodes.Clear(); } } currNodes.Add(startNode); currNodes.Add(endNode); lastNode = endNode; } return(true); }
/// <summary> /// Gets the <see cref="Coordinate"/> along the /// given linear <see cref="Geometry"/> which is /// referenced by this location. /// /// </summary> /// <param name="linearGeom">a linear geometry /// </param> /// <returns> the <tt>Coordinate</tt> at the location /// </returns> public Coordinate GetCoordinate(Geometry linearGeom) { LineString lineComp = (LineString)linearGeom.GetGeometry(componentIndex); Coordinate p0 = lineComp.GetCoordinate(segmentIndex); if (segmentIndex >= lineComp.NumPoints - 1) { return(p0); } Coordinate p1 = lineComp.GetCoordinate(segmentIndex + 1); return(PointAlongSegmentByFraction(p0, p1, segmentFraction)); }
/// <summary> /// Converts a LineString to <LineString Text> format, then /// appends it to the writer. /// </summary> /// <param name="lineString"> the LineString to process /// </param> /// <param name="writer"> the output writer to append to /// </param> private void AppendLineStringText(LineString lineString, int level, bool doIndent, TextWriter writer) { if (lineString.IsEmpty) { writer.Write(WktEmpty); } else { if (doIndent) { Indent(level, writer); } writer.Write(WktLParan); for (int i = 0; i < lineString.NumPoints; i++) { if (i > 0) { writer.Write(WktComma); if (i % 10 == 0) { Indent(level + 2, writer); } } AppendCoordinate(lineString.GetCoordinate(i), writer); } writer.Write(WktRParan); } }
/// <summary> /// Gets the length of the segment in the given Geometry containing /// this location. /// </summary> /// <param name="linearGeom">A linear geometry.</param> /// <returns>The length of the segment.</returns> public double GetSegmentLength(Geometry linearGeom) { LineString lineComp = (LineString)linearGeom.GetGeometry(componentIndex); // ensure segment index is valid int segIndex = segmentIndex; if (segmentIndex >= lineComp.NumPoints - 1) { segIndex = lineComp.NumPoints - 2; } Coordinate p0 = lineComp.GetCoordinate(segIndex); Coordinate p1 = lineComp.GetCoordinate(segIndex + 1); return(p0.Distance(p1)); }