/// <summary> /// Converts a MultiLineString to <MultiLineString Text> /// format, then Appends it to the writer. /// </summary> /// <param name="multiLineString">The MultiLineString to process.</param> /// <param name="level"></param> /// <param name="indentFirst"></param> /// <param name="writer">The output stream writer to Append to.</param> protected void AppendMultiLineStringText(MultiLineString multiLineString, int level, bool indentFirst, StringWriter writer) { if (multiLineString.isEmpty()) { writer.Write("EMPTY"); } else { int level2 = level; bool doIndent = indentFirst; writer.Write("("); for (int i = 0; i < multiLineString.getNumGeometries(); i++) { if (i > 0) { writer.Write(", "); level2 = level + 1; doIndent = true; } AppendLineStringText((LineString)multiLineString.getGeometryN(i), level2, doIndent, writer); } writer.Write(")"); } }
/// <summary> /// Writes to the given stream the equilivent shape file record given a Geometry object. /// </summary> /// <param name="geometry">The geometry object to write.</param> /// <param name="writer">The stream to write to.</param> /// <param name="factory">The geometry factory to use.</param> public override void Write(Geometry geometry, BinaryWriter writer, GeometryFactory factory) { MultiLineString multi = (MultiLineString)geometry; writer.Write((int)this.ShapeType); this.WriteBoundingBox(multi.getEnvelopeInternal(), writer); int numParts = multi.getNumGeometries(); int numPoints = multi.getNumPoints(); writer.Write(numParts); writer.Write(numPoints); //LineString[] lines = new LineString[numParts]; // write the offsets int offset = 0; for (int i = 0; i < numParts; i++) { Geometry g = multi.getGeometryN(i); writer.Write(offset); offset = offset + g.getNumPoints(); } for (int part = 0; part < numParts; part++) { Coordinate[] coords = multi.getGeometryN(part).getCoordinates(); for (int i = 0; i < coords.Length; i++) { factory.getPrecisionModel().makePrecise(coords[i]); writer.Write(coords[i].x); writer.Write(coords[i].y); } } }
public void TestMultiLineString1() { string wkt = "MULTILINESTRING (( 10.05 10.28 , 20.95 20.89 ),( 20.95 20.89, 31.92 21.45)) "; GeometryFactory factory = new GeometryFactory(); Geometry geometry = new GeometryWKTReader(factory).Create(wkt); MultiLineString multilineString = (MultiLineString)geometry; Assertion.AssertEquals("Multilinestring 1", 2, multilineString.getNumGeometries()); LineString linestring1 = (LineString)multilineString.getGeometryN(0); LineString linestring2 = (LineString)multilineString.getGeometryN(1); Assertion.AssertEquals("MLS 1", 10.05, linestring1.getCoordinates()[0].x); Assertion.AssertEquals("MLS 2", 10.28, linestring1.getCoordinates()[0].y); Assertion.AssertEquals("MLS 3", 20.95, linestring1.getCoordinates()[1].x); Assertion.AssertEquals("MLS 4", 20.89, linestring1.getCoordinates()[1].y); Assertion.AssertEquals("MLS 1", 20.95, linestring2.getCoordinates()[0].x); Assertion.AssertEquals("MLS 2", 20.89, linestring2.getCoordinates()[0].y); Assertion.AssertEquals("MLS 3", 31.92, linestring2.getCoordinates()[1].x); Assertion.AssertEquals("MLS 4", 21.45, linestring2.getCoordinates()[1].y); string wkt2 = new GeometryWKTWriter().Write(multilineString); Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2)); }
internal static IList <TDWay> wktMultiLineStringToWays(string wktFile) { Geometry geometry = readWKTFile(wktFile); if (geometry == null || !(geometry is MultiLineString)) { return(null); } MultiLineString mls = (MultiLineString)geometry; IList <TDWay> ret = new List <TDWay>(); for (int i = 0; i < mls.NumGeometries; i++) { ret.Add(fromLinestring((LineString)mls.getGeometryN(i), false)); } return(ret); }
private void WriteMultiLineString(MultiLineString mls, WKBByteOrder byteOrder) { // Write byte order _writer.Write((byte)byteOrder); // Write type this.WriteType(mls, byteOrder); //Write the number of linestrings. this.Write((uint)mls.getNumGeometries(), byteOrder); //Loop on the number of linestrings. for (int i = 0; i < mls.getNumGeometries(); i++) { // Write each linestring. this.WriteLineString((LineString)mls.getGeometryN(i), byteOrder, true); } }
/// <summary> /// Converts a MultiLineString to <MultiLineString Text> /// format, then Appends it to the writer. /// </summary> /// <param name="multiLineString">The MultiLineString to process.</param> /// <param name="writer">The output stream writer to Append to.</param> protected void AppendMultiLineStringText(MultiLineString multiLineString, TextWriter writer) { if (multiLineString.isEmpty()) { writer.Write("EMPTY"); } else { for (int i = 0; i < multiLineString.getNumGeometries(); i++) { if (i > 0) { writer.Write(", "); } //AppendLineStringText((LineString) multiLineString.GetGeometryN(i), level2, doIndent, writer); AppendLineStringText((LineString)multiLineString.getGeometryN(i), writer); } //writer.Write(")"); } }
/// <summary> /// Converts a MultiLineString to <MultiLineString Text> /// format, then Appends it to the writer. /// </summary> /// <param name="multiLineString">The MultiLineString to process.</param> /// <param name="level"></param> /// <param name="indentFirst"></param> /// <param name="writer">The output stream writer to Append to.</param> protected void AppendMultiLineStringText(MultiLineString multiLineString, int level, bool indentFirst, StringWriter writer) { if ( multiLineString.isEmpty() ) { writer.Write("EMPTY"); } else { int level2 = level; bool doIndent = indentFirst; writer.Write("("); for (int i = 0; i < multiLineString.getNumGeometries(); i++) { if (i > 0) { writer.Write(", "); level2 = level + 1; doIndent = true; } AppendLineStringText((LineString) multiLineString.getGeometryN(i), level2, doIndent, writer); } writer.Write(")"); } }
private void WriteMultiLineString(MultiLineString mls, WKBByteOrder byteOrder) { // Write byte order _writer.Write((byte)byteOrder); // Write type this.WriteType(mls, byteOrder); //Write the number of linestrings. this.Write((uint)mls.getNumGeometries(), byteOrder); //Loop on the number of linestrings. for (int i = 0; i < mls.getNumGeometries(); i++) { // Write each linestring. this.WriteLineString((LineString)mls.getGeometryN(i), byteOrder, true); } }
/// <summary> /// Convert a JTS Geometry to a WayDataBlock list. /// </summary> /// <param name="geometry"> /// a geometry object which should be converted </param> /// <returns> a list of WayBlocks which you can use to save the way. </returns> public static IList <WayDataBlock> toWayDataBlockList(Geometry geometry) { IList <WayDataBlock> res = new List <WayDataBlock>(); if (geometry is MultiPolygon) { MultiPolygon mp = (MultiPolygon)geometry; for (int i = 0; i < mp.NumGeometries; i++) { Polygon p = (Polygon)mp.getGeometryN(i); IList <int?> outer = toCoordinateList(p.ExteriorRing); if (outer.Count / 2 > 0) { IList <IList <int?> > inner = new List <IList <int?> >(); for (int j = 0; j < p.NumInteriorRing; j++) { IList <int?> innr = toCoordinateList(p.getInteriorRingN(j)); if (innr.Count / 2 > 0) { inner.Add(innr); } } res.Add(new WayDataBlock(outer, inner)); } } } else if (geometry is Polygon) { Polygon p = (Polygon)geometry; IList <int?> outer = toCoordinateList(p.ExteriorRing); if (outer.Count / 2 > 0) { IList <IList <int?> > inner = new List <IList <int?> >(); for (int i = 0; i < p.NumInteriorRing; i++) { IList <int?> innr = toCoordinateList(p.getInteriorRingN(i)); if (innr.Count / 2 > 0) { inner.Add(innr); } } res.Add(new WayDataBlock(outer, inner)); } } else if (geometry is MultiLineString) { MultiLineString ml = (MultiLineString)geometry; for (int i = 0; i < ml.NumGeometries; i++) { LineString l = (LineString)ml.getGeometryN(i); IList <int?> outer = toCoordinateList(l); if (outer.Count / 2 > 0) { res.Add(new WayDataBlock(outer, null)); } } } else if (geometry is LinearRing || geometry is LineString) { IList <int?> outer = toCoordinateList(geometry); if (outer.Count / 2 > 0) { res.Add(new WayDataBlock(outer, null)); } } else if (geometry is GeometryCollection) { GeometryCollection gc = (GeometryCollection)geometry; for (int i = 0; i < gc.NumGeometries; i++) { IList <WayDataBlock> recursiveResult = toWayDataBlockList(gc.getGeometryN(i)); foreach (WayDataBlock wayDataBlock in recursiveResult) { IList <int?> outer = wayDataBlock.OuterWay; if (outer.Count / 2 > 0) { res.Add(wayDataBlock); } } } } return(res); }
/// <summary> /// Converts a MultiLineString to <MultiLineString Text> /// format, then Appends it to the writer. /// </summary> /// <param name="multiLineString">The MultiLineString to process.</param> /// <param name="writer">The output stream writer to Append to.</param> protected void AppendMultiLineStringText(MultiLineString multiLineString, TextWriter writer) { if (multiLineString.isEmpty()) { writer.Write("EMPTY"); } else { for (int i = 0; i < multiLineString.getNumGeometries(); i++) { if (i > 0) { writer.Write(", "); } //AppendLineStringText((LineString) multiLineString.GetGeometryN(i), level2, doIndent, writer); AppendLineStringText((LineString) multiLineString.getGeometryN(i), writer); } //writer.Write(")"); } }