Example #1
0
        public SubFileParameter(SubFileParameterBuilder subFileParameterBuilder, RepresentationConverter projection)
        {
            this.StartAddress      = subFileParameterBuilder.startAddress;
            this.IndexStartAddress = subFileParameterBuilder.indexStartAddress;
            this.SubFileSize       = subFileParameterBuilder.subFileSize;
            this.BaseZoomLevel     = subFileParameterBuilder.baseZoomLevel;
            this.ZoomLevelMin      = subFileParameterBuilder.zoomLevelMin;
            this.ZoomLevelMax      = subFileParameterBuilder.zoomLevelMax;

            // calculate the XY numbers of the boundary tiles in this sub-file
            var tile1 = projection.GeoPointToTile(subFileParameterBuilder.boundingBox.point1, this.BaseZoomLevel);
            var tile2 = projection.GeoPointToTile(subFileParameterBuilder.boundingBox.point2, this.BaseZoomLevel);

            this.BoundaryTileLeft   = tile1.TileX;
            this.BoundaryTileBottom = tile1.TileY;
            this.BoundaryTileRight  = tile2.TileX;
            this.BoundaryTileTop    = tile2.TileY;

            // calculate the horizontal and vertical amount of blocks in this sub-file
            this.BlocksWidth  = this.BoundaryTileRight - this.BoundaryTileLeft + 1;
            this.BlocksHeight = this.BoundaryTileBottom - this.BoundaryTileTop + 1;

            // calculate the total amount of blocks in this sub-file
            this.NumberOfBlocks = this.BlocksWidth * this.BlocksHeight;

            this.IndexEndAddress = this.IndexStartAddress + this.NumberOfBlocks * BytesPerIndexEntry;
        }
Example #2
0
        private void ReadSubFileParameters(BufferStream readBuffer, long fileSize, MapFileInfoBuilder mapFileInfoBuilder)
        {
            // get and check the number of sub-files (1 byte)
            byte numberOfSubFiles = (byte)readBuffer.ReadByte();

            if (numberOfSubFiles < 1)
            {
                throw new System.IO.InvalidDataException("invalid number of sub-files: " + numberOfSubFiles);
            }
            mapFileInfoBuilder.numberOfSubFiles = numberOfSubFiles;

            SubFileParameter[] tempSubFileParameters = new SubFileParameter[numberOfSubFiles];
            this.zoomLevelMinimum = byte.MaxValue;
            this.zoomLevelMaximum = byte.MinValue;

            // get and check the information for each sub-file
            for (byte currentSubFile = 0; currentSubFile < numberOfSubFiles; ++currentSubFile)
            {
                SubFileParameterBuilder subFileParameterBuilder = new SubFileParameterBuilder();

                // get and check the base zoom level (1 byte)
                byte baseZoomLevel = (byte)readBuffer.ReadByte();
                if (baseZoomLevel < 0 || baseZoomLevel > BASE_ZOOM_LEVEL_MAX)
                {
                    throw new System.IO.InvalidDataException("invalid base zooom level: " + baseZoomLevel);
                }
                subFileParameterBuilder.baseZoomLevel = baseZoomLevel;

                // get and check the minimum zoom level (1 byte)
                byte zoomLevelMin = (byte)readBuffer.ReadByte();
                if (zoomLevelMin < 0 || zoomLevelMin > 22)
                {
                    throw new System.IO.InvalidDataException("invalid minimum zoom level: " + zoomLevelMin);
                }
                subFileParameterBuilder.zoomLevelMin = zoomLevelMin;

                // get and check the maximum zoom level (1 byte)
                byte zoomLevelMax = (byte)readBuffer.ReadByte();
                if (zoomLevelMax < 0 || zoomLevelMax > 22)
                {
                    throw new System.IO.InvalidDataException("invalid maximum zoom level: " + zoomLevelMax);
                }
                subFileParameterBuilder.zoomLevelMax = zoomLevelMax;

                // check for valid zoom level range
                if (zoomLevelMin > zoomLevelMax)
                {
                    throw new System.IO.InvalidDataException("invalid zoom level range: " + zoomLevelMin + SPACE + zoomLevelMax);
                }

                // get and check the start address of the sub-file (8 bytes)
                long startAddress = readBuffer.ReadLong();
                if (startAddress < HEADER_SIZE_MIN || startAddress >= fileSize)
                {
                    throw new System.IO.InvalidDataException("invalid start address: " + startAddress);
                }
                subFileParameterBuilder.startAddress = startAddress;

                long indexStartAddress = startAddress;
                if (mapFileInfoBuilder.optionalFields.isDebugFile)
                {
                    // the sub-file has an index signature before the index
                    indexStartAddress += SIGNATURE_LENGTH_INDEX;
                }
                subFileParameterBuilder.indexStartAddress = indexStartAddress;

                // get and check the size of the sub-file (8 bytes)
                long subFileSize = readBuffer.ReadLong();
                if (subFileSize < 1)
                {
                    throw new System.IO.InvalidDataException("invalid sub-file size: " + subFileSize);
                }
                subFileParameterBuilder.subFileSize = subFileSize;

                subFileParameterBuilder.boundingBox = mapFileInfoBuilder.boundingBox;

                // add the current sub-file to the list of sub-files
                tempSubFileParameters[currentSubFile] = subFileParameterBuilder.build(mapFileInfoBuilder.Projection);

                updateZoomLevelInformation(tempSubFileParameters[currentSubFile]);
            }

            // create and fill the lookup table for the sub-files
            this.subFileParameters = new SubFileParameter[this.zoomLevelMaximum + 1];
            for (int currentMapFile = 0; currentMapFile < numberOfSubFiles; ++currentMapFile)
            {
                SubFileParameter subFileParameter = tempSubFileParameters[currentMapFile];
                for (byte zoomLevel = subFileParameter.ZoomLevelMin; zoomLevel <= subFileParameter.ZoomLevelMax; ++zoomLevel)
                {
                    this.subFileParameters[zoomLevel] = subFileParameter;
                }
            }
        }