void HasNotTagSelector::matchWay(WayId wayID, const shared_ptr<TileIdentifier>& ti, RenderAttributes* attributes) const { Way* way = geodata->getWay(wayID); auto entry = way->getTags().find(tag); if (entry == way->getTags().end() || entry->second == precached_no || entry->second == precached_false) { next->matchWay(wayID, ti, attributes); } }
static bool isChildOfArea(Feature *mapFeature) { Way* R = Way::GetSingleParentRoadInner(mapFeature); if (R) return (R->area() > 0.0); return false; }
void TagEqualsSelector::matchWay(WayId wayID, const shared_ptr<TileIdentifier>& ti, RenderAttributes* attributes) const { Way* way = geodata->getWay(wayID); auto entry = way->getTags().find(tag); if (entry != way->getTags().end() && entry->second == value) { next->matchWay(wayID, ti, attributes); } }
void HasTagSelector::matchWay(WayId wayID, const shared_ptr<TileIdentifier>& ti, RenderAttributes* attributes) const { Way* way = geodata->getWay(wayID); auto& map = way->getTags(); if (map.find(tag) != map.end()) { next->matchWay(wayID, ti, attributes); } }
void OSMDocument::test() { //Node* tn = this->FindNodeAt(39.7814771, 117.0522314); //Node* tn = this->FindNodeAt(39.7814111, 117.0482403); //Node* tn = this->FindNodeAt(39.8027487,116.7982348); Node* tn = this->FindNode( 2272249421 ); if ( tn == NULL ) { std::cout << "no node found" << std::endl; } else { tn->printstr(); } std::vector<Way*> ws = this->FindWaysWithRef( m_Ways, tn ); std::vector<Way*>::const_iterator it(ws.begin()); std::vector<Way*>::const_iterator last(ws.end()); while(it!=last) { Way* w = *it++; w->printstr(); } }
void ScaleInteraction::snapMousePressEvent(QMouseEvent * anEvent, Feature* aLast) { QList<Feature*> sel; if (view()->isSelectionLocked()) { if (theMain->properties()->selection(0)) sel.append(theMain->properties()->selection(0)); else sel.append(aLast); } else { sel = theMain->properties()->selection(); if (!sel.size() && aLast) sel.append(aLast); } Radius = 1.0; clearNoSnap(); Scaling.clear(); OriginalPosition.clear(); if (!sel.size()) return; view()->setInteracting(true); StartDragPosition = XY_TO_COORD(anEvent->pos()); OriginNode = NULL; NodeOrigin = false; CoordBox selBB = sel[0]->boundingBox(); for (int j=0; j<sel.size(); j++) { selBB.merge(sel[j]->boundingBox()); if (CHECK_WAY(sel[j])) { Way* R = STATIC_CAST_WAY(sel[j]); for (int i=0; i<R->size(); ++i) if (std::find(Scaling.begin(),Scaling.end(),R->get(i)) == Scaling.end()) Scaling.push_back(R->getNode(i)); addToNoSnap(R); } else if (CHECK_NODE(sel[j])) { if (!OriginNode && !NodeOrigin) { OriginNode = STATIC_CAST_NODE(sel[j]); NodeOrigin = true; } else { NodeOrigin = false; } } } if (Scaling.size() > 1) { if (NodeOrigin) { ScaleCenter = COORD_TO_XY(OriginNode->position()); } else { ScaleCenter = COORD_TO_XY(selBB.center()); } for (int i=0; i<Scaling.size(); ++i) { OriginalPosition.push_back(Scaling[i]->position()); addToNoSnap(Scaling[i]); } } else Scaling.clear(); }
void TagMatchesSelector::matchWay(WayId wayID, const shared_ptr<TileIdentifier>& ti, RenderAttributes* attributes) const { Way* way = geodata->getWay(wayID); auto entry = way->getTags().find(tag); if (entry != way->getTags().end()) { if (boost::regex_match(entry->second.str(), expression)) { next->matchWay(wayID, ti, attributes); } } }
int main() { Way wayNode; wayNode.SetId("123"); wayNode.SetName("jan"); AreaDataRepository::Instance().SetOnGoingWay(wayNode); std::cout << AreaDataRepository::Instance().GetOnGoingWay().GetId(); std::cin.get(); return 0; }
void LineSelector::matchWay(WayId wayID, const shared_ptr<TileIdentifier>& ti, RenderAttributes* attributes) const { Way* way = geodata->getWay(wayID); auto& nodes = way->getNodeIDs(); // (area is open) or (area is set and area == no) if (nodes.front() != nodes.back()) { next->matchWay(wayID, ti, attributes); } else { auto entry = way->getTags().find(precached_area); if (entry != way->getTags().end() && entry->second == precached_no) { next->matchWay(wayID, ti, attributes); } } }
/// Construct an Area object from a Way object. Area(const Way& way) : Object(way), m_node_list(way.nodes()), m_relation_member_list(), m_geos_geometry() { id(id() * 2); }
bool WayBufferFilter::isFiltered(const Way& w) const { try { bool result = true; shared_ptr<LineString> ls2 = ElementConverter(_map). convertToLineString(_map->getWay(w.getId())); if (fabs((w.getCircularError() + _buffer) - _bufferAccuracy) > 0.1) { _bufferAccuracy = w.getCircularError() + _buffer; _baseBuffered.reset(_baseLs->buffer(_bufferAccuracy, 3, geos::operation::buffer::BufferOp::CAP_ROUND)); _boundsPlus = *_baseBuffered->getEnvelopeInternal(); } if (ls2->getEnvelopeInternal()->intersects(_boundsPlus)) { shared_ptr<Geometry> g(_baseBuffered->intersection(ls2.get())); double ls2Length = ls2->getLength(); double ls2IntersectLength = g->getLength(); if (ls2IntersectLength / ls2Length >= _matchPercent) { shared_ptr<Geometry> ls2Buffer(ls2->buffer(_bufferAccuracy, 3, geos::operation::buffer::BufferOp::CAP_ROUND)); g.reset(ls2Buffer->intersection(_baseLs.get())); double ls1IntersectLength = g->getLength(); if (ls1IntersectLength / _baseLength >= _matchPercent) { result = false; } } } return result; } catch (geos::util::TopologyException& e) { LOG_WARN(ElementConverter(_map).convertToLineString(_map->getWay(w.getId()))); throw e; } }
void styleWays(const shared_ptr<std::vector<WayId> >& ids, RenderAttributes& attr) const { for (auto id : *ids) { Way* w = data->getWay(id); auto& tags = w->getTags(); auto name = tags.find(CachedString("name")); if (name != tags.end()) { auto style = styles.find(name->second); if (style != styles.end()) { Style* s = attr.getNewStyle(id); *s = style->second; } } } }
bool WayLocationProcessorFilter::Process(Progress& progress, const FileOffset& offset, Way& way, bool& /*save*/) { try { if (!way.GetType()->GetIndexAsPOI()) { return true; } NameFeatureValue *nameValue=nameReader->GetValue(way.GetFeatureValueBuffer()); if (nameValue==NULL) { return true; } LocationFeatureValue *locationValue=locationReader->GetValue(way.GetFeatureValueBuffer()); std::string name; std::string location; std::string address; name=nameValue->GetName(); if (locationValue!=NULL) { location=locationValue->GetLocation(); } writer.WriteFileOffset(offset); writer.WriteNumber(way.GetType()->GetWayId()); writer.Write(name); writer.Write(location); writer.Write(way.nodes); overallDataCount++; } catch (IOException& e) { progress.Error(e.GetDescription()); return false; } return true; }
/** * Ways can be ordered by id and version. * Note that we use the absolute value of the id for a * better ordering of objects with negative ids. */ inline bool operator<(const Way& lhs, const Way& rhs) { if (lhs.id() == rhs.id()) { return lhs.version() < rhs.version(); } else { return abs(lhs.id()) < abs(rhs.id()); } }
bool AbstractRoutingProfile::CanUseBackward(const Way& way) const { size_t index=way.GetType()->GetIndex(); if (index>=speeds.size() || speeds[index]<=0.0) { return false; } AccessFeatureValue *accessValue=accessReader.GetValue(way.GetFeatureValueBuffer()); if (accessValue!=NULL) { switch (vehicle) { case vehicleFoot: return accessValue->CanRouteFootBackward(); break; case vehicleBicycle: return accessValue->CanRouteBicycleBackward(); break; case vehicleCar: return accessValue->CanRouteCarBackward(); break; } } else { switch (vehicle) { case vehicleFoot: return way.GetType()->CanRouteFoot(); break; case vehicleBicycle: return way.GetType()->CanRouteBicycle(); break; case vehicleCar: return way.GetType()->CanRouteCar(); break; } } return false; }
bool WayTypeIgnoreProcessorFilter::Process(Progress& /*progress*/, const FileOffset& /*offset*/, Way& way, bool& save) { save=way.GetType()!=NULL && way.GetType()!=typeInfoIgnore; if (!save) { removedWaysCount++; } return true; }
void Map::StreetCollision(Node *node, Point M, int &insidePoints) { if (node == NULL) return; Point nodeCenter = node->GetCenter(); std::vector<long> adjacentWays = node->GetWays(); if (Tools::PointInsideCircle(M, nodeCenter, NODE_DIAMETER / 2)) { insidePoints++; for (int adjW = 0; adjW < adjacentWays.size(); adjW++) { int index = ways[adjacentWays[adjW]]->GetIndex(node); int size = ways[adjacentWays[adjW]]->GetNodes().size(); if ((index == 0 || index == size - 1) && insidePoints == 0) { Tools::UpdateIntersections(node->GetId()); } } return; } for (int adjW = 0; adjW < adjacentWays.size(); adjW++) { Way* adjacentWay = ways[adjacentWays[adjW]]; int nodeWayIndex = adjacentWay->GetIndex(node); Street *portionStreet = adjacentWay->GetPortionStreet(nodeWayIndex); if (portionStreet != NULL && Tools::PointInsideRectangle(M, portionStreet->corners[0], portionStreet->corners[1], portionStreet->corners[2], portionStreet->corners[3])) { if (insidePoints == 0) { if (currentWayName == NULL) { currentWayName = new char[70]; } strcpy(currentWayName, adjacentWay->GetName()); } insidePoints++; return; } portionStreet = adjacentWay->GetPortionStreet(nodeWayIndex - 1); if (portionStreet != NULL && Tools::PointInsideRectangle(M, portionStreet->corners[0], portionStreet->corners[1], portionStreet->corners[2], portionStreet->corners[3])) { if (insidePoints == 0) { if (currentWayName == NULL) { currentWayName = new char[70]; } strcpy(currentWayName, adjacentWay->GetName()); } insidePoints++; return; } } }
void CreateRoundaboutInteraction::mousePressEvent(QMouseEvent * event) { if (event->buttons() & Qt::LeftButton) { if (!HaveCenter) { HaveCenter = true; view()->setInteracting(true); Center = XY_TO_COORD(event->pos()); } else { calculatePoints(); if (Points.size() == 0) return; QPointF Prev = Points[0]; Node* First = g_backend.allocNode(theMain->document()->getDirtyOrOriginLayer(), XY_TO_COORD(Prev.toPoint())); Way* R = g_backend.allocWay(theMain->document()->getDirtyOrOriginLayer()); CommandList* L = new CommandList(MainWindow::tr("Create Roundabout %1").arg(R->id().numId), R); L->add(new AddFeatureCommand(theMain->document()->getDirtyOrOriginLayer(),R,true)); R->add(First); L->add(new AddFeatureCommand(theMain->document()->getDirtyOrOriginLayer(),First,true)); if (M_PREFS->getAutoSourceTag()) { QStringList sl = theMain->document()->getCurrentSourceTags(); if (sl.size()) R->setTag("source", sl.join(";")); } // "oneway" is implied on roundabouts //R->setTag("oneway","yes"); if (DockData.type->currentIndex() == 0) R->setTag("junction","roundabout"); for (int i = 1; i < Points.size(); i++ ) { QPointF Next = Points[i]; Node* New = g_backend.allocNode(theMain->document()->getDirtyOrOriginLayer(), XY_TO_COORD(Next.toPoint())); L->add(new AddFeatureCommand(theMain->document()->getDirtyOrOriginLayer(),New,true)); R->add(New); } R->add(First); for (FeatureIterator it(document()); !it.isEnd(); ++it) { Way* W1 = CAST_WAY(it.get()); if (W1 && (W1 != R)) Way::createJunction(theMain->document(), L, R, W1, true); } theMain->properties()->setSelection(R); document()->addHistory(L); view()->setInteracting(false); view()->invalidate(true, true, false); theMain->launchInteraction(0); } } else Interaction::mousePressEvent(event); }
bool OptimizeAreaWayIdsGenerator::ScanWayIds(const ImportParameter& parameter, Progress& progress, const TypeConfig& typeConfig, NodeUseMap& nodeUseMap) { FileScanner scanner; uint32_t dataCount=0; progress.SetAction("Scanning ids from 'wayway.tmp'"); if (!scanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(), "wayway.tmp"), FileScanner::Sequential, parameter.GetWayDataMemoryMaped())) { progress.Error(std::string("Cannot open '")+scanner.GetFilename()+"'"); return false; } if (!scanner.Read(dataCount)) { progress.Error("Error while reading number of data entries in file"); return false; } for (uint32_t current=1; current<=dataCount; current++) { uint8_t type; Id id; Way data; progress.SetProgress(current,dataCount); if (!scanner.Read(type) || !scanner.Read(id) || !data.Read(typeConfig, scanner)) { progress.Error(std::string("Error while reading data entry ")+ NumberToString(current)+" of "+ NumberToString(dataCount)+ " in file '"+ scanner.GetFilename()+"'"); return false; } if (!data.GetType()->CanRoute()) { continue; } std::unordered_set<Id> nodeIds; for (const auto& id : data.ids) { if (nodeIds.find(id)==nodeIds.end()) { nodeUseMap.SetNodeUsed(id); nodeIds.insert(id); } } // If we have a circular way, we "fake" a double usage, // to make sure, that the node id of the first node // is not dropped later on, and we cannot detect // circular ways anymore if (data.ids.front()==data.ids.back()) { nodeUseMap.SetNodeUsed(data.ids.back()); } } if (!scanner.Close()) { progress.Error(std::string("Error while closing file '")+ scanner.GetFilename()+"'"); return false; } return true; }
void CreateSingleWayInteraction::snapMouseMoveEvent(QMouseEvent* ev, Feature* lastSnap) { if (Node* Pt = dynamic_cast<Node*>(lastSnap)) LastCursor = COORD_TO_XY(Pt); else if (Way* R = dynamic_cast<Way*>(lastSnap)) { Coord P(XY_TO_COORD(ev->pos())); findSnapPointIndex(R, P); LastCursor = COORD_TO_XY(P); } else if (theRoad && theRoad->size() > 1 && SnapAngle) { QLineF l1(COORD_TO_XY(theRoad->getNode(theRoad->size()-1)), COORD_TO_XY(theRoad->getNode(theRoad->size()-2))); QLineF l2(COORD_TO_XY(theRoad->getNode(theRoad->size()-1)), ev->pos()); qreal a = l1.angleTo(l2); a = qRound(a/SnapAngle) * SnapAngle; l2.setAngle(l1.angle() + a); LastCursor = l2.p2().toPoint(); } else if (HaveFirst && ParallelMode) { #define CLEAR_DISTANCE 200 QPointF PreviousPoint; if (theRoad && theRoad->size() && !Prepend) PreviousPoint = COORD_TO_XY(CAST_NODE(theRoad->get(theRoad->size()-1))->position()); else PreviousPoint = COORD_TO_XY(FirstPoint); CoordBox HotZone(XY_TO_COORD(ev->pos()-QPoint(CLEAR_DISTANCE, CLEAR_DISTANCE)),XY_TO_COORD(ev->pos()+QPoint(CLEAR_DISTANCE, CLEAR_DISTANCE))); qreal BestDistanceNW = 9999, AngleNW = 0; qreal BestDistanceNE = 9999, AngleNE = 0; qreal* BestDistance = &BestDistanceNW; qreal* BestAngle = &BestDistanceNE; qreal curAngle = 666; Way* R; for (int j=0; j<document()->layerSize(); ++j) { QList < Feature* > ret = g_backend.indexFind(document()->getLayer(j), HotZone); foreach(Feature* F, ret) { if (!(R = CAST_WAY(F))) continue; if (R->isHidden()) continue; if (R->notEverythingDownloaded()) continue; for (int i=0; i<R->size()-1; ++i) { LineF F(COORD_TO_XY(R->getNode(i)),COORD_TO_XY(R->getNode(i+1))); qreal D = F.capDistance(ev->pos()); if (D < CLEAR_DISTANCE) { QLineF l(COORD_TO_XY(R->getNode(i)), COORD_TO_XY(R->getNode(i+1))); qreal a = l.angle(); if ((a >= 0 && a < 90) || (a < -270 && a >= -360)) { BestDistance = &BestDistanceNE; BestAngle = &AngleNE; curAngle = a; } else if ((a >= 90 && a < 180) || (a < -180 && a >= -270)) { BestDistance = &BestDistanceNW; BestAngle = &AngleNW; curAngle = a; } else if ((a >= 180 && a < 270) || (a < -90 && a >= -180)) { BestDistance = &BestDistanceNE; BestAngle = &AngleNE; curAngle = a - 180; } else if ((a >= 270 && a < 360) || (a < 0 && a >= -90)) { BestDistance = &BestDistanceNW; BestAngle = &AngleNW; curAngle = a - 180; } if (D < *BestDistance) { *BestDistance = D; *BestAngle = curAngle; } } } qDebug() << BestDistanceNE << BestDistanceNW << AngleNE << AngleNW; } } /* Check if for some reason not a single angle was found. */ Q_ASSERT(curAngle >= -360 && curAngle <= 360); QLineF l(PreviousPoint, ev->pos()); qreal a = l.angle(); if ((a >= 0 && a < 90) || (a < -270 && a >= -360)) { if (BestDistanceNE < 9999) a = AngleNE; } else if ((a >= 90 && a < 180) || (a < -180 && a >= -270)) { if (BestDistanceNW < 9999) a = AngleNW; } else if ((a >= 180 && a < 270) || (a < -90 && a >= -180)) { if (BestDistanceNE < 9999) a = AngleNE - 180; } else if ((a >= 270 && a < 360) || (a < 0 && a >= -90)) { if (BestDistanceNW < 9999) a = AngleNW - 180; } l.setAngle(a); LastCursor = l.p2().toPoint(); } else
bool AreaWayIndexGenerator::Import(const ImportParameter& parameter, Progress& progress, const TypeConfig& typeConfig) { FileScanner wayScanner; FileWriter writer; std::set<TypeId> remainingWayTypes; std::vector<TypeData> wayTypeData; size_t level; size_t maxLevel=0; wayTypeData.resize(typeConfig.GetTypes().size()); if (!wayScanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(), "ways.dat"), FileScanner::Sequential, parameter.GetWayDataMemoryMaped())) { progress.Error("Cannot open 'ways.dat'"); return false; } // // Scanning distribution // progress.SetAction("Scanning level distribution of way types"); for (size_t i=0; i<typeConfig.GetTypes().size(); i++) { if (typeConfig.GetTypeInfo(i).CanBeWay() && !typeConfig.GetTypeInfo(i).GetIgnore()) { remainingWayTypes.insert(i); } } level=parameter.GetAreaWayMinMag(); while (!remainingWayTypes.empty()) { uint32_t wayCount=0; std::set<TypeId> currentWayTypes(remainingWayTypes); double cellWidth=360.0/pow(2.0,(int)level); double cellHeight=180.0/pow(2.0,(int)level); std::vector<CoordCountMap> cellFillCount(typeConfig.GetTypes().size()); progress.Info("Scanning Level "+NumberToString(level)+" ("+NumberToString(remainingWayTypes.size())+" types remaining)"); wayScanner.GotoBegin(); if (!wayScanner.Read(wayCount)) { progress.Error("Error while reading number of data entries in file"); return false; } Way way; for (uint32_t w=1; w<=wayCount; w++) { progress.SetProgress(w,wayCount); if (!way.Read(wayScanner)) { progress.Error(std::string("Error while reading data entry ")+ NumberToString(w)+" of "+ NumberToString(wayCount)+ " in file '"+ wayScanner.GetFilename()+"'"); return false; } // Count number of entries per current type and coordinate if (currentWayTypes.find(way.GetType())==currentWayTypes.end()) { continue; } double minLon; double maxLon; double minLat; double maxLat; way.GetBoundingBox(minLon,maxLon,minLat,maxLat); // // Calculate minimum and maximum tile ids that are covered // by the way // Renormated coordinate space (everything is >=0) // uint32_t minxc=(uint32_t)floor((minLon+180.0)/cellWidth); uint32_t maxxc=(uint32_t)floor((maxLon+180.0)/cellWidth); uint32_t minyc=(uint32_t)floor((minLat+90.0)/cellHeight); uint32_t maxyc=(uint32_t)floor((maxLat+90.0)/cellHeight); for (uint32_t y=minyc; y<=maxyc; y++) { for (uint32_t x=minxc; x<=maxxc; x++) { cellFillCount[way.GetType()][Pixel(x,y)]++; } } } // Check if cell fill for current type is in defined limits for (size_t i=0; i<typeConfig.GetTypes().size(); i++) { if (currentWayTypes.find(i)!=currentWayTypes.end()) { CalculateStatistics(level,wayTypeData[i],cellFillCount[i]); if (!FitsIndexCriteria(parameter, progress, typeConfig.GetTypeInfo(i), wayTypeData[i], cellFillCount[i])) { currentWayTypes.erase(i); } } } for (std::set<TypeId>::const_iterator cwt=currentWayTypes.begin(); cwt!=currentWayTypes.end(); cwt++) { maxLevel=std::max(maxLevel,level); progress.Info("Type "+typeConfig.GetTypeInfo(*cwt).GetName()+"(" + NumberToString(*cwt)+"), "+NumberToString(wayTypeData[*cwt].indexCells)+" cells, "+NumberToString(wayTypeData[*cwt].indexEntries)+" objects"); remainingWayTypes.erase(*cwt); } level++; } // // Writing index file // progress.SetAction("Generating 'areaway.idx'"); if (!writer.Open(AppendFileToDir(parameter.GetDestinationDirectory(), "areaway.idx"))) { progress.Error("Cannot create 'areaway.idx'"); return false; } uint32_t indexEntries=0; for (size_t i=0; i<typeConfig.GetTypes().size(); i++) { if (typeConfig.GetTypeInfo(i).CanBeWay() && wayTypeData[i].HasEntries()) { indexEntries++; } } writer.Write(indexEntries); for (size_t i=0; i<typeConfig.GetTypes().size(); i++) { if (typeConfig.GetTypeInfo(i).CanBeWay() && wayTypeData[i].HasEntries()) { uint8_t dataOffsetBytes=0; FileOffset bitmapOffset=0; writer.WriteNumber(typeConfig.GetTypeInfo(i).GetId()); writer.GetPos(wayTypeData[i].indexOffset); writer.WriteFileOffset(bitmapOffset); if (wayTypeData[i].HasEntries()) { writer.Write(dataOffsetBytes); writer.WriteNumber(wayTypeData[i].indexLevel); writer.WriteNumber(wayTypeData[i].cellXStart); writer.WriteNumber(wayTypeData[i].cellXEnd); writer.WriteNumber(wayTypeData[i].cellYStart); writer.WriteNumber(wayTypeData[i].cellYEnd); } } } for (size_t l=parameter.GetAreaWayMinMag(); l<=maxLevel; l++) { std::set<TypeId> indexTypes; uint32_t wayCount; double cellWidth=360.0/pow(2.0,(int)l); double cellHeight=180.0/pow(2.0,(int)l); for (size_t i=0; i<typeConfig.GetTypes().size(); i++) { if (typeConfig.GetTypeInfo(i).CanBeWay() && wayTypeData[i].HasEntries() && wayTypeData[i].indexLevel==l) { indexTypes.insert(i); } } if (indexTypes.empty()) { continue; } progress.Info("Scanning ways for index level "+NumberToString(l)); std::vector<CoordOffsetsMap> typeCellOffsets(typeConfig.GetTypes().size()); wayScanner.GotoBegin(); if (!wayScanner.Read(wayCount)) { progress.Error("Error while reading number of data entries in file"); return false; } Way way; for (uint32_t w=1; w<=wayCount; w++) { progress.SetProgress(w,wayCount); FileOffset offset; wayScanner.GetPos(offset); if (!way.Read(wayScanner)) { progress.Error(std::string("Error while reading data entry ")+ NumberToString(w)+" of "+ NumberToString(wayCount)+ " in file '"+ wayScanner.GetFilename()+"'"); return false; } if (indexTypes.find(way.GetType())==indexTypes.end()) { continue; } double minLon; double maxLon; double minLat; double maxLat; way.GetBoundingBox(minLon,maxLon,minLat,maxLat); // // Calculate minimum and maximum tile ids that are covered // by the way // Renormated coordinate space (everything is >=0) // uint32_t minxc=(uint32_t)floor((minLon+180.0)/cellWidth); uint32_t maxxc=(uint32_t)floor((maxLon+180.0)/cellWidth); uint32_t minyc=(uint32_t)floor((minLat+90.0)/cellHeight); uint32_t maxyc=(uint32_t)floor((maxLat+90.0)/cellHeight); for (uint32_t y=minyc; y<=maxyc; y++) { for (uint32_t x=minxc; x<=maxxc; x++) { typeCellOffsets[way.GetType()][Pixel(x,y)].push_back(offset); } } } for (std::set<TypeId>::const_iterator type=indexTypes.begin(); type!=indexTypes.end(); ++type) { if (!WriteBitmap(progress, writer, typeConfig.GetTypeInfo(*type), wayTypeData[*type], typeCellOffsets[*type])) { return false; } } } return !writer.HasError() && writer.Close(); }
bool OptimizeAreaWayIdsGenerator::CopyWays(const ImportParameter& parameter, Progress& progress, const TypeConfig& typeConfig, NodeUseMap& nodeUseMap) { FileScanner scanner; FileWriter writer; uint32_t dataCount=0; progress.SetAction("Copy data from 'wayway.tmp' to 'ways.tmp'"); if (!scanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(), "wayway.tmp"), FileScanner::Sequential, parameter.GetWayDataMemoryMaped())) { progress.Error(std::string("Cannot open '")+scanner.GetFilename()+"'"); return false; } if (!scanner.Read(dataCount)) { progress.Error("Error while reading number of data entries in file"); return false; } if (!writer.Open(AppendFileToDir(parameter.GetDestinationDirectory(), "ways.tmp"))) { progress.Error(std::string("Cannot create '")+writer.GetFilename()+"'"); return false; } writer.Write(dataCount); for (uint32_t current=1; current<=dataCount; current++) { uint8_t type; Id id; Way data; progress.SetProgress(current,dataCount); if (!scanner.Read(type) || !scanner.Read(id) || !data.Read(typeConfig, scanner)) { progress.Error(std::string("Error while reading data entry ")+ NumberToString(current)+" of "+ NumberToString(dataCount)+ " in file '"+ scanner.GetFilename()+"'"); return false; } for (auto& id : data.ids) { if (!nodeUseMap.IsNodeUsedAtLeastTwice(id)) { id=0; } } if (!writer.Write(type) || !writer.Write(id) || !data.Write(typeConfig, writer)) { progress.Error(std::string("Error while writing data entry to file '")+ writer.GetFilename()+"'"); return false; } } if (!scanner.Close()) { progress.Error(std::string("Error while closing file '")+ scanner.GetFilename()+"'"); return false; } if (!writer.Close()) { progress.Error(std::string("Error while closing file '")+ writer.GetFilename()+"'"); return false; } return true; }
void MapRenderer::render( QPainter* P, const QMap<RenderPriority, QSet <Feature*> >& theFeatures, const RendererOptions& options, MapView* aView ) { // #ifndef NDEBUG // QTime Start(QTime::currentTime()); // #endif theView = aView; theOptions = options; theGlobalPainter = M_STYLE->getGlobalPainter(); bool bgLayerVisible = TEST_RFLAGS(RendererOptions::BackgroundVisible); bool fgLayerVisible = TEST_RFLAGS(RendererOptions::ForegroundVisible); bool tchpLayerVisible = TEST_RFLAGS(RendererOptions::TouchupVisible); bool lblLayerVisible = TEST_RFLAGS(RendererOptions::NamesVisible); QMap<RenderPriority, QSet<Feature*> >::const_iterator itm; QMap<RenderPriority, QSet<Feature*> >::const_iterator itmCur; QSet<Feature*>::const_iterator it; thePainter = P; itm = theFeatures.constBegin(); while (itm != theFeatures.constEnd()) { int curLayer = (itm.key()).layer(); itmCur = itm; while (itm != theFeatures.constEnd() && (itm.key()).layer() == curLayer) { if (bgLayerVisible) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(theView->pixelPerM())) continue; bglayer.draw(R); } else if (CHECK_NODE(*it)) bglayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) bglayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } ++itm; } itm = itmCur; while (itm != theFeatures.constEnd() && (itm.key()).layer() == curLayer) { if (fgLayerVisible) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(theView->pixelPerM())) continue; fglayer.draw(R); } else if (CHECK_NODE(*it)) fglayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) fglayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } ++itm; } } if (tchpLayerVisible) { for (itm = theFeatures.constBegin() ;itm != theFeatures.constEnd(); ++itm) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(theView->pixelPerM())) continue; tchuplayer.draw(R); } else if (CHECK_NODE(*it)) tchuplayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) tchuplayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } } for (itm = theFeatures.constBegin() ;itm != theFeatures.constEnd(); ++itm) { for (it = itm.value().constBegin() ;it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) P->setOpacity(alpha); (*it)->draw(*P, aView); } } if (lblLayerVisible) { for (itm = theFeatures.constBegin() ;itm != theFeatures.constEnd(); ++itm) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { P->save(); qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; P->setOpacity(alpha); if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(theView->pixelPerM())) continue; lbllayer.draw(R); } else if (CHECK_NODE(*it)) lbllayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) lbllayer.draw(STATIC_CAST_RELATION(*it)); P->restore(); } } } // #ifndef NDEBUG // QTime Stop(QTime::currentTime()); // qDebug() << Start.msecsTo(Stop) << "ms"; // #endif }
void TrackLayer::extractLayer() { DrawingLayer* extL = new DrawingLayer(tr("Extract - %1").arg(name())); extL->setUploadable(false); TrackNode* P; QList<TrackNode*> PL; const qreal coordPer10M = (double(COORD_MAX) * 2 / 40080000) * 2; for (int i=0; i < size(); i++) { if (TrackSegment* S = dynamic_cast<TrackSegment*>(get(i))) { if (S->size() < 2) continue; // Cope with walking tracks qreal konstant = coordPer10M; qreal meanSpeed = S->distance() / S->duration() * 3600; if (meanSpeed < 10.) konstant /= 3.; PL.clear(); P = g_backend.allocTrackNode(extL, S->getNode(0)->position() ); P->setTime(S->getNode(0)->time()); P->setElevation(S->getNode(0)->elevation()); P->setSpeed(S->getNode(0)->speed()); PL.append(P); int startP = 0; P = g_backend.allocTrackNode(extL, S->getNode(1)->position() ); P->setTime(S->getNode(1)->time()); P->setElevation(S->getNode(1)->elevation()); P->setSpeed(S->getNode(1)->speed()); PL.append(P); int endP = 1; for (int j=2; j < S->size(); j++) { P = g_backend.allocTrackNode(extL, S->getNode(j)->position() ); P->setTime(S->getNode(j)->time()); P->setElevation(S->getNode(j)->elevation()); P->setSpeed(S->getNode(j)->speed()); PL.append(P); endP = PL.size()-1; LineF l(PL[startP]->position(), PL[endP]->position()); for (int k=startP+1; k < endP; k++) { qreal d = l.distance(PL[k]->position()); if (d < konstant) { Node* P = PL[k]; PL.removeAt(k); g_backend.deallocFeature(extL, P); endP--; } else startP = k; } } Way* R = g_backend.allocWay(extL); R->setLastUpdated(Feature::OSMServer); extL->add(R); for (int i=0; i < PL.size(); i++) { extL->add(PL[i]); R->add(PL[i]); } } } p->theDocument->add(extL); }
void PropertiesDock::resetValues() { Highlighted.clear(); // Tables that might need column sizing CurrentTagView = NULL; CurrentMembersView = NULL; // to prevent slots to change the values also QList<Feature*> Current = Selection; Selection.clear(); if (FullSelection.size() == 1) { Main->info()->setHtml(FullSelection[0]->toHtml()); Node* Pt = dynamic_cast<Node*>(FullSelection[0]); Way* R = dynamic_cast<Way*>(FullSelection[0]); Relation* L = dynamic_cast<Relation*>(FullSelection[0]); if ((Pt) && (NowShowing == TrackPointUiShowing)) { TrackPointUi.Id->setText(QString::number(Pt->id().numId)); TrackPointUi.Latitude->setText(COORD2STRING(Pt->position().y())); TrackPointUi.Longitude->setText(COORD2STRING(Pt->position().x())); TrackPointUi.TagView->setModel(theModel); TrackPointUi.TagView->setItemDelegate(delegate); QWidget* w; for (int i=0; i<TrackPointUi.variableLayout->count(); ++i) { w = TrackPointUi.variableLayout->itemAt(i)->widget(); if (w) { w->hide(); w->deleteLater(); } } if (theTemplates) { w = theTemplates->getWidget(Pt, Main->view()); w->installEventFilter(shortcutFilter); TrackPointUi.variableLayout->addWidget(w); } CurrentTagView = TrackPointUi.TagView; #ifdef GEOIMAGE Main->geoImage()->setImage(Pt); #endif } else if ((R) && (NowShowing == RoadUiShowing)) { RoadUi.Id->setText(QString::number(R->id().numId)); //RoadUi.Name->setText(R->tagValue("name","")); RoadUi.TagView->setModel(theModel); RoadUi.TagView->setItemDelegate(delegate); QWidget* w; for (int i=0; i<RoadUi.variableLayout->count(); ++i) { w = RoadUi.variableLayout->itemAt(i)->widget(); if (w) { w->hide(); w->deleteLater(); } } if (theTemplates) { w = theTemplates->getWidget(R, Main->view()); w->installEventFilter(shortcutFilter); RoadUi.variableLayout->addWidget(w); } CurrentTagView = RoadUi.TagView; } else if ((L) && (NowShowing == RelationUiShowing)) { RelationUi.MembersView->setModel(L->referenceMemberModel(Main)); RelationUi.TagView->setModel(theModel); RelationUi.TagView->setItemDelegate(delegate); QWidget* w; for (int i=0; i<RelationUi.variableLayout->count(); ++i) { w = RelationUi.variableLayout->itemAt(i)->widget(); if (w) { w->hide(); w->deleteLater(); } } if (theTemplates) { w = theTemplates->getWidget(L, Main->view()); w->installEventFilter(shortcutFilter); RelationUi.variableLayout->addWidget(w); } CurrentTagView = RelationUi.TagView; CurrentMembersView = RelationUi.MembersView; } if (theTemplates) theTemplates->apply(FullSelection[0]); } else if ((FullSelection.size() > 1) && (NowShowing == MultiShowing)) { Main->info()->setHtml(""); #ifdef GEOIMAGE Main->geoImage()->setImage((Node *)NULL); #endif MultiUi.TagView->setModel(theModel); MultiUi.TagView->setItemDelegate(delegate); CurrentTagView = MultiUi.TagView; } theModel->setFeature(Current); Selection = Current; checkMenuStatus(); emit selectionChanged(); /* If we have standard TableViews in the current UI, set it so that the */ /* first column is the width of the default text (Edit this to add...) */ /* And the rest of the space is assigned to the second column */ if (CurrentTagView) { if (M_PREFS->getTagListFirstColumnWidth() > 20 && M_PREFS->getTagListFirstColumnWidth() < CurrentTagView->width()) CurrentTagView->setColumnWidth( 0, M_PREFS->getTagListFirstColumnWidth() ); else CurrentTagView->setColumnWidth( 0, CurrentTagView->fontMetrics().width(theModel->newKeyText())+10 ); CurrentTagView->horizontalHeader()->setStretchLastSection(true); CurrentTagView->installEventFilter(shortcutFilter); } if (CurrentMembersView) { CurrentMembersView->setColumnWidth( 0, CurrentMembersView->fontMetrics().width(theModel->newKeyText())+10 ); CurrentMembersView->horizontalHeader()->setStretchLastSection(true); CurrentMembersView->installEventFilter(shortcutFilter); } }
// export bool ImportExportGdal::export_(const QList<Feature *>& featList) { const char *pszDriverName = "SQLite"; OGRSFDriver *poDriver; OGRRegisterAll(); poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName); if( poDriver == NULL ) { qDebug( "%s driver not available.", pszDriverName ); return false; } OGRDataSource *poDS; QFile::remove(QString(HOMEDIR + "/test.sqlite")); poDS = poDriver->CreateDataSource( QString(HOMEDIR + "/test.sqlite").toUtf8().constData(), NULL ); if( poDS == NULL ) { qDebug( "Creation of output file failed." ); return false; } poDS->ExecuteSQL("PRAGMA synchronous = OFF", NULL, NULL); OGRSpatialReference *poSRS; poSRS = new OGRSpatialReference(); poSRS->importFromEPSG(4326); char **papszOptions = NULL; papszOptions = CSLSetNameValue( papszOptions, "SPATIALITE", "YES" ); papszOptions = CSLSetNameValue( papszOptions, "FORMAT", "SPATIALITE" ); papszOptions = CSLSetNameValue( papszOptions, "SPATIAL_INDEX", "YES" ); OGRLayer *poLayer; poLayer = poDS->CreateLayer( "osm", poSRS, wkbUnknown, papszOptions); CSLDestroy( papszOptions ); if( poLayer == NULL ) { qDebug( "Layer creation failed." ); return false; } OGRFieldDefn oField("osm_id", OFTReal); if( poLayer->CreateField( &oField ) != OGRERR_NONE ) { qDebug( "Creating field failed." ); return false; } oField.Set("osm_version", OFTInteger ); poLayer->CreateField( &oField ); oField.Set("osm_timestamp", OFTInteger ); poLayer->CreateField( &oField ); OGRFeature *poFeature; foreach (Feature* F, featList) { poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() ); poFeature->SetField( "osm_id", (qreal)(F->id().numId)); #ifndef FRISIUS_BUILD poFeature->SetField( "osm_version", F->versionNumber()); poFeature->SetField( "osm_timestamp", (int)F->time().toTime_t()); #endif if (CHECK_NODE(F)) { Node* N = STATIC_CAST_NODE(F); OGRPoint pt; pt.setX(N->position().x()); pt.setY(N->position().y()); poFeature->SetGeometry( &pt ); } else if (CHECK_WAY(F)) { Way* W = STATIC_CAST_WAY(F); OGRLineString ls; ls.setNumPoints(W->size()); for (int i=0; i<W->size(); ++i) { ls.setPoint(i, W->getNode(i)->position().x(), W->getNode(i)->position().y(), 0); } poFeature->SetGeometry( &ls ); } if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE ) { qDebug( "Failed to create feature in output." ); return false; } OGRFeature::DestroyFeature( poFeature ); }
bool AreaWayIndexGenerator::Import(const TypeConfigRef& typeConfig, const ImportParameter& parameter, Progress& progress) { FileScanner wayScanner; FileWriter writer; std::vector<TypeData> wayTypeData; size_t maxLevel; progress.Info("Minimum magnification: "+NumberToString(parameter.GetAreaWayMinMag())); // // Scanning distribution // progress.SetAction("Scanning level distribution of way types"); if (!CalculateDistribution(typeConfig, parameter, progress, wayTypeData, maxLevel)) { return false; } // Calculate number of types which have data uint32_t indexEntries=0; for (const auto& type : typeConfig->GetWayTypes()) { if (wayTypeData[type->GetIndex()].HasEntries()) { indexEntries++; } } // // Writing index file // progress.SetAction("Generating 'areaway.idx'"); if (!writer.Open(AppendFileToDir(parameter.GetDestinationDirectory(), "areaway.idx"))) { progress.Error("Cannot create 'areaway.idx'"); return false; } writer.Write(indexEntries); for (const auto &type : typeConfig->GetWayTypes()) { size_t i=type->GetIndex(); if (wayTypeData[i].HasEntries()) { uint8_t dataOffsetBytes=0; FileOffset bitmapOffset=0; writer.WriteTypeId(type->GetWayId(), typeConfig->GetWayTypeIdBytes()); writer.GetPos(wayTypeData[i].indexOffset); writer.WriteFileOffset(bitmapOffset); writer.Write(dataOffsetBytes); writer.WriteNumber(wayTypeData[i].indexLevel); writer.WriteNumber(wayTypeData[i].cellXStart); writer.WriteNumber(wayTypeData[i].cellXEnd); writer.WriteNumber(wayTypeData[i].cellYStart); writer.WriteNumber(wayTypeData[i].cellYEnd); } } if (!wayScanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(), "ways.dat"), FileScanner::Sequential, parameter.GetWayDataMemoryMaped())) { progress.Error("Cannot open 'ways.dat'"); return false; } for (size_t l=parameter.GetAreaWayMinMag(); l<=maxLevel; l++) { TypeInfoSet indexTypes(*typeConfig); uint32_t wayCount; double cellWidth=360.0/pow(2.0,(int)l); double cellHeight=180.0/pow(2.0,(int)l); wayScanner.GotoBegin(); for (const auto &type : typeConfig->GetWayTypes()) { if (wayTypeData[type->GetIndex()].HasEntries() && wayTypeData[type->GetIndex()].indexLevel==l) { indexTypes.Set(type); } } if (indexTypes.Empty()) { continue; } progress.Info("Scanning ways for index level "+NumberToString(l)); std::vector<CoordOffsetsMap> typeCellOffsets(typeConfig->GetTypeCount()); if (!wayScanner.Read(wayCount)) { progress.Error("Error while reading number of data entries in file"); return false; } Way way; for (uint32_t w=1; w<=wayCount; w++) { progress.SetProgress(w,wayCount); FileOffset offset; wayScanner.GetPos(offset); if (!way.Read(*typeConfig, wayScanner)) { progress.Error(std::string("Error while reading data entry ")+ NumberToString(w)+" of "+ NumberToString(wayCount)+ " in file '"+ wayScanner.GetFilename()+"'"); return false; } if (!indexTypes.IsSet(way.GetType())) { continue; } GeoBox boundingBox; way.GetBoundingBox(boundingBox); // // Calculate minimum and maximum tile ids that are covered // by the way // Renormalized coordinate space (everything is >=0) // uint32_t minxc=(uint32_t)floor((boundingBox.GetMinLon()+180.0)/cellWidth); uint32_t maxxc=(uint32_t)floor((boundingBox.GetMaxLon()+180.0)/cellWidth); uint32_t minyc=(uint32_t)floor((boundingBox.GetMinLat()+90.0)/cellHeight); uint32_t maxyc=(uint32_t)floor((boundingBox.GetMaxLat()+90.0)/cellHeight); for (uint32_t y=minyc; y<=maxyc; y++) { for (uint32_t x=minxc; x<=maxxc; x++) { typeCellOffsets[way.GetType()->GetIndex()][Pixel(x,y)].push_back(offset); } } } for (const auto &type : indexTypes) { size_t index=type->GetIndex(); if (!WriteBitmap(progress, writer, *typeConfig->GetTypeInfo(index), wayTypeData[index], typeCellOffsets[index])) { return false; } } } return !writer.HasError() && writer.Close(); }
void MapRenderer::render( QPainter* P, QMap<RenderPriority, QSet <Feature*> > theFeatures, const RendererOptions& options, MapView* aView ) { #ifndef NDEBUG QTime Start(QTime::currentTime()); #endif theView = aView; theOptions = options; QMap<RenderPriority, QSet<Feature*> >::const_iterator itm; QSet<Feature*>::const_iterator it; bool bgLayerVisible = TEST_RFLAGS(RendererOptions::BackgroundVisible); bool fgLayerVisible = TEST_RFLAGS(RendererOptions::ForegroundVisible); bool tchpLayerVisible = TEST_RFLAGS(RendererOptions::TouchupVisible); bool lblLayerVisible = TEST_RFLAGS(RendererOptions::NamesVisible); Way * R = NULL; Node * Pt = NULL; Relation * RR = NULL; QPixmap pix(theView->size()); thePainter = new QPainter(); itm = theFeatures.constBegin(); while (itm != theFeatures.constEnd()) { pix.fill(Qt::transparent); thePainter->begin(&pix); if (M_PREFS->getUseAntiAlias()) thePainter->setRenderHint(QPainter::Antialiasing); int curLayer = (itm.key()).layer(); while (itm != theFeatures.constEnd() && (itm.key()).layer() == curLayer) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); thePainter->setOpacity(alpha); R = NULL; Pt = NULL; RR = NULL; if (!(R = CAST_WAY(*it))) if (!(Pt = CAST_NODE(*it))) RR = CAST_RELATION(*it); if (R) { // If there is painter at the relation level, don't paint at the way level bool draw = true; for (int i=0; i<R->sizeParents(); ++i) { if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(PixelPerM)) draw = false; } if (!draw) continue; } if (!Pt) { if (bgLayerVisible) { thePainter->save(); if (R && R->area() == 0) thePainter->setCompositionMode(QPainter::CompositionMode_DestinationOver); if (R) bglayer.draw(R); else if (Pt) bglayer.draw(Pt); else if (RR) bglayer.draw(RR); thePainter->restore(); } if (fgLayerVisible) { thePainter->save(); if (R) fglayer.draw(R); else if (Pt) fglayer.draw(Pt); else if (RR) fglayer.draw(RR); thePainter->restore(); } } if (tchpLayerVisible) { thePainter->save(); if (R) tchuplayer.draw(R); else if (Pt) tchuplayer.draw(Pt); else if (RR) tchuplayer.draw(RR); thePainter->restore(); } if (lblLayerVisible) { thePainter->save(); if (R) lbllayer.draw(R); else if (Pt) lbllayer.draw(Pt); else if (RR) lbllayer.draw(RR); thePainter->restore(); } (*it)->draw(*thePainter, aView); } ++itm; } thePainter->end(); P->drawPixmap(0, 0, pix); #ifndef NDEBUG QTime Stop(QTime::currentTime()); qDebug() << Start.msecsTo(Stop) << "ms"; #endif } }
void MapRenderer::render( QPainter* P, const QMap<RenderPriority, QSet <Feature*> >& theFeatures, const QRectF& pViewport, const QRect& screen, const qreal pixelPerM, const RendererOptions& options ) { theViewport = pViewport; theScreen = screen; thePixelPerM = pixelPerM; qreal Aspect = (double)screen.width() / screen.height(); qreal pAspect = fabs(pViewport.width() / pViewport.height()); qreal wv, hv; if (pAspect > Aspect) { wv = fabs(pViewport.width()); hv = fabs(pViewport.height() * pAspect / Aspect); } else { wv = fabs(pViewport.width() * Aspect / pAspect); hv = fabs(pViewport.height()); } qreal ScaleLon = screen.width() / wv; qreal ScaleLat = screen.height() / hv; theTransform.reset(); theTransform.scale(ScaleLon, -ScaleLat); theTransform.translate(-pViewport.topLeft().x(), -pViewport.topLeft().y()); theOptions = options; theGlobalPainter = M_STYLE->getGlobalPainter(); if (theGlobalPainter.DrawNodes) { NodeWidth = thePixelPerM*theGlobalPainter.NodesProportional+theGlobalPainter.NodesFixed; } else { NodeWidth = thePixelPerM * M_PREFS->getNodeSize(); if (NodeWidth > M_PREFS->getNodeSize()) NodeWidth = M_PREFS->getNodeSize(); } bool bgLayerVisible = TEST_RFLAGS(RendererOptions::BackgroundVisible); bool fgLayerVisible = TEST_RFLAGS(RendererOptions::ForegroundVisible); bool tchpLayerVisible = TEST_RFLAGS(RendererOptions::TouchupVisible); bool lblLayerVisible = TEST_RFLAGS(RendererOptions::NamesVisible); QMap<RenderPriority, QSet<Feature*> >::const_iterator itm; QMap<RenderPriority, QSet<Feature*> >::const_iterator itmCur; QSet<Feature*>::const_iterator it; thePainter = P; thePainter->save(); thePainter->translate(screen.left(), screen.top()); itm = theFeatures.constBegin(); while (itm != theFeatures.constEnd()) { int curLayer = (itm.key()).layer(); itmCur = itm; while (itm != theFeatures.constEnd() && (itm.key()).layer() == curLayer) { if (bgLayerVisible) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(thePixelPerM)) continue; bglayer.draw(R); } else if (CHECK_NODE(*it)) bglayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) bglayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } ++itm; } itm = itmCur; while (itm != theFeatures.constEnd() && (itm.key()).layer() == curLayer) { if (fgLayerVisible) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(thePixelPerM)) continue; fglayer.draw(R); } else if (CHECK_NODE(*it)) fglayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) fglayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } ++itm; } } if (tchpLayerVisible) { for (itm = theFeatures.constBegin() ;itm != theFeatures.constEnd(); ++itm) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; if (alpha != 1.) { P->save(); P->setOpacity(alpha); } if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(thePixelPerM)) continue; tchuplayer.draw(R); } else if (CHECK_NODE(*it)) tchuplayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) tchuplayer.draw(STATIC_CAST_RELATION(*it)); if (alpha != 1.) { P->restore(); } } } } if (lblLayerVisible) { for (itm = theFeatures.constBegin() ;itm != theFeatures.constEnd(); ++itm) { for (it = itm.value().constBegin(); it != itm.value().constEnd(); ++it) { P->save(); qreal alpha = (*it)->getAlpha(); if ((*it)->isReadonly() && !TEST_RFLAGS(RendererOptions::ForPrinting)) alpha /= 2.0; P->setOpacity(alpha); if (CHECK_WAY(*it)) { Way * R = STATIC_CAST_WAY(*it); for (int i=0; i<R->sizeParents(); ++i) if (!R->getParent(i)->isDeleted() && R->getParent(i)->hasPainter(thePixelPerM)) continue; lbllayer.draw(R); } else if (CHECK_NODE(*it)) lbllayer.draw(STATIC_CAST_NODE(*it)); else if (CHECK_RELATION(*it)) lbllayer.draw(STATIC_CAST_RELATION(*it)); P->restore(); } } } thePainter->restore(); }
bool AreaWayIndexGenerator::CalculateDistribution(const TypeConfigRef& typeConfig, const ImportParameter& parameter, Progress& progress, std::vector<TypeData>& wayTypeData, size_t& maxLevel) const { FileScanner wayScanner; TypeInfoSet remainingWayTypes; size_t level; maxLevel=0; wayTypeData.resize(typeConfig->GetTypeCount()); if (!wayScanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(), "ways.dat"), FileScanner::Sequential, parameter.GetWayDataMemoryMaped())) { progress.Error("Cannot open 'ways.dat'"); return false; } remainingWayTypes.Set(typeConfig->GetWayTypes()); level=parameter.GetAreaWayMinMag(); while (!remainingWayTypes.Empty()) { uint32_t wayCount=0; TypeInfoSet currentWayTypes(remainingWayTypes); double cellWidth=360.0/pow(2.0,(int)level); double cellHeight=180.0/pow(2.0,(int)level); std::vector<CoordCountMap> cellFillCount(typeConfig->GetTypeCount()); progress.Info("Scanning Level "+NumberToString(level)+" ("+NumberToString(remainingWayTypes.Size())+" types remaining)"); wayScanner.GotoBegin(); if (!wayScanner.Read(wayCount)) { progress.Error("Error while reading number of data entries in file"); return false; } Way way; for (uint32_t w=1; w<=wayCount; w++) { progress.SetProgress(w,wayCount); if (!way.Read(*typeConfig, wayScanner)) { progress.Error(std::string("Error while reading data entry ")+ NumberToString(w)+" of "+ NumberToString(wayCount)+ " in file '"+ wayScanner.GetFilename()+"'"); return false; } // Count number of entries per current type and coordinate if (!currentWayTypes.IsSet(way.GetType())) { continue; } GeoBox boundingBox; way.GetBoundingBox(boundingBox); // // Calculate minimum and maximum tile ids that are covered // by the way // Renormalized coordinate space (everything is >=0) // uint32_t minxc=(uint32_t)floor((boundingBox.GetMinLon()+180.0)/cellWidth); uint32_t maxxc=(uint32_t)floor((boundingBox.GetMaxLon()+180.0)/cellWidth); uint32_t minyc=(uint32_t)floor((boundingBox.GetMinLat()+90.0)/cellHeight); uint32_t maxyc=(uint32_t)floor((boundingBox.GetMaxLat()+90.0)/cellHeight); for (uint32_t y=minyc; y<=maxyc; y++) { for (uint32_t x=minxc; x<=maxxc; x++) { cellFillCount[way.GetType()->GetIndex()][Pixel(x,y)]++; } } } // Check if cell fill for current type is in defined limits for (auto &type : currentWayTypes) { size_t i=type->GetIndex(); CalculateStatistics(level, wayTypeData[i], cellFillCount[i]); if (!FitsIndexCriteria(parameter, progress, *typeConfig->GetTypeInfo(i), wayTypeData[i], cellFillCount[i])) { currentWayTypes.Remove(type); } } for (const auto &type : currentWayTypes) { maxLevel=std::max(maxLevel,level); progress.Info("Type "+type->GetName()+", "+NumberToString(wayTypeData[type->GetIndex()].indexCells)+" cells, "+NumberToString(wayTypeData[type->GetIndex()].indexEntries)+" objects"); remainingWayTypes.Remove(type); } level++; } return !wayScanner.HasError() && wayScanner.Close(); }