public void GetLittleEndianUInt32()
        {
            _log.Debug("Running: GetLittleEndianUInt32");
            const UInt32 anInt   = 12345;
            UInt32       aNewInt = ByteEncoder.GetLittleEndian(anInt);

            Assert.IsTrue(anInt == ByteEncoder.GetLittleEndian(aNewInt));
        }
        public void GetLittleEndianlong()
        {
            _log.Debug("Running: GetLittleEndianlong");
            const long anInt   = 123456660700770;
            long       aNewInt = ByteEncoder.GetLittleEndian(anInt);

            Assert.IsTrue(anInt == ByteEncoder.GetLittleEndian(aNewInt));
        }
示例#3
0
 public void WriteHeader(BinaryWriter writer)
 {
     writer.Seek(0, SeekOrigin.Begin);
     writer.Write(ByteEncoder.GetBigEndian(ShapeFileConstants.HeaderStartCode));
     writer.Write(new Byte[20]);
     writer.Write(ByteEncoder.GetBigEndian(FileLengthInWords));
     writer.Write(ByteEncoder.GetLittleEndian(ShapeFileConstants.VersionCode));
     writer.Write(ByteEncoder.GetLittleEndian((Int32)ShapeType));
     writer.Write(ByteEncoder.GetLittleEndian(Extents.GetMin(Ordinates.X)));
     writer.Write(ByteEncoder.GetLittleEndian(Extents.GetMin(Ordinates.Y)));
     writer.Write(ByteEncoder.GetLittleEndian(Extents.GetMax(Ordinates.X)));
     writer.Write(ByteEncoder.GetLittleEndian(Extents.GetMax(Ordinates.Y)));
     writer.Write(new Byte[32]); // Z-values and M-values
 }
示例#4
0
        /// <summary>
        /// Reads and parses the header of the .shp index file
        /// </summary>
        /// <remarks>
        /// From ESRI ShapeFile Technical Description document
        ///
        /// http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf
        ///
        /// Byte
        /// Position    Field           Value       Type    Order
        /// -----------------------------------------------------
        /// Byte 0      File Code       9994        Integer Big
        /// Byte 4      Unused          0           Integer Big
        /// Byte 8      Unused          0           Integer Big
        /// Byte 12     Unused          0           Integer Big
        /// Byte 16     Unused          0           Integer Big
        /// Byte 20     Unused          0           Integer Big
        /// Byte 24     File Length     File Length Integer Big
        /// Byte 28     Version         1000        Integer Little
        /// Byte 32     Shape Type      Shape Type  Integer Little
        /// Byte 36     Bounding Box    Xmin        Double  Little
        /// Byte 44     Bounding Box    Ymin        Double  Little
        /// Byte 52     Bounding Box    Xmax        Double  Little
        /// Byte 60     Bounding Box    Ymax        Double  Little
        /// Byte 68*    Bounding Box    Zmin        Double  Little
        /// Byte 76*    Bounding Box    Zmax        Double  Little
        /// Byte 84*    Bounding Box    Mmin        Double  Little
        /// Byte 92*    Bounding Box    Mmax        Double  Little
        ///
        /// * Unused, with value 0.0, if not Measured or Z type
        ///
        /// The "Integer" type corresponds to the CLS Int32 type, and "Double" to CLS Double (IEEE 754).
        /// </remarks>
        private void parseHeader(BinaryReader reader)
        {
            reader.BaseStream.Seek(0, SeekOrigin.Begin);

            // Check file header
            if (ByteEncoder.GetBigEndian(reader.ReadInt32()) != ShapeFileConstants.HeaderStartCode)
            {
                throw new ShapeFileIsInvalidException("Invalid ShapeFile (.shp)");
            }

            // Seek to File Length
            reader.BaseStream.Seek(24, 0);

            // Read filelength as big-endian. The length is number of 16-bit words in file
            FileLengthInWords = ByteEncoder.GetBigEndian(reader.ReadInt32());

            // Seek to ShapeType
            reader.BaseStream.Seek(32, 0);
            ShapeType = (ShapeType)reader.ReadInt32();

            // Seek to bounding box of shapefile
            reader.BaseStream.Seek(36, 0);

            // Read the spatial bounding box of the contents
            Double xMin = ByteEncoder.GetLittleEndian(reader.ReadDouble());
            Double yMin = ByteEncoder.GetLittleEndian(reader.ReadDouble());
            Double xMax = ByteEncoder.GetLittleEndian(reader.ReadDouble());
            Double yMax = ByteEncoder.GetLittleEndian(reader.ReadDouble());

            ICoordinate min = _geoFactory.CoordinateFactory.Create(xMin, yMin);
            ICoordinate max = _geoFactory.CoordinateFactory.Create(xMax, yMax);

            Extents = min.Equals(max) && min.Equals(_geoFactory.CoordinateFactory.Create(0, 0)) //jd: if the shapefile has just been created the box wil be 0,0,0,0 in this case create an empty extents
                ? _geoFactory.CreateExtents()
                : _geoFactory.CreateExtents(min, max);


            //jd:allow exmpty extents
            //if (Extents.IsEmpty)
            //{
            //    Extents = null;
            //}
        }