public void Add(NodeWayBundle nodeWayBundle)
 {
     this.nodes.AddRange(nodeWayBundle.Nodes);
     this.ways.AddRange(nodeWayBundle.Ways);
 }
Exemple #2
0
        private MapReadResult processBlocks(QueryParameters queryParameters, SubFileParameter subFileParameter)
        {
            bool queryIsWater       = true;
            bool queryReadWaterInfo = false;

            MapReadResultBuilder mapReadResultBuilder = new MapReadResultBuilder();

            // read and process all blocks from top to bottom and from left to right
            for (long row = queryParameters.fromBlockY; row <= queryParameters.toBlockY; ++row)
            {
                for (long column = queryParameters.fromBlockX; column <= queryParameters.toBlockX; ++column)
                {
                    // calculate the actual block number of the needed block in the file
                    long blockNumber = row * subFileParameter.BlocksWidth + column;

                    // get the current index entry
                    long currentBlockIndexEntry = this.databaseIndexCache.getIndexEntry(subFileParameter, blockNumber);

                    // check if the current query would still return a water tile
                    if (queryIsWater)
                    {
                        // check the water flag of the current block in its index entry
                        queryIsWater      &= (currentBlockIndexEntry & BITMASK_INDEX_WATER) != 0;
                        queryReadWaterInfo = true;
                    }

                    // get and check the current block pointer
                    long currentBlockpointer = currentBlockIndexEntry & BITMASK_INDEX_OFFSET;
                    if (currentBlockpointer < 1 || currentBlockpointer > subFileParameter.SubFileSize)
                    {
                        System.Diagnostics.Debug.WriteLine("invalid current block pointer: " + currentBlockpointer);
                        System.Diagnostics.Debug.WriteLine("subFileSize: " + subFileParameter.SubFileSize);
                        return(null);
                    }

                    long nextBlockpointer;
                    // check if the current block is the last block in the file
                    if (blockNumber + 1 == subFileParameter.NumberOfBlocks)
                    {
                        // set the next block pointer to the end of the file
                        nextBlockpointer = subFileParameter.SubFileSize;
                    }
                    else
                    {
                        // get and check the next block pointer
                        nextBlockpointer = this.databaseIndexCache.getIndexEntry(subFileParameter, blockNumber + 1)
                                           & BITMASK_INDEX_OFFSET;
                        if (nextBlockpointer > subFileParameter.SubFileSize)
                        {
                            System.Diagnostics.Debug.WriteLine("invalid next block pointer: " + nextBlockpointer);
                            System.Diagnostics.Debug.WriteLine("sub-file size: " + subFileParameter.SubFileSize);
                            return(null);
                        }
                    }

                    // calculate the size of the current block
                    int currentBlockSize = (int)(nextBlockpointer - currentBlockpointer);
                    if (currentBlockSize < 0)
                    {
                        System.Diagnostics.Debug.WriteLine("current block size must not be negative: " + currentBlockSize);
                        return(null);
                    }
                    else if (currentBlockSize == 0)
                    {
                        // the current block is empty, continue with the next block
                        continue;
                    }
                    else if (currentBlockSize > BufferStream.MAXIMUM_BUFFER_SIZE)
                    {
                        // the current block is too large, continue with the next block
                        System.Diagnostics.Debug.WriteLine("current block size too large: " + currentBlockSize);
                        continue;
                    }
                    else if (currentBlockpointer + currentBlockSize > this.fileSize)
                    {
                        System.Diagnostics.Debug.WriteLine("current block largher than file size: " + currentBlockSize);
                        return(null);
                    }

                    // seek to the current block in the map file
                    this.inputFile.Seek(subFileParameter.StartAddress + currentBlockpointer, SeekOrigin.Begin);

                    // read the current block into the buffer
                    if (!this.readBuffer.ReadFromFile(currentBlockSize))
                    {
                        // skip the current block
                        System.Diagnostics.Debug.WriteLine("reading current block has failed: " + currentBlockSize);
                        return(null);
                    }

                    // calculate the top-left coordinates of the underlying tile
                    this.tile = new Tile(
                        subFileParameter.BoundaryTileLeft + column,
                        subFileParameter.BoundaryTileTop + row,
                        subFileParameter.BaseZoomLevel,
                        Projection.TileSize
                        );
                    this.tilePosition = Projection.MappointToGeoPoint(tile.MapPoint1);

                    try {
                        NodeWayBundle nodeWayBundle = ProcessBlock(queryParameters, subFileParameter);
                        mapReadResultBuilder.Add(nodeWayBundle);
                    } catch (IndexOutOfRangeException e) {
                        System.Diagnostics.Debug.WriteLine(e.Message);
                    }
                }
            }

            // the query is finished, was the water flag set for all blocks?
            if (queryIsWater && queryReadWaterInfo)
            {
                mapReadResultBuilder.isWater = true;
            }

            return(mapReadResultBuilder.build());
        }