/// <summary> /// Loads a vertex and returns true if found. /// </summary> /// <param name="vertexId"></param> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> private bool LoadVertex(uint vertexId, out float latitude, out float longitude) { uint blockId = CHBlock.CalculateId(vertexId, _blockSize); CHBlock block; if (!_blocks.TryGet(blockId, out block)) { // damn block not cached! block = this.DeserializeBlock(blockId); if (block == null) { // oops even now the block is not found! longitude = 0; latitude = 0; return(false); } _blocks.Add(blockId, block); } uint blockIdx = vertexId - blockId; if (block.Vertices != null && blockIdx < block.Vertices.Length) { // block is found and the vertex is there! latitude = block.Vertices[blockIdx].Latitude; longitude = block.Vertices[blockIdx].Longitude; return(true); } // oops even now the block is not found! longitude = 0; latitude = 0; return(false); }
/// <summary> /// Loads all arcs but no shapes associated with the given vertex. /// </summary> /// <param name="vertexId"></param> /// <returns></returns> private KeyValuePair <uint, CHEdgeData>[] LoadArcsNoShapes(uint vertexId) { uint blockId = CHBlock.CalculateId(vertexId, _blockSize); CHBlock block; if (!_blocks.TryGet(blockId, out block)) { // damn block not cached! block = this.DeserializeBlock(blockId); if (block == null) { // oops even now the block is not found! return(new KeyValuePair <uint, CHEdgeData> [0]); } _blocks.Add(blockId, block); } uint blockIdx = vertexId - blockId; if (block.Vertices != null && blockIdx < block.Vertices.Length) { // block is found and the vertex is there! var arcs = new KeyValuePair <uint, CHEdgeData> [ block.Vertices[blockIdx].ArcCount]; for (int arcIdx = block.Vertices[blockIdx].ArcIndex; arcIdx < block.Vertices[blockIdx].ArcIndex + block.Vertices[blockIdx].ArcCount; arcIdx++) { // loop over all arcs. var chArc = block.Arcs[arcIdx]; var edgeData = new CHEdgeData(chArc.Value, chArc.Weight, chArc.Meta); arcs[arcIdx - block.Vertices[blockIdx].ArcIndex] = new KeyValuePair <uint, CHEdgeData>( chArc.TargetId, edgeData); } return(arcs); } // oops even now the block is not found! return(new KeyValuePair <uint, CHEdgeData> [0]); }
/// <summary> /// Loads the edge between the given vertices. /// </summary> /// <param name="vertex1"></param> /// <param name="vertex2"></param> /// <param name="data"></param> /// <returns></returns> private bool LoadArc(uint vertex1, uint vertex2, out CHEdgeData data) { uint blockId = CHBlock.CalculateId(vertex1, _blockSize); CHBlock block; if (!_blocks.TryGet(blockId, out block)) { // damn block not cached! block = this.DeserializeBlock(blockId); if (block == null) { // oops even now the block is not found! data = new CHEdgeData(); return(false); } _blocks.Add(blockId, block); } uint blockIdx = vertex1 - blockId; if (block.Vertices != null && blockIdx < block.Vertices.Length) { // block is found and the vertex is there! for (int arcIdx = block.Vertices[blockIdx].ArcIndex; arcIdx < block.Vertices[blockIdx].ArcIndex + block.Vertices[blockIdx].ArcCount; arcIdx++) { // loop over all arcs. var chArc = block.Arcs[arcIdx]; if (chArc.TargetId == vertex2) { data = new CHEdgeData(chArc.Value, chArc.Weight, chArc.Meta); return(true); } } } blockId = CHBlock.CalculateId(vertex2, _blockSize); if (!_blocks.TryGet(blockId, out block)) { // damn block not cached! block = this.DeserializeBlock(blockId); if (block == null) { // oops even now the block is not found! data = new CHEdgeData(); return(false); } _blocks.Add(blockId, block); } blockIdx = vertex2 - blockId; if (block.Vertices != null && blockIdx < block.Vertices.Length) { // block is found and the vertex is there! for (int arcIdx = block.Vertices[blockIdx].ArcIndex; arcIdx < block.Vertices[blockIdx].ArcIndex + block.Vertices[blockIdx].ArcCount; arcIdx++) { // loop over all arcs. var chArc = block.Arcs[arcIdx]; if (chArc.TargetId == vertex1) { data = new CHEdgeData(chArc.Value, chArc.Weight, chArc.Meta); return(true); } } } data = new CHEdgeData(); return(false); }
/// <summary> /// Loads the reverses for the given vertex. /// </summary> /// <param name="vertex"></param> /// <returns></returns> private uint[] LoadVertexReverses(uint vertex) { uint blockId = CHBlock.CalculateId(vertex, _blockSize); CHBlockReverse blockReverses; if (!_blockReverses.TryGet(blockId, out blockReverses)) { // damn block not cached! blockReverses = this.DeserializeReverse(blockId); if (blockReverses == null) { // oops even now the block is not found! return(new uint[0]); } _blockReverses.Add(blockId, blockReverses); uint blockIdx = vertex - blockId; var vertices = blockReverses.Vertices[blockIdx].Neighbours; if (vertices != null) { return(vertices); } } return(new uint[0]); }
/// <summary> /// Loads the edge between the given vertices. /// </summary> /// <param name="vertex1"></param> /// <param name="vertex2"></param> /// <param name="shape"></param> /// <returns></returns> private bool LoadArcShape(uint vertex1, uint vertex2, out ICoordinateCollection shape) { uint blockId = CHBlock.CalculateId(vertex1, _blockSize); CHBlockCoordinates blockCoordinates; if (!_blockShapes.TryGet(blockId, out blockCoordinates)) { // damn block not cached! blockCoordinates = this.DeserializeShape(blockId); if (blockCoordinates == null) { // oops even now the block is not found! shape = null; return(false); } _blockShapes.Add(blockId, blockCoordinates); } CHBlock block; if (!_blocks.TryGet(blockId, out block)) { // damn block not cached! block = this.DeserializeBlock(blockId); if (block == null) { // oops even now the block is not found! shape = null; return(false); } _blocks.Add(blockId, block); } uint blockIdx = vertex1 - blockId; if (block.Vertices != null && blockIdx < block.Vertices.Length) { // block is found and the vertex is there! for (int arcIdx = block.Vertices[blockIdx].ArcIndex; arcIdx < block.Vertices[blockIdx].ArcIndex + block.Vertices[blockIdx].ArcCount; arcIdx++) { // loop over all arcs. var chArc = block.Arcs[arcIdx]; if (chArc.TargetId == vertex2) { var arcCoordinates = blockCoordinates.Arcs[arcIdx]; shape = null; if (arcCoordinates.Coordinates != null) { shape = new CoordinateArrayCollection <GeoCoordinateSimple>(arcCoordinates.Coordinates); } return(true); } } } blockId = CHBlock.CalculateId(vertex2, _blockSize); if (!_blocks.TryGet(blockId, out block)) { // damn block not cached! block = this.DeserializeBlock(blockId); if (block == null) { // oops even now the block is not found! shape = null; return(false); } _blocks.Add(blockId, block); } if (!_blockShapes.TryGet(blockId, out blockCoordinates)) { // damn block not cached! blockCoordinates = this.DeserializeShape(blockId); if (blockCoordinates == null) { // oops even now the block is not found! shape = null; return(false); } _blockShapes.Add(blockId, blockCoordinates); } blockIdx = vertex2 - blockId; if (block.Vertices != null && blockIdx < block.Vertices.Length) { // block is found and the vertex is there! for (int arcIdx = block.Vertices[blockIdx].ArcIndex; arcIdx < block.Vertices[blockIdx].ArcIndex + block.Vertices[blockIdx].ArcCount; arcIdx++) { // loop over all arcs. var chArc = block.Arcs[arcIdx]; if (chArc.TargetId == vertex1) { var arcCoordinates = blockCoordinates.Arcs[arcIdx]; shape = null; if (arcCoordinates.Coordinates != null) { shape = new CoordinateArrayCollection <GeoCoordinateSimple>(arcCoordinates.Coordinates); } return(true); } } } shape = null; return(false); }