예제 #1
0
        private NodeWayBundle ProcessBlock(QueryParameters queryParameters, SubFileParameter subFileParameter)
        {
            if (!processBlockSignature())
            {
                return(null);
            }

            ZoomTable zoomTable = readZoomTable(subFileParameter);

            if (zoomTable == null)
            {
                return(null);
            }
            int zoomTableRow          = queryParameters.queryZoomLevel - subFileParameter.ZoomLevelMin;
            int nodesOnQueryZoomLevel = zoomTable[zoomTableRow].NodesCount;
            int waysOnQueryZoomLevel  = zoomTable[zoomTableRow].WaysCount;

            // get the relative offset to the first stored way in the block
            long firstWayOffset = this.readBuffer.ReadUnsignedInt();

            if (firstWayOffset < 0)
            {
                return(null);
            }

            // add the current buffer position to the relative first way offset
            firstWayOffset += this.readBuffer.Position;
            if (firstWayOffset > this.readBuffer.Length)
            {
                return(null);
            }

            List <Node> nodes = processNodes(nodesOnQueryZoomLevel);

            if (nodes == null)
            {
                return(null);
            }

            // finished reading nodes, check if the current buffer position is valid
            if (this.readBuffer.Position > firstWayOffset)
            {
                return(null);
            }

            // move the pointer to the first way
            this.readBuffer.Position = firstWayOffset;

            List <Way> ways = processWays(queryParameters, waysOnQueryZoomLevel);

            if (ways == null)
            {
                return(null);
            }

            return(new NodeWayBundle(this.tile, nodes, ways));
        }
예제 #2
0
        private ZoomTable readZoomTable(SubFileParameter subFileParameter)
        {
            int       rows      = subFileParameter.ZoomLevelMax - subFileParameter.ZoomLevelMin + 1;
            ZoomTable zoomTable = new ZoomTable(rows);

            int cumulatedNumberOfnodes = 0;
            int cumulatedNumberOfWays  = 0;

            for (int row = 0; row < rows; ++row)
            {
                cumulatedNumberOfnodes += this.readBuffer.ReadUnsignedInt();
                cumulatedNumberOfWays  += this.readBuffer.ReadUnsignedInt();

                if (cumulatedNumberOfnodes < 0 || cumulatedNumberOfnodes > MAXIMUM_ZOOM_TABLE_OBJECTS)
                {
                    System.Diagnostics.Debug.WriteLine("invalid cumulated number of nodes in row " + row + ' ' + cumulatedNumberOfnodes);
                    if (this.mapFileHeader.MapFileInfo.DebugFile)
                    {
                        System.Diagnostics.Debug.WriteLine(DEBUG_SIGNATURE_BLOCK + this.signatureBlock);
                    }
                    return(null);
                }
                else if (cumulatedNumberOfWays < 0 || cumulatedNumberOfWays > MAXIMUM_ZOOM_TABLE_OBJECTS)
                {
                    System.Diagnostics.Debug.WriteLine("invalid cumulated number of ways in row " + row + ' ' + cumulatedNumberOfWays);
                    if (this.mapFileHeader.MapFileInfo.DebugFile)
                    {
                        System.Diagnostics.Debug.WriteLine(DEBUG_SIGNATURE_BLOCK + this.signatureBlock);
                    }
                    return(null);
                }

                zoomTable[row] = new ZoomTable.ZoomTableEntry(cumulatedNumberOfnodes, cumulatedNumberOfWays);
            }

            return(zoomTable);
        }