public ShapefileDataReader(IStreamProviderRegistry streamProviderRegistry, IGeometryFactory geometryFactory)
        {
            if (streamProviderRegistry==null)
                throw new ArgumentNullException("streamProviderRegistry");
            if (geometryFactory == null)
                throw new ArgumentNullException("geometryFactory");
            _open = true;

            _dbfReader = new DbaseFileReader(streamProviderRegistry);
            _shpReader = new ShapefileReader(streamProviderRegistry, geometryFactory);

            _dbfHeader = _dbfReader.GetHeader();
            _recordCount = _dbfHeader.NumRecords;

            // copy dbase fields to our own array. Insert into the first position, the shape column
            _dbaseFields = new DbaseFieldDescriptor[_dbfHeader.Fields.Length + 1];
            _dbaseFields[0] = DbaseFieldDescriptor.ShapeField();
            for (int i = 0; i < _dbfHeader.Fields.Length; i++)
                _dbaseFields[i + 1] = _dbfHeader.Fields[i];

            _shpHeader = _shpReader.Header;
            _dbfEnumerator = _dbfReader.GetEnumerator();
            _shpEnumerator = _shpReader.GetEnumerator();
            _moreRecords = true;
        }
        public ShapefileDataReader(IStreamProviderRegistry streamProviderRegistry, IGeometryFactory geometryFactory)
        {
            if (streamProviderRegistry == null)
            {
                throw new ArgumentNullException("streamProviderRegistry");
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException("geometryFactory");
            }
            _open = true;

            _dbfReader = new DbaseFileReader(streamProviderRegistry);
            _shpReader = new ShapefileReader(streamProviderRegistry, geometryFactory);

            _dbfHeader   = _dbfReader.GetHeader();
            _recordCount = _dbfHeader.NumRecords;

            // copy dbase fields to our own array. Insert into the first position, the shape column
            _dbaseFields    = new DbaseFieldDescriptor[_dbfHeader.Fields.Length + 1];
            _dbaseFields[0] = DbaseFieldDescriptor.ShapeField();
            for (int i = 0; i < _dbfHeader.Fields.Length; i++)
            {
                _dbaseFields[i + 1] = _dbfHeader.Fields[i];
            }

            _shpHeader     = _shpReader.Header;
            _dbfEnumerator = _dbfReader.GetEnumerator();
            _shpEnumerator = _shpReader.GetEnumerator();
            _moreRecords   = true;
        }
        /// <summary>
        /// Initializes a new instance of the ShapefileDataReader class.
        /// </summary>
        /// <param name="filename">The shapefile to read (minus the .shp extension)</param>
        ///<param name="geometryFactory">The GeometryFactory to use.</param>
        public ShapefileDataReader(string filename, IGeometryFactory geometryFactory)
        {
            if (String.IsNullOrEmpty(filename))
                throw new ArgumentNullException("filename");
            if (geometryFactory == null)
                throw new ArgumentNullException("geometryFactory");
            _open = true;

            string dbfFile = Path.ChangeExtension(filename, "dbf");
            _dbfReader = new DbaseFileReader(dbfFile);
            string shpFile = Path.ChangeExtension(filename, "shp");
            _shpReader = new ShapefileReader(shpFile, geometryFactory);

            _dbfHeader = _dbfReader.GetHeader();
            _recordCount = _dbfHeader.NumRecords;

            // copy dbase fields to our own array. Insert into the first position, the shape column
            _dbaseFields = new DbaseFieldDescriptor[_dbfHeader.Fields.Length + 1];
            _dbaseFields[0] = DbaseFieldDescriptor.ShapeField();
            for (int i = 0; i < _dbfHeader.Fields.Length; i++)
                _dbaseFields[i + 1] = _dbfHeader.Fields[i];

            _shpHeader = _shpReader.Header;
            _dbfEnumerator = _dbfReader.GetEnumerator();
            _shpEnumerator = _shpReader.GetEnumerator();
            _moreRecords = true;
        }
        private void TestSharcDbf()
        {
			const string filename = @"Strade.dbf";
            if (!File.Exists(filename))
                throw new FileNotFoundException(filename + " not found at " + Environment.CurrentDirectory);

            var reader = new DbaseFileReader(filename);
            var header = reader.GetHeader();
            Console.WriteLine("HeaderLength: " + header.HeaderLength);
            Console.WriteLine("RecordLength: " + header.RecordLength);
            Console.WriteLine("NumFields: " + header.NumFields);
            Console.WriteLine("NumRecords: " + header.NumRecords);            
            Console.WriteLine("LastUpdateDate: " + header.LastUpdateDate);
            foreach (var descr in header.Fields)
            {
                Console.WriteLine("FieldName: " + descr.Name);
                Console.WriteLine("DBF Type: " + descr.DbaseType);
                Console.WriteLine("CLR Type: " + descr.Type);
                Console.WriteLine("Length: " + descr.Length);
                Console.WriteLine("DecimalCount: " + descr.DecimalCount);                
                Console.WriteLine("DataAddress: " + descr.DataAddress);                
            }

            var ienum = reader.GetEnumerator();
            while (ienum.MoveNext())
            {
                var objs = (ArrayList)ienum.Current;
                foreach (var obj in objs)
                    Console.WriteLine(obj);                
            }
            Console.WriteLine();            
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DbaseFileEnumerator"/> class.
 /// </summary>
 /// <param name="parent"></param>
 public DbaseFileEnumerator(DbaseFileReader parent)
 {
     _parent = parent;
     var stream = IoManager.File.CreateFileStream(parent._filename, FileMode.Open, FileAccess.Read, FileShare.Read);
     _dbfStream = new BinaryReader(stream, parent._header.Encoding);
     ReadHeader();
 }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the ShapefileDataReader class.
        /// </summary>
        /// <param name="filename">The shapefile to read (minus the .shp extension)</param>
        ///<param name="geometryFactory">The GeometryFactory to use.</param>
        public ShapefileDataReader(string filename, IGeometryFactory geometryFactory)
        {
            if (String.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException("filename");
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException("geometryFactory");
            }
            _open = true;

            string dbfFile = Path.ChangeExtension(filename, "dbf");

            _dbfReader = new DbaseFileReader(dbfFile);
            string shpFile = Path.ChangeExtension(filename, "shp");

            _shpReader = new ShapefileReader(shpFile, geometryFactory);

            _dbfHeader   = _dbfReader.GetHeader();
            _recordCount = _dbfHeader.NumRecords;

            // copy dbase fields to our own array. Insert into the first position, the shape column
            _dbaseFields    = new DbaseFieldDescriptor[_dbfHeader.Fields.Length + 1];
            _dbaseFields[0] = DbaseFieldDescriptor.ShapeField();
            for (int i = 0; i < _dbfHeader.Fields.Length; i++)
            {
                _dbaseFields[i + 1] = _dbfHeader.Fields[i];
            }

            _shpHeader     = _shpReader.Header;
            _dbfEnumerator = _dbfReader.GetEnumerator();
            _shpEnumerator = _shpReader.GetEnumerator();
            _moreRecords   = true;
        }
Esempio n. 7
0
        public void ReadDbfDate()
        {            
            string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, 
                string.Format("..{0}..{0}..{0}NetTopologySuite.Samples.Shapefiles{0}date.dbf", Path.DirectorySeparatorChar));

            if (!File.Exists(file))
                throw new FileNotFoundException("file not found at " + Path.GetDirectoryName(file));
            
            DbaseFileReader reader = new DbaseFileReader(file);
            DbaseFileHeader header = reader.GetHeader();
            IEnumerator ienum = reader.GetEnumerator();
            ienum.MoveNext();            
            ArrayList items = ienum.Current as ArrayList;

            Assert.IsNotNull(items);
            Assert.AreEqual(2, items.Count);

            foreach (Object item in items)
                Assert.IsNotNull(item);

            DateTime date = (DateTime)items[1];

            Assert.AreEqual(10, date.Day);
            Assert.AreEqual(3, date.Month);
            Assert.AreEqual(2006, date.Year);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DbaseFileEnumerator"/> class.
 /// </summary>
 /// <param name="parent"></param>
 public DbaseFileEnumerator(DbaseFileReader parent)
 {
     _parent = parent;
     Stream stream = parent._streamProvider.OpenRead();
     _dbfStream = new BinaryReader(stream, parent._header.Encoding);
     ReadHeader();
 }
            /// <summary>
            /// Initializes a new instance of the <see cref="DbaseFileEnumerator"/> class.
            /// </summary>
            /// <param name="parent"></param>
            public DbaseFileEnumerator(DbaseFileReader parent)
            {
                _parent = parent;
                Stream stream = parent._streamProvider.OpenRead();

                _dbfStream = new BinaryReader(stream, parent._header.Encoding);
                ReadHeader();
            }
            /// <summary>
            /// Initializes a new instance of the <see cref="DbaseFileEnumerator"/> class.
            /// </summary>
            /// <param name="parent"></param>
            public DbaseFileEnumerator(DbaseFileReader parent)
            {
                _parent = parent;
                FileStream stream = new FileStream(parent._filename, FileMode.Open, FileAccess.Read, FileShare.Read);

                _dbfStream = new BinaryReader(stream, parent._header.Encoding);
                ReadHeader();
            }
Esempio n. 11
0
            /// <summary>
            /// Initializes a new instance of the <see cref="DbaseFileEnumerator"/> class.
            /// </summary>
            /// <param name="parent"></param>
            public DbaseFileEnumerator(DbaseFileReader parent)
            {
                _parent = parent;
                FileStream stream = new FileStream(parent._filename, FileMode.Open, FileAccess.Read, FileShare.Read);

                _dbfStream = new BinaryReader(stream, PlatformUtilityEx.GetDefaultEncoding());
                ReadHeader();
            }
            /// <summary>
            /// Initializes a new instance of the <see cref="DbaseFileEnumerator"/> class.
            /// </summary>
            /// <param name="parent"></param>
            public DbaseFileEnumerator(DbaseFileReader parent)
            {
                _isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication();

                _parent = parent;
                IsolatedStorageFileStream stream = new IsolatedStorageFileStream(parent._filename, FileMode.Open, FileAccess.Read, FileShare.Read, _isolatedStorageFile);
                _dbfStream = new BinaryReader(stream, PlatformUtilityEx.GetDefaultEncoding());
                ReadHeader();
            }
            /// <summary>
            /// Initializes a new instance of the <see cref="DbaseFileEnumerator"/> class.
            /// </summary>
            /// <param name="parent"></param>
            public DbaseFileEnumerator(DbaseFileReader parent)
            {
                _isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication();

                _parent = parent;
                IsolatedStorageFileStream stream = new IsolatedStorageFileStream(parent._filename, FileMode.Open, FileAccess.Read, FileShare.Read, _isolatedStorageFile);

                _dbfStream = new BinaryReader(stream, PlatformUtilityEx.GetDefaultEncoding());
                ReadHeader();
            }
Esempio n. 14
0
        public override void Open()
        {
            if (IsOpened)
                throw new Exception(string.Format("Cannot open before to close the resource {0}", Path));
            
            if (string.IsNullOrEmpty(Path))
                throw new Exception("Cannot open a null or empty path");

#if USE_SFDR
            reader = Shapefile.CreateDataReader(Path, new GeometryFactory());
            var s1 = reader.ShapeHeader;
            var h = reader.DbaseHeader;
#else

            var shpReader = new ShapefileReader(Path);
            shpProvider = shpReader.GetEnumerator();

            var dbfReader = new DbaseFileReader(IoManager.File.ChangeExtension(Path, ".dbf"));
            var h = dbfReader.GetHeader();
            dbfProvider = dbfReader.GetEnumerator();
#endif

            foreach (var f in h.Fields)
            {
                var lf = new LayerField();
                lf.Name = f.Name;

                switch (f.DbaseType)
                {
                    case 'L': // logical data type, one character (T,t,F,f,Y,y,N,n)
                        lf.FieldType = GisFieldType.GisFieldTypeBoolean;
                        break;
                    case 'C': // char or string
                        lf.FieldType = GisFieldType.GisFieldTypeString;
                        break;
                    case 'D': // date
                        lf.FieldType = GisFieldType.GisFieldTypeDate;
                        break;
                    case 'N': // numeric
                        if (f.DecimalCount > 0)
                            lf.FieldType = GisFieldType.GisFieldTypeFloat;
                        else
                            lf.FieldType = GisFieldType.GisFieldTypeNumber;
                        break;
                    case 'F': // double
                        lf.FieldType = GisFieldType.GisFieldTypeNumber;
                        break;
                    default:
                        throw new NotSupportedException("Do not know how to parse Field type " + f.DbaseType);
                      
                }

                Fields.Add(lf);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Initializes a new instance of the ShapefileDataReader class.
        /// </summary>
        /// <param name="filename">The shapefile to read (minus the .shp extension)</param>
        ///<param name="geometryFactory">The GeometryFactory to use.</param>
        public ShapefileDataReader(string filename, IGeometryFactory geometryFactory)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException("geometryFactory");
            }
            _open = true;

            if (filename.ToLower().EndsWith(".shp"))
            {
                filename = filename.ToLower().Replace(".shp", String.Empty);
            }

            _dbfReader = new DbaseFileReader(filename + ".dbf");
            _shpReader = new ShapefileReader(filename + ".shp", geometryFactory);

            _dbfHeader   = _dbfReader.GetHeader();
            _recordCount = _dbfHeader.NumRecords;

            // copy dbase fields to our own array. Insert into the first position, the shape column
            _dbaseFields    = new DbaseFieldDescriptor[_dbfHeader.Fields.Length + 1];
            _dbaseFields[0] = DbaseFieldDescriptor.ShapeField();
            for (int i = 0; i < _dbfHeader.Fields.Length; i++)
            {
                _dbaseFields[i + 1] = _dbfHeader.Fields[i];
            }

            _shpHeader     = _shpReader.Header;
            _dbfEnumerator = _dbfReader.GetEnumerator();
            _shpEnumerator = _shpReader.GetEnumerator();
            _moreRecords   = true;
        }