Ejemplo n.º 1
0
 /// <summary>
 /// Writes geometry to the output using specified writer.
 /// </summary>
 /// <param name="geometry">The geometry to write.</param>
 /// <param name="writer">The BinaryWriter used to write geometry to the output.</param>
 private static void Write(IGeometry geometry, BinaryWriter writer)
 {
     if (geometry is IPoint)
     {
         WkbWriter.WritePoint((IPoint)geometry, writer);
     }
     else if (geometry is ILineString)
     {
         WkbWriter.WriteLineString((ILineString)geometry, writer);
     }
     else if (geometry is IPolygon)
     {
         WkbWriter.WritePolygon((IPolygon)geometry, writer);
     }
     else if (geometry is IMultiPoint)
     {
         WkbWriter.WriteMultiPoint((IMultiPoint)geometry, writer);
     }
     else if (geometry is IMultiLineString)
     {
         WkbWriter.WriteMultiLineString((IMultiLineString)geometry, writer);
     }
     else if (geometry is IMultiPolygon)
     {
         WkbWriter.WriteMultiPolygon((IMultiPolygon)geometry, writer);
     }
     else if (geometry is IGeometryCollection <IGeometry> )
     {
         WkbWriter.WriteGeometryCollection((IGeometryCollection <IGeometry>)geometry, writer);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Writes GeometryCollection to the output using specified writer.
 /// </summary>
 /// <param name="collection">The GeometryCollection to write.</param>
 /// <param name="writer">The BinaryWriter used to write geometry to the output.</param>
 private static void WriteGeometryCollection(IGeometryCollection <IGeometry> collection, BinaryWriter writer)
 {
     writer.Write((uint)WkbWriter.AdjustGeometryType(collection, WkbGeometryType.GeometryCollection));
     writer.Write((uint)collection.Geometries.Count());
     foreach (var geometry in collection.Geometries)
     {
         WkbWriter.Write(geometry, writer);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Writes MultiPolygon to the output using specified writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to write.</param>
 /// <param name="writer">The BinaryWriter used to write geometry to the output.</param>
 private static void WriteMultiPolygon(IMultiPolygon multiPolygon, BinaryWriter writer)
 {
     writer.Write((uint)WkbWriter.AdjustGeometryType(multiPolygon, WkbGeometryType.MultiPolygon));
     writer.Write((uint)multiPolygon.Geometries.Count());
     foreach (var polygon in multiPolygon.Geometries)
     {
         WkbWriter.WritePolygonContent(polygon, writer);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Writes MultiLineString to the output using specified writer.
 /// </summary>
 /// <param name="multiLineString">The MultiLineString to write.</param>
 /// <param name="writer">The BinaryWriter used to write geometry to the output.</param>
 private static void WriteMultiLineString(IMultiLineString multiLineString, BinaryWriter writer)
 {
     writer.Write((uint)WkbWriter.AdjustGeometryType(multiLineString, WkbGeometryType.MultiLineString));
     writer.Write((uint)multiLineString.Geometries.Count());
     foreach (var linestring in multiLineString.Geometries)
     {
         WkbWriter.WriteCoordinates(linestring.Coordinates, writer);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Writes MultiPoint to the output using specified writer.
 /// </summary>
 /// <param name="multipoint">The MultiPoint to write.</param>
 /// <param name="writer">The BinaryWriter used to write geometry to the output.</param>
 private static void WriteMultiPoint(IMultiPoint multipoint, BinaryWriter writer)
 {
     writer.Write((uint)WkbWriter.AdjustGeometryType(multipoint, WkbGeometryType.MultiPoint));
     writer.Write((uint)multipoint.Geometries.Count());
     foreach (var point in multipoint.Geometries)
     {
         WkbWriter.WriteCoordinate(point.Position, writer);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Writes list of Coordinates to the output using specified writer.
        /// </summary>
        /// <param name="coordinates">The list od Coordinates to write.</param>
        /// <param name="writer">The BinaryWriter used to write geometry to the output.</param>
        private static void WriteCoordinates(ICoordinateList coordinates, BinaryWriter writer)
        {
            writer.Write((uint)coordinates.Count);

            for (int i = 0; i < coordinates.Count; i++)
            {
                WkbWriter.WriteCoordinate(coordinates[i], writer);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Writes specified Geometry in the WKB format to a binary arrray using default WkbWriterSettings.
        /// </summary>
        /// <param name="geometry">The geometry to write.</param>
        /// <returns>The binary array with WKB representation of the Geometry.</returns>
        public static byte[] WriteToArray(IGeometry geometry)
        {
            using (MemoryStream dataStream = new MemoryStream()) {
                using (BinaryWriter writer = new BinaryWriter(dataStream)) {
                    WkbWriterSettings defaultSettings = new WkbWriterSettings();

                    WkbWriter.WriteEncoding(writer, defaultSettings.Encoding);
                    WkbWriter.Write(geometry, writer);

                    return(dataStream.ToArray());
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Writes Point to the output using specified writer.
 /// </summary>
 /// <param name="point">The Point to write.</param>
 /// <param name="writer">The BinaryWriter used to write geometry to the output.</param>
 private static void WritePoint(IPoint point, BinaryWriter writer)
 {
     if (point.Position.Equals(Coordinate.Empty))
     {
         writer.Write((uint)WkbGeometryType.GeometryCollection);
         writer.Write(0u);
     }
     else
     {
         writer.Write((uint)WkbWriter.AdjustGeometryType(point, WkbGeometryType.Point));
         WkbWriter.WriteCoordinate(point.Position, writer);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Writes content of the Polygon to the output using specified writer.
        /// </summary>
        /// <param name="polygon">The Polygon to write.</param>
        /// <param name="writer">The BinaryWriter used to write geometry to the output.</param>
        private static void WritePolygonContent(IPolygon polygon, BinaryWriter writer)
        {
            if (polygon.ExteriorRing.Count == 0)
            {
                writer.Write(0u);
            }
            else
            {
                writer.Write((uint)(1 + polygon.InteriorRings.Count()));
                WkbWriter.WriteCoordinates(polygon.ExteriorRing, writer);

                foreach (var ring in polygon.InteriorRings)
                {
                    WkbWriter.WriteCoordinates(ring, writer);
                }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Writes Polygon to the output using specified writer.
 /// </summary>
 /// <param name="polygon">The Polygon to write.</param>
 /// <param name="writer">The BinaryWriter used to write geometry to the output.</param>
 private static void WritePolygon(IPolygon polygon, BinaryWriter writer)
 {
     writer.Write((uint)WkbWriter.AdjustGeometryType(polygon, WkbGeometryType.Polygon));
     WkbWriter.WritePolygonContent(polygon, writer);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Writes LineString to the output using specified writer.
 /// </summary>
 /// <param name="linestring">The LineString to write.</param>
 /// <param name="writer">The BinaryWriter used to write geometry to the output.</param>
 private static void WriteLineString(ILineString linestring, BinaryWriter writer)
 {
     writer.Write((uint)WkbWriter.AdjustGeometryType(linestring, WkbGeometryType.LineString));
     WkbWriter.WriteCoordinates(linestring.Coordinates, writer);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Writes specified Geometry in the WKB format to the output.
 /// </summary>
 /// <param name="geometry">The geometry to write.</param>
 public void Write(IGeometry geometry)
 {
     WkbWriter.WriteEncoding(_writer, this.Settings.Encoding);
     WkbWriter.Write(geometry, _writer);
 }