Example #1
0
        /// <summary>
        /// Writes the specified feature collection.
        /// </summary>
        /// <param name="featureCollection">The feature collection.</param>
        public void Write(IList featureCollection)
        {
            // Test if the Header is initialized
            if (Header == null)
            {
                throw new ApplicationException("Header must be set first!");
            }

#if DEBUG
            // Test if all elements of the collections are features
            foreach (object obj in featureCollection)
            {
                if (obj.GetType() != typeof(Feature))
                {
                    throw new ArgumentException("All the elements in the given collection must be " + typeof(Feature).Name);
                }
            }
#endif

            try
            {
                // Write shp and shx
                IGeometry[] geometries = new IGeometry[featureCollection.Count];
                int         index      = 0;
                foreach (Feature feature in featureCollection)
                {
                    geometries[index++] = feature.Geometry;
                }
                shapeWriter.Write(new GeometryCollection(geometries, geometryFactory));

                // Write dbf
                dbaseWriter.Write(Header);
                foreach (Feature feature in featureCollection)
                {
                    IAttributesTable attribs = feature.Attributes;
                    ArrayList        values  = new ArrayList();
                    for (int i = 0; i < Header.NumFields; i++)
                    {
                        values.Add(attribs[Header.Fields[i].Name]);
                    }
                    dbaseWriter.Write(values);
                }
            }
            finally
            {
                // Close dbf writer
                dbaseWriter.Close();
            }
        }
Example #2
0
 public void Close()
 {
     shapeWriter.Close();
     dbaseWriter.Close();
 }