예제 #1
0
 public void Dispose()
 {
     if (_shpBinaryReader != null)
     {
         _shpBinaryReader.Close();
     }
 }
예제 #2
0
 public void Close()
 {
     if (!_isClosed)
     {
         _reader.Close();
         _isClosed = true;
     }
 }
예제 #3
0
 public bool MoveNext()
 {
     if (_shpBinaryReader.PeekChar() != -1)
     {
         int recordNumber  = _shpBinaryReader.ReadIntBE();
         int contentLength = _shpBinaryReader.ReadIntBE();
         if (Shapefile.TraceSwitch.Enabled)
         {
             Trace.WriteLine("Record number :" + recordNumber);
             Trace.WriteLine("contentLength :" + contentLength);
         }
         _geometry = _handler.Read(_shpBinaryReader, _parent._geometryFactory);
         return(true);
     }
     else
     {
         // reached end of file, so close the reader.
         _shpBinaryReader.Close();
         return(false);
     }
 }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the Shapefile class with the given parameters.
        /// </summary>
        /// <param name="filename">The filename of the shape file to read (with .shp).</param>
        /// <param name="geometryFactory">The GeometryFactory to use when creating Geometry objects.</param>
        public ShapefileReader(string filename, GeometryFactory geometryFactory)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException("geometryFactory");
            }
            _filename = filename;
            Trace.WriteLineIf(Shapefile.TraceSwitch.Enabled, "Reading filename:" + filename);

            _geometryFactory = geometryFactory;

            // read header information. note, we open the file, read the header information and then
            // close the file. This means the file is not opened again until GetEnumerator() is requested.
            // For each call to GetEnumerator() a new BinaryReader is created.
            FileStream            stream          = new FileStream(filename, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read);
            BigEndianBinaryReader shpBinaryReader = new BigEndianBinaryReader(stream);

            _mainHeader = new ShapefileHeader(shpBinaryReader);
            shpBinaryReader.Close();
        }
예제 #5
0
		/// <summary>
		/// Initializes a new instance of the Shapefile class with the given parameters.
		/// </summary>
		/// <param name="filename">The filename of the shape file to read (with .shp).</param>
		/// <param name="geometryFactory">The GeometryFactory to use when creating Geometry objects.</param>
		public ShapefileReader(string filename, GeometryFactory geometryFactory)
		{
			if (filename==null)
			{
				throw new ArgumentNullException("filename");
			}
			if (geometryFactory==null)
			{
				throw new ArgumentNullException("geometryFactory");
			}
			_filename = filename;
			Trace.WriteLineIf(Shapefile.TraceSwitch.Enabled,"Reading filename:"+filename);
			
			_geometryFactory = geometryFactory;

			// read header information. note, we open the file, read the header information and then
			// close the file. This means the file is not opened again until GetEnumerator() is requested.
			// For each call to GetEnumerator() a new BinaryReader is created.
			FileStream stream = new FileStream(filename, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read);
			BigEndianBinaryReader shpBinaryReader = new BigEndianBinaryReader(stream);
			_mainHeader = new ShapefileHeader(shpBinaryReader);
			shpBinaryReader.Close();
		}