// Get an OSM tag for a given key (or return empty string if none) // Called from Lua string Find(const string& key) const { // First, convert the string into a number if (tagMap.find(key) == tagMap.end()) { return ""; } uint keyNum = tagMap.at(key); if (isWay) { // Then see if this number is in the way tags, and return its value if so for (uint n=0; n < tagLength; n++) { if (keysPtr->Get(n)==keyNum) { return stringTable[valsPtr->Get(n)]; } } } else { for (uint n=denseStart; n<denseEnd; n+=2) { if (densePtr->keys_vals(n)==keyNum) { return stringTable[densePtr->keys_vals(n+1)]; } } } return ""; }
// Check if there's a value for a given key // Called from Lua bool Holds(const string& key) const { if (tagMap.find(key) == tagMap.end()) { return false; } uint keyNum = tagMap.at(key); if (isWay) { for (uint n=0; n > tagLength; n++) { if (keysPtr->Get(n)==keyNum) { return true; } } } else { for (uint n=denseStart; n<denseEnd; n+=2) { if (densePtr->keys_vals(n)==keyNum) { return true; } } } return false; }
void PbfReader::_loadDenseNodes(const DenseNodes& dn) { int size = std::min(dn.id_size(), std::min(dn.lat_size(), dn.lon_size())); if (dn.id_size() != dn.lat_size() || dn.id_size() != dn.lon_size()) { LOG_WARN("Dense node list sizes are not equal."); } vector< shared_ptr<hoot::Node> > nodes; nodes.reserve(size); // the file uses delta encoding long lon = 0; long lat = 0; long id = 0; for (int i = 0; i < size; i++) { id += dn.id().Get(i); lon += dn.lon().Get(i); lat += dn.lat().Get(i); long newId = _getNodeId(id); double x = _convertLon(lon); double y = _convertLat(lat); shared_ptr<Node> n(new hoot::Node(_status, newId, x, y, _circularError)); nodes.push_back(n); if (_map->containsNode(newId)) { LOG_WARN("Map already contains node: " << newId); } _map->addNode(n); } int index = 0; int kv = 0; QString k, v; for (int i = 0; i < dn.keys_vals_size(); i++) { int sid = dn.keys_vals().Get(i); if (sid == 0) { index++; kv = 0; } else { QString str = _strings[sid]; if (kv == 0) { k = str; kv = 1; } else { v = str; _addTag(nodes[index], k, v); kv = 0; } } } if (dn.has_denseinfo()) { const DenseInfo& di = dn.denseinfo(); int timestampSize = di.timestamp_size(); if (timestampSize != size) { LOG_WARN("Dense info timestamp size doesn't match other node counts"); timestampSize = std::min(size, timestampSize); } if (_addSourceDateTime) { long timestamp = 0; for (int i = 0; i < timestampSize; i++) { timestamp += di.timestamp().Get(i) * _dateGranularity; if (timestamp != 0 && nodes[i]->getTags().getInformationCount() > 0) { QDateTime dt = QDateTime::fromMSecsSinceEpoch(timestamp).toTimeSpec(Qt::UTC); QString dts = dt.toString("yyyy-MM-ddThh:mm:ss.zzzZ"); nodes[i]->setTag("source:datetime", dts); } } } } }