Ejemplo n.º 1
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, IGeometryFactory geometryFactory)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException("geometryFactory");
            }

            _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, FileMode.Open, FileAccess.Read, FileShare.Read);
            BigEndianBinaryReader shpBinaryReader = new BigEndianBinaryReader(stream);

            _mainHeader = new ShapefileHeader(shpBinaryReader);
            shpBinaryReader.Close();
        }
Ejemplo n.º 2
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, IGeometryFactory geometryFactory)
		{           
			if (filename == null)
				throw new ArgumentNullException("filename");
			if (geometryFactory == null)
				throw new ArgumentNullException("geometryFactory");
			
            _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, FileMode.Open, FileAccess.Read, FileShare.Read);
			BigEndianBinaryReader shpBinaryReader = new BigEndianBinaryReader(stream);
			_mainHeader = new ShapefileHeader(shpBinaryReader);
			shpBinaryReader.Close();
		}
Ejemplo n.º 3
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing,
 /// releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _shpBinaryReader.Close();
 }
Ejemplo n.º 4
0
 public ArchiveParser(byte[] archive)
 {
     this.data = archive;
     archiveReader = new BigEndianBinaryReader(new MemoryStream(this.data));
     DecompressedSize = archiveReader.ReadUInt24();
     CompressedSize = archiveReader.ReadUInt24();
     if (CompressedSize != DecompressedSize)
     {
         byte[] input = new byte[DecompressedSize - 6];
         Array.Copy(this.data, 6, input, 0, DecompressedSize - 6);
         byte[] dec = new byte[DecompressedSize - 6];
         BZip2.Decompress(new MemoryStream(input), new MemoryStream(dec), true);
         finalBuffer = dec;
         archiveReader.Close();
         archiveReader = new BigEndianBinaryReader(new MemoryStream(finalBuffer));
         compressedAsWhole = true;
     }
     else
     {
         finalBuffer = this.data;
         compressedAsWhole = false;
     }
     totalFiles = archiveReader.ReadUInt16();
     int offset = 8 + totalFiles * 10;
     for (int i = 0; i < totalFiles; i++)
     {
         identifiers.Add(archiveReader.ReadInt32());
         decompressedSizes.Add(archiveReader.ReadUInt24());
         compressedSizes.Add(archiveReader.ReadUInt24());
         startOffsets.Add(offset);
         Logger.Log("Found file: " + identifiers[i] + " at " + offset + ", size: " + compressedSizes[i], LogType.Success);
         offset += compressedSizes[i];
         files.Add(getFileAt(i));
     }
 }