Beispiel #1
0
        /// <summary>
        /// Converts the List of Coordinates to WKT format and appends it to output stream.
        /// </summary>
        /// <param name="coordinates">The list of coordinates to be converted.</param>
        /// <param name="writer">The output stream.</param>
        /// <param name="wrap">bool value indicating whether the list of coordinates should be enclosed in parathenes.</param>
        private static void AppendCoordinates(ICoordinateList coordinates, TextWriter writer, bool wrap)
        {
            if (coordinates.Count == 0)
            {
                return;
            }

            if (wrap)
            {
                writer.Write("(");
            }

            WktWriter.AppendCoordinate(coordinates[0], writer);

            for (int i = 1; i < coordinates.Count; i++)
            {
                writer.Write(", ");
                WktWriter.AppendCoordinate(coordinates[i], writer);
            }

            if (wrap)
            {
                writer.Write(")");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Converts Polygon's content to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="polygon">The Polygon to be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendPolygonText(IPolygon polygon, TextWriter writer)
        {
            if (polygon.ExteriorRing.Count == 0)
            {
                writer.Write("empty");
            }
            else
            {
                writer.Write("(");
                WktWriter.AppendCoordinates(polygon.ExteriorRing, writer, true);

                if (polygon.InteriorRings.Count() > 0)
                {
                    writer.Write(",");
                    WktWriter.AppendCoordinates(polygon.InteriorRings.First(), writer, true);

                    foreach (var ring in polygon.InteriorRings.Skip(1))
                    {
                        writer.Write(",");
                        WktWriter.AppendCoordinates(ring, writer, true);
                    }
                }

                writer.Write(")");
            }
        }
Beispiel #3
0
 /// <summary>
 /// Writes specified Geometry to the TextWriter in WKT format.
 /// </summary>
 /// <param name="geometry">The geometry to be written.</param>
 /// <param name="writer">The output Stream the Geometry will be written to.</param>
 protected static void Write(IGeometry geometry, TextWriter writer)
 {
     if (geometry is IPoint)
     {
         WktWriter.AppendPointTaggedText((IPoint)geometry, writer);
     }
     else if (geometry is ILineString)
     {
         WktWriter.AppendLineStringTaggedText((ILineString)geometry, writer);
     }
     else if (geometry is IPolygon)
     {
         WktWriter.AppendPolygonTaggedText((IPolygon)geometry, writer);
     }
     else if (geometry is IMultiPoint)
     {
         WktWriter.AppendMultiPointTaggedText((IMultiPoint)geometry, writer);
     }
     else if (geometry is IMultiLineString)
     {
         WktWriter.AppendMultiLineStringTaggedText((IMultiLineString)geometry, writer);
     }
     else if (geometry is IMultiPolygon)
     {
         WktWriter.AppendMultiPolygonTaggetText((IMultiPolygon)geometry, writer);
     }
     else if (geometry is IGeometryCollection <IGeometry> )
     {
         WktWriter.AppendGeometryCollectionTaggedText((IGeometryCollection <IGeometry>)geometry, writer);
     }
 }
Beispiel #4
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 #5
0
 /// <summary>
 /// Converts LineString's content to WKT and appends it to the output stream.
 /// </summary>
 /// <param name="linestring">The LineString to be converted.</param>
 /// <param name="writer">The output Stream to Append WKT representation to.</param>
 private static void AppendLineStringText(ILineString linestring, TextWriter writer)
 {
     if (linestring.Coordinates.Count == 0)
     {
         writer.Write("empty");
     }
     else
     {
         WktWriter.AppendCoordinates(linestring.Coordinates, writer, true);
     }
 }
Beispiel #6
0
 /// <summary>
 /// Converts Point's content to WKT format and appends it to the output stream.
 /// </summary>
 /// <param name="point">The Point to be converted.</param>
 /// <param name="writer">The output Stream to append WKT representation to.</param>
 private static void AppendPointText(IPoint point, TextWriter writer)
 {
     if (point.Position.Equals(Coordinate.Empty))
     {
         writer.Write("empty");
     }
     else
     {
         writer.Write("(");
         WktWriter.AppendCoordinate(point.Position, writer);
         writer.Write(")");
     }
 }
Beispiel #7
0
        /// <summary>
        /// Converts GeometryCollection to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="collection">The GeometryCollection be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendGeometryCollectionTaggedText(IGeometryCollection <IGeometry> collection, TextWriter writer)
        {
            writer.Write("geometrycollection ");

            string dimension = WktWriter.GetDimensionText(collection);

            if (string.IsNullOrEmpty(dimension) == false)
            {
                writer.Write(dimension);
                writer.Write(" ");
            }

            WktWriter.AppendGeometryCollectionText(collection, writer);
        }
Beispiel #8
0
        /// <summary>
        /// Converts LineString to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="linestring">The LineString to be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendLineStringTaggedText(ILineString linestring, TextWriter writer)
        {
            writer.Write("linestring ");

            string dimension = WktWriter.GetDimensionText(linestring);

            if (string.IsNullOrEmpty(dimension) == false)
            {
                writer.Write(dimension);
                writer.Write(" ");
            }

            WktWriter.AppendLineStringText(linestring, writer);
        }
Beispiel #9
0
        /// <summary>
        /// Converts Polygon to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="polygon">The Polygon to be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendPolygonTaggedText(IPolygon polygon, TextWriter writer)
        {
            writer.Write("polygon ");

            string dimension = WktWriter.GetDimensionText(polygon);

            if (string.IsNullOrEmpty(dimension) == false)
            {
                writer.Write(dimension);
                writer.Write(" ");
            }

            WktWriter.AppendPolygonText(polygon, writer);
        }
Beispiel #10
0
        /// <summary>
        /// Converts MultiPolygon to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="mp">The Multipolygon to be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendMultiPolygonTaggetText(IMultiPolygon mp, TextWriter writer)
        {
            writer.Write("multipolygon ");

            string dimension = WktWriter.GetDimensionText(mp);

            if (string.IsNullOrEmpty(dimension) == false)
            {
                writer.Write(dimension);
                writer.Write(" ");
            }

            WktWriter.AppendMultiPolygonText(mp, writer);
        }
Beispiel #11
0
        /// <summary>
        /// Converts MultiLineString to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="mls">The MultiLineString to be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendMultiLineStringTaggedText(IMultiLineString mls, TextWriter writer)
        {
            writer.Write("multilinestring ");

            string dimension = WktWriter.GetDimensionText(mls);

            if (string.IsNullOrEmpty(dimension) == false)
            {
                writer.Write(dimension);
                writer.Write(" ");
            }

            WktWriter.AppendMultiLineStringText(mls, writer);
        }
Beispiel #12
0
        /// <summary>
        /// Converts MultiPoint to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="multipoint">The MultiPoint to be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendMultiPointTaggedText(IMultiPoint multipoint, TextWriter writer)
        {
            writer.Write("multipoint ");

            string dimension = WktWriter.GetDimensionText(multipoint);

            if (string.IsNullOrEmpty(dimension) == false)
            {
                writer.Write(dimension);
                writer.Write(" ");
            }

            WktWriter.AppendMultiPointText(multipoint, writer);
        }
Beispiel #13
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 #14
0
        /// <summary>
        /// Converts MultiPolygon's content to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="multipolygon">The MultiPolygon to be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendMultiPolygonText(IMultiPolygon multipolygon, TextWriter writer)
        {
            if (multipolygon.Geometries.Count() == 0)
            {
                writer.Write("empty");
            }
            else
            {
                writer.Write("(");

                WktWriter.AppendPolygonText(multipolygon.Geometries.First(), writer);

                foreach (var polygon in multipolygon.Geometries.Skip(1))
                {
                    writer.Write(",");
                    WktWriter.AppendPolygonText(polygon, writer);
                }

                writer.Write(")");
            }
        }
Beispiel #15
0
        /// <summary>
        /// Converts MultiLineString's content to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="mls">The MultiLIneString to be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendMultiLineStringText(IMultiLineString mls, TextWriter writer)
        {
            if (mls.Geometries.Count() == 0)
            {
                writer.Write("empty");
            }
            else
            {
                writer.Write("(");

                WktWriter.AppendLineStringText(mls.Geometries.First(), writer);

                foreach (var linestring in mls.Geometries.Skip(1))
                {
                    writer.Write(",");
                    WktWriter.AppendLineStringText(linestring, writer);
                }

                writer.Write(")");
            }
        }
Beispiel #16
0
        /// <summary>
        /// Converts MultiPoint's content to WKT format and appends WKT representation to the output stream.
        /// </summary>
        /// <param name="multipoint">The MultiPoint to be converted.</param>
        /// <param name="writer">The output Stream to Append WKT representation to.</param>
        private static void AppendMultiPointText(IMultiPoint multipoint, TextWriter writer)
        {
            if (multipoint.Geometries.Count() == 0)
            {
                writer.Write("empty");
            }
            else
            {
                writer.Write("(");

                if (multipoint.Geometries.Count() > 0)
                {
                    WktWriter.AppendPointText(multipoint.Geometries.First(), writer);

                    foreach (var point in multipoint.Geometries.Skip(1))
                    {
                        writer.Write(",");
                        WktWriter.AppendPointText(point, writer);
                    }
                }

                writer.Write(")");
            }
        }
        public void Dispose_ClosesOutputStreamIfWritingToFiles()
        {
            string filename = "TestFiles\\wktwriter-closes-output-filestream-test.wkt";
            File.Delete(filename);

            WktWriterSettings settings = new WktWriterSettings();
            WktWriter target = new WktWriter(filename, settings);
            target.Dispose();

            FileStream testStream = null;
            Assert.DoesNotThrow(() => testStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite));
            testStream.Dispose();
        }
        public void Constructor_PathSettings_CreatesOutputFile()
        {
            string filename = "TestFiles\\wktwriter-constructor-creates-output-test.wkt";
            File.Delete(filename);

            WktWriterSettings settings = new WktWriterSettings();
            using (WktWriter target = new WktWriter(filename, settings)) {
                ;
            }

            Assert.True(File.Exists(filename));
        }
        public void Dispose_ClosesOutputStreamIfWritingToStream()
        {
            MemoryStream stream = new MemoryStream();

            WktWriter target = new WktWriter(stream, new WktWriterSettings());
            target.Dispose();

            Assert.False(stream.CanRead);
        }
        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);
            }
        }
Beispiel #21
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);
 }
 public void Construcotor_StreamSettings_SetsSettingsAndMakeThemReadOnly()
 {
     WktWriterSettings settings = new WktWriterSettings();
     using (WktWriter target = new WktWriter(new MemoryStream(), settings)) {
         Assert.Same(settings, target.Settings);
         Assert.True(settings.IsReadOnly);
     }
 }