/// <summary> /// Dekodiert die Werte aus einem PBF-Stream /// </summary> /// <param name="buf">Buffer, worraus die Werte gelesen werden sollen</param> /// <param name="ofs">Startposition innerhalb des Buffers</param> /// <param name="box">BBox-Struktur mit den ausgelesenen Werten</param> /// <returns>Anzahl der gelesenen Bytes aus dem Buffer</returns> public static int Decode(byte[] buf, int ofs, out HeaderBBox box) { /***** * message HeaderBBox * { * required sint64 left = 1; * required sint64 right = 2; * required sint64 top = 3; * required sint64 bottom = 4; * } *****/ box = new HeaderBBox(); ulong tmp; int len = ProtoBuf.ReadVarInt(buf, ofs, out tmp); int endLen = len + (int)tmp; // --- required sint64 left = 1; --- if (buf[ofs + len++] != (1 << 3 | 0)) { throw new PbfParseException(); } len += ProtoBuf.ReadVarInt(buf, ofs + len, out tmp); box.left = ProtoBuf.SignedInt64(tmp); // --- required sint64 right = 2; --- if (buf[ofs + len++] != (2 << 3 | 0)) { throw new PbfParseException(); } len += ProtoBuf.ReadVarInt(buf, ofs + len, out tmp); box.right = ProtoBuf.SignedInt64(tmp); // --- required sint64 top = 3; --- if (buf[ofs + len++] != (3 << 3 | 0)) { throw new PbfParseException(); } len += ProtoBuf.ReadVarInt(buf, ofs + len, out tmp); box.top = ProtoBuf.SignedInt64(tmp); // --- required sint64 bottom = 4; --- if (buf[ofs + len++] != (4 << 3 | 0)) { throw new PbfParseException(); } len += ProtoBuf.ReadVarInt(buf, ofs + len, out tmp); box.bottom = ProtoBuf.SignedInt64(tmp); if (len != endLen) { throw new PbfParseException(); } return(len); }
static void DecodeNodeBlock(byte[] buf, int bufLen) { long id = 0; long pos = 0; var keyDict = new Dictionary <string, int>(); var valDict = new Dictionary <string, int>(); var outputNodes = new List <DecodeNodeBlockValue>(); var outputValues = new List <int>(); for (int p = 0; p < bufLen;) { DecodeNodeBlockValue nodeValue; ulong tmp; p += ProtoBuf.ReadVarInt(buf, p, out tmp); id += ProtoBuf.SignedInt64(tmp); nodeValue.id = id; p += ProtoBuf.ReadVarInt(buf, p, out tmp); pos += ProtoBuf.SignedInt64(tmp); nodeValue.pos = pos; p += ProtoBuf.ReadVarInt(buf, p, out tmp); int valueCount = (int)(uint)tmp; nodeValue.valueCount = valueCount; nodeValue.valuePos = outputValues.Count / 2; for (int i = 0; i < valueCount; i++) { string key, val; p += ProtoBuf.ReadString(buf, p, out key); if (!keyDict.ContainsKey(key)) { keyDict.Add(key, keyDict.Count); } outputValues.Add(keyDict[key]); p += ProtoBuf.ReadString(buf, p, out val); if (!valDict.ContainsKey(val)) { valDict.Add(val, valDict.Count); } outputValues.Add(valDict[val]); } outputNodes.Add(nodeValue); } // --- sort --- long lastId = outputNodes[outputNodes.Count - 1].id; Console.WriteLine(" sort: " + outputNodes.Count + " nodes"); outputNodes.Sort((x, y) => x.pos.CompareTo(y.pos)); // --- write --- Console.WriteLine("write: " + outputNodes.Count + " nodes"); WriteNodeBlock(keyDict, valDict, outputValues, outputNodes, lastId); }
static void DecodeDelta(OsmWay[] ways) { for (int i = 1; i < ways.Length; i++) { var ids = ways[i].nodeIds; for (int n = 1; n < ids.Length; n++) { ids[n] = ProtoBuf.SignedInt64((ulong)ids[n]) + ids[n - 1]; } ways[i] = new OsmWay(ways[i].id + ways[i - 1].id, ways[i].values, ids); } }