/// <summary>
 /// Writes an homogeneus <c>GometryCollection</c> into a binary shapefile.
 /// </summary>
 /// <param name="geometries">If geometries are not of the same type throws <c>System.ArgumentException</c>.</param>
 /// <param name="shapepath">Path of the shapefile to create: will be created a new file using the given path.
 /// if file exists throws <c>System.IO.IOException</c>.</param>        
 public void Write(GeometryCollection geometries, string shapepath)
 {
     using (Stream stream = new FileStream(shapepath, FileMode.CreateNew, FileAccess.Write, FileShare.None))
     {
         Write(geometries, stream);
     }
 }
        /// <summary>
        /// Writes an homogeneus <c>GometryCollection</c> into a binary stream.
        /// </summary>
        /// <param name="geometries"></param>
        /// <param name="stream"></param>
        protected void Write(GeometryCollection geometries, Stream stream)
        {
            if (!geometries.IsHomogeneous)
                throw new ArgumentException("Shapefile does contain only geometries of th esame type!");

            // Init counter
            recordCounter = 0;

            using (BigEndianBinaryWriter beWriter = new BigEndianBinaryWriter(stream))
            {
                using (BinaryWriter leWriter = new BinaryWriter(stream))
                {
                    // Evaluate stream length
                    int fileLength = 0;
                    foreach (Geometry geometry in geometries.Geometries)
                        fileLength += (shapeWriter.GetBytesLength(geometry) + 8);  // 12 is the length of record header
                    fileLength += 100;  // Add main header
                    WriteHeaderFile(geometries, leWriter, beWriter, (int)(fileLength / 2));     // Write length in 16 bit words!

                    foreach (Geometry geometry in geometries.Geometries)
                        Write(geometry, leWriter, beWriter);
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="geometries"></param>
        /// <param name="beWriter">Big Endian Writer</param>
        /// <param name="leWriter">Little Endian Endian Writer</param>
        /// <param name="streamLength"></param>
        protected void WriteHeaderFile(GeometryCollection geometries, BinaryWriter leWriter, BigEndianBinaryWriter beWriter, int streamLength)
        {
            // Write stub value for FileCode (big endian)
            beWriter.WriteIntBE((int) 9994);
            // Write stub values for unused (big endian)
            beWriter.WriteIntBE((int) 0);
            beWriter.WriteIntBE((int) 0);
            beWriter.WriteIntBE((int) 0);
            beWriter.WriteIntBE((int) 0);
            beWriter.WriteIntBE((int) 0);
            // Write stub value for Length (big endian)
            beWriter.WriteIntBE((int) streamLength);

            // Write version
            leWriter.Write((int) 1000);
            // Write ShapeTipe
            leWriter.Write((int) GetShapeType((Geometry) geometries.Geometries[0]));
            // Write values for boundingbox
            Envelope envelope = (Envelope) geometries.EnvelopeInternal;
            leWriter.Write((double) envelope.MinX);
            leWriter.Write((double) envelope.MinY);
            leWriter.Write((double) envelope.MaxX);
            leWriter.Write((double) envelope.MaxY);
            leWriter.Write((double) 0);
            leWriter.Write((double) 0);
            leWriter.Write((double) 0);
            leWriter.Write((double) 0);
        }
 /// <summary>
 /// Transforms a <see cref="GeometryCollection"/>.
 /// </summary>
 /// <param name="geoms">GeometryCollection to transform</param>
 /// <param name="transform">MathTransform</param>
 /// <returns>Transformed GeometryCollection</returns>
 public static IGeometryCollection TransformGeometryCollection(GeometryCollection geoms, IMathTransform transform)
 {
     List<IGeometry> coll = new List<IGeometry>(geoms.Geometries.Length);
     foreach (IGeometry g in geoms.Geometries)
         coll.Add(TransformGeometry(g, transform));
     return new GeometryCollection(coll.ToArray());
 }