void AreaWayIndexGenerator::CalculateStatistics(size_t level, TypeData& typeData, const CoordCountMap& cellFillCount) { typeData.indexLevel=(uint32_t)level; typeData.indexCells=cellFillCount.size(); typeData.indexEntries=0; // If we do not have any entries, we store it now if (cellFillCount.empty()) { return; } typeData.cellXStart=cellFillCount.begin()->first.x; typeData.cellYStart=cellFillCount.begin()->first.y; typeData.cellXEnd=typeData.cellXStart; typeData.cellYEnd=typeData.cellYStart; for (CoordCountMap::const_iterator cell=cellFillCount.begin(); cell!=cellFillCount.end(); ++cell) { typeData.indexEntries+=cell->second; typeData.cellXStart=std::min(typeData.cellXStart,cell->first.x); typeData.cellXEnd=std::max(typeData.cellXEnd,cell->first.x); typeData.cellYStart=std::min(typeData.cellYStart,cell->first.y); typeData.cellYEnd=std::max(typeData.cellYEnd,cell->first.y); } typeData.cellXCount=typeData.cellXEnd-typeData.cellXStart+1; typeData.cellYCount=typeData.cellYEnd-typeData.cellYStart+1; }
/** * Calculate internal statistics that are the base for deciding if the given way type is * indexed at the given index level. * @param level * @param typeData * @param cellFillCount */ void AreaWayIndexGenerator::CalculateStatistics(size_t level, TypeData& typeData, const CoordCountMap& cellFillCount) const { // Initialize/reset data structure typeData.indexLevel=(uint32_t)level; typeData.indexCells=cellFillCount.size(); typeData.indexEntries=0; // If we do not have any entries, we are done ;-) if (cellFillCount.empty()) { return; } typeData.cellXStart=cellFillCount.begin()->first.x; typeData.cellYStart=cellFillCount.begin()->first.y; typeData.cellXEnd=typeData.cellXStart; typeData.cellYEnd=typeData.cellYStart; for (const auto& cell : cellFillCount) { typeData.indexEntries+=cell.second; typeData.cellXStart=std::min(typeData.cellXStart,cell.first.x); typeData.cellXEnd=std::max(typeData.cellXEnd,cell.first.x); typeData.cellYStart=std::min(typeData.cellYStart,cell.first.y); typeData.cellYEnd=std::max(typeData.cellYEnd,cell.first.y); } typeData.cellXCount=typeData.cellXEnd-typeData.cellXStart+1; typeData.cellYCount=typeData.cellYEnd-typeData.cellYStart+1; }
bool AreaWayIndexGenerator::FitsIndexCriteria(const ImportParameter& parameter, Progress& progress, const TypeInfo& typeInfo, const TypeData& typeData, const CoordCountMap& cellFillCount) { if (typeData.indexCells==0) { return true; } size_t entryCount=0; size_t max=0; for (CoordCountMap::const_iterator cell=cellFillCount.begin(); cell!=cellFillCount.end(); ++cell) { entryCount+=cell->second; max=std::max(max,cell->second); } // Average number of entries per tile cell double average=entryCount*1.0/cellFillCount.size(); // If the fill rate of the index is too low, we use this index level anyway if (typeData.indexCells/(1.0*typeData.cellXCount*typeData.cellYCount)<= parameter.GetAreaWayIndexMinFillRate()) { progress.Warning(typeInfo.GetName()+" ("+NumberToString(typeInfo.GetId())+") is not well distributed"); return true; } // If average fill size and max fill size for tile cells // is within limits, store it now. if (max<=parameter.GetAreaWayIndexCellSizeMax() && average<=parameter.GetAreaWayIndexCellSizeAverage()) { return true; } return false; }