private void ProcessNode(PrimitiveBlock block, Formats.Pbf.Node node) { var latitude = .000000001 * (block.lat_offset + (block.granularity * (double)node.lat)); var longitude = .000000001 * (block.lon_offset + (block.granularity * (double)node.lon)); var elementNode = new Entities.Node(); elementNode.Id = node.id; elementNode.Coordinate = new GeoCoordinate(latitude, longitude); if (node.keys.Any()) { elementNode.Tags = new TagCollection(node.keys.Count); for (int tagIdx = 0; tagIdx < node.keys.Count; tagIdx++) { var keyBytes = block.stringtable.s[(int)node.keys[tagIdx]]; string key = Encoding.UTF8.GetString(keyBytes, 0, keyBytes.Length); var valueBytes = block.stringtable.s[(int)node.vals[tagIdx]]; string value = Encoding.UTF8.GetString(valueBytes, 0, valueBytes.Length); //if (elementNode.Tags.ContainsKey(key)) // continue; elementNode.Tags.Add(key, value); } } _envelop.Extend(elementNode.Coordinate); _context.Builder.ProcessNode(elementNode, node.keys.Count); }
/// <summary> /// Processes primitive block /// </summary> private void ProcessPrimitiveBlock(PrimitiveBlock block) { if (block.primitivegroup != null) { foreach (PrimitiveGroup primitivegroup in block.primitivegroup) { if (primitivegroup.dense != null) { int keyValsIdx = 0; long currentId = 0; long currentLat = 0; long currentLon = 0; var count = primitivegroup.dense.id.Count; var nodes = new List <Formats.Pbf.Node>(); for (int idx = 0; idx < count; idx++) { // do the delta decoding stuff. currentId = currentId + primitivegroup.dense.id[idx]; currentLat = currentLat + primitivegroup.dense.lat[idx]; currentLon = currentLon + primitivegroup.dense.lon[idx]; var node = new Formats.Pbf.Node { id = currentId, lat = currentLat, lon = currentLon }; // get the keys/vals. List <int> keysVals = primitivegroup.dense.keys_vals; var keysValsCount = keysVals.Count; node.Initialize(); while (keysValsCount > keyValsIdx && keysVals[keyValsIdx] != 0) { node.keys.Add((uint)keysVals[keyValsIdx]); keyValsIdx++; node.vals.Add((uint)keysVals[keyValsIdx]); keyValsIdx++; } keyValsIdx++; nodes.Add(node); } primitivegroup.nodes = nodes; } } } }