Exemplo n.º 1
0
        /// <summary>
        /// Reads and validates the header block from the map file.
        /// </summary>
        /// <param name="readBuffer">
        ///            the ReadBuffer for the file data. </param>
        /// <param name="fileSize">
        ///            the size of the map file in bytes. </param>
        /// <exception cref="IOException">
        ///             if an error occurs while reading the file. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void readHeader(MapsforgeSharp.Reader.ReadBuffer readBuffer, long fileSize) throws java.io.IOException
        public virtual void ReadHeader(ReadBuffer readBuffer, long fileSize)
        {
            RequiredFields.ReadMagicByte(readBuffer);
            RequiredFields.ReadRemainingHeader(readBuffer);

            MapFileInfoBuilder mapFileInfoBuilder = new MapFileInfoBuilder();

            RequiredFields.readFileVersion(readBuffer, mapFileInfoBuilder);

            RequiredFields.ReadFileSize(readBuffer, fileSize, mapFileInfoBuilder);

            RequiredFields.ReadMapDate(readBuffer, mapFileInfoBuilder);

            RequiredFields.ReadBoundingBox(readBuffer, mapFileInfoBuilder);

            RequiredFields.ReadTilePixelSize(readBuffer, mapFileInfoBuilder);

            RequiredFields.ReadProjectionName(readBuffer, mapFileInfoBuilder);

            OptionalFields.ReadOptionalFields(readBuffer, mapFileInfoBuilder);

            RequiredFields.ReadPoiTags(readBuffer, mapFileInfoBuilder);

            RequiredFields.ReadWayTags(readBuffer, mapFileInfoBuilder);

            ReadSubFileParameters(readBuffer, fileSize, mapFileInfoBuilder);

            this.mapFileInfo = mapFileInfoBuilder.Build();
        }
Exemplo n.º 2
0
        private void ReadSubFileParameters(ReadBuffer readBuffer, long fileSize, MapFileInfoBuilder mapFileInfoBuilder)
        {
            sbyte numberOfSubFiles = readBuffer.ReadByte();

            mapFileInfoBuilder.numberOfSubFiles = numberOfSubFiles;

            var tempSubFileParameters = new SubFileParameter[numberOfSubFiles];

            zoomLevelMinimum = sbyte.MaxValue;
            zoomLevelMaximum = sbyte.MinValue;

            for (sbyte currentSubFile = 0; currentSubFile < numberOfSubFiles; ++currentSubFile)
            {
                var subFileParameterBuilder = new SubFileParameterBuilder();

                sbyte baseZoomLevel = readBuffer.ReadByte();
                subFileParameterBuilder.BaseZoomLevel = baseZoomLevel;

                sbyte zoomLevelMin = readBuffer.ReadByte();
                subFileParameterBuilder.ZoomLevelMin = zoomLevelMin;

                sbyte zoomLevelMax = readBuffer.ReadByte();
                subFileParameterBuilder.ZoomLevelMax = zoomLevelMax;

                long startAddress = readBuffer.ReadLong();
                subFileParameterBuilder.StartAddress = startAddress;

                long indexStartAddress = startAddress;
                subFileParameterBuilder.IndexStartAddress = indexStartAddress;

                long subFileSize = readBuffer.ReadLong();
                subFileParameterBuilder.SubFileSize = subFileSize;

                subFileParameterBuilder.BoundingBox = mapFileInfoBuilder.boundingBox;

                tempSubFileParameters[currentSubFile] = subFileParameterBuilder.Build();

                if (zoomLevelMinimum > tempSubFileParameters[currentSubFile].ZoomLevelMin)
                {
                    zoomLevelMinimum = tempSubFileParameters[currentSubFile].ZoomLevelMin;
                    mapFileInfoBuilder.zoomLevelMin = zoomLevelMinimum;
                }
                if (zoomLevelMaximum < tempSubFileParameters[currentSubFile].ZoomLevelMax)
                {
                    zoomLevelMaximum = tempSubFileParameters[currentSubFile].ZoomLevelMax;
                    mapFileInfoBuilder.zoomLevelMax = zoomLevelMaximum;
                }
            }

            subFileParameters = new SubFileParameter[zoomLevelMaximum + 1];
            for (int currentMapFile = 0; currentMapFile < numberOfSubFiles; ++currentMapFile)
            {
                var subFileParameter = tempSubFileParameters[currentMapFile];
                for (sbyte zoomLevel = subFileParameter.ZoomLevelMin; zoomLevel <= subFileParameter.ZoomLevelMax; ++zoomLevel)
                {
                    subFileParameters[zoomLevel] = subFileParameter;
                }
            }
        }
Exemplo n.º 3
0
        private void ReadSubFileParameters(ReadBuffer readBuffer, long fileSize, MapFileInfoBuilder mapFileInfoBuilder)
        {
            // get and check the number of sub-files (1 byte)
            sbyte numberOfSubFiles = readBuffer.ReadByte();

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

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

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

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

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

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

                // check for valid zoom level range
                if (zoomLevelMin > zoomLevelMax)
                {
                    throw new MapFileException("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 MapFileException("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 MapFileException("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();


                // update the global minimum and maximum zoom level information
                if (this.zoomLevelMinimum > tempSubFileParameters[currentSubFile].ZoomLevelMin)
                {
                    this.zoomLevelMinimum           = tempSubFileParameters[currentSubFile].ZoomLevelMin;
                    mapFileInfoBuilder.zoomLevelMin = this.zoomLevelMinimum;
                }
                if (this.zoomLevelMaximum < tempSubFileParameters[currentSubFile].ZoomLevelMax)
                {
                    this.zoomLevelMaximum           = tempSubFileParameters[currentSubFile].ZoomLevelMax;
                    mapFileInfoBuilder.zoomLevelMax = this.zoomLevelMaximum;
                }
            }

            // 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 (sbyte zoomLevel = subFileParameter.ZoomLevelMin; zoomLevel <= subFileParameter.ZoomLevelMax; ++zoomLevel)
                {
                    this.subFileParameters[zoomLevel] = subFileParameter;
                }
            }
        }