Beispiel #1
0
        /// <summary>
        /// Writes the Geometry object to the string in WKT format.
        /// </summary>
        /// <param name="geometry">The Geometry to be written.</param>
        /// <returns>The WKT representation of the Geometry.</returns>
        public static string WriteToString(IGeometry geometry)
        {
            StringWriter tw = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);

            WktWriter.Write(geometry, tw);

            return(tw.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Converts GeometryCollection's content to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="collection">The GeometryCollection to be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendGeometryCollectionText(IGeometryCollection <IGeometry> collection, TextWriter writer)
        {
            if (collection.Geometries.Count() == 0)
            {
                writer.Write("empty");
            }
            else
            {
                writer.Write("(");
                WktWriter.Write(collection.Geometries.First(), writer);

                foreach (var geometry in collection.Geometries.Skip(1))
                {
                    writer.Write(",");
                    WktWriter.Write(geometry, writer);
                }

                writer.Write(")");
            }
        }
Beispiel #3
0
 /// <summary>
 /// Writes the Geometry object in the WKT format to the output.
 /// </summary>
 /// <param name="geometry">The geometry to write.</param>
 public void Write(IGeometry geometry)
 {
     WktWriter.Write(geometry, _writer);
 }
        private void TestWriteGeometry(IGeometry geometry, string expectedWkt)
        {
            MemoryStream stream = new MemoryStream();
            using (WktWriter writer = new WktWriter(stream, new WktWriterSettings())) {
                writer.Write(geometry);
            }

            using (TextReader tr = new StreamReader(new MemoryStream(stream.ToArray()))) {
                string wkt = tr.ReadToEnd();
                Assert.Equal(expectedWkt, wkt, StringComparer.InvariantCultureIgnoreCase);
            }
        }