Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="recordCount"></param>
        public static void WriteDummyDbf(string filename, int recordCount)
        {
            DbaseFileHeader dbfHeader = new DbaseFileHeader();
            dbfHeader.AddColumn("Description",'C', 20, 0);

            DbaseFileWriter dbfWriter = new DbaseFileWriter(filename);
            dbfWriter.Write(dbfHeader);
            for (int i = 0; i < recordCount; i++)
            {
                ArrayList columnValues = new ArrayList();
                columnValues.Add((double) i);
                dbfWriter.Write(columnValues);
            }
            dbfWriter.Close();
        }
Example #2
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!");
            }

            // 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);
                }
            }

            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(shpFile, 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 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="recordCount"></param>
        public static void WriteDummyDbf(string filename, int recordCount)
        {
            DbaseFileHeader dbfHeader = new DbaseFileHeader();

            dbfHeader.AddColumn("Description", 'C', 20, 0);

            DbaseFileWriter dbfWriter = new DbaseFileWriter(filename);

            dbfWriter.Write(dbfHeader);
            for (int i = 0; i < recordCount; i++)
            {
                ArrayList columnValues = new ArrayList();
                columnValues.Add((double)i);
                dbfWriter.Write(columnValues);
            }
            dbfWriter.Close();
        }