本文整理汇总了C++中Progress::SetProgress方法的典型用法代码示例。如果您正苦于以下问题:C++ Progress::SetProgress方法的具体用法?C++ Progress::SetProgress怎么用?C++ Progress::SetProgress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Progress
的用法示例。
在下文中一共展示了Progress::SetProgress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetAreas
bool OptimizeAreasLowZoomGenerator::GetAreas(const TypeConfig& typeConfig,
const ImportParameter& parameter,
Progress& progress,
FileScanner& scanner,
const TypeInfoSet& types,
std::vector<std::list<AreaRef> >& areas,
TypeInfoSet& loadedTypes)
{
uint32_t areaCount=0;
size_t collectedAreasCount=0;
loadedTypes=types;
progress.SetAction("Collecting area data to optimize");
scanner.GotoBegin();
scanner.Read(areaCount);
for (uint32_t a=1; a<=areaCount; a++) {
AreaRef area=std::make_shared<Area>();
progress.SetProgress(a,areaCount);
area->Read(typeConfig,
scanner);
if (loadedTypes.IsSet(area->GetType())) {
areas[area->GetType()->GetIndex()].push_back(area);
collectedAreasCount++;
while (collectedAreasCount>parameter.GetOptimizationMaxWayCount() &&
loadedTypes.Size()>1) {
TypeInfoRef victimType;
for (auto &type : loadedTypes) {
if (areas[type->GetIndex()].size()>0 &&
(!victimType ||
areas[type->GetIndex()].size()<areas[victimType->GetIndex()].size())) {
victimType=type;
}
}
assert(victimType);
collectedAreasCount-=areas[victimType->GetIndex()].size();
areas[victimType->GetIndex()].clear();
loadedTypes.Remove(victimType);
}
}
}
progress.Info("Collected "+NumberToString(collectedAreasCount)+" areas for "+NumberToString(loadedTypes.Size())+" types");
return !scanner.HasError();
}
示例2: MergeAreas
void MergeAreasGenerator::MergeAreas(Progress& progress,
const std::unordered_set<Id>& nodeUseMap,
AreaMergeData& job)
{
std::unordered_map<Id,std::set<AreaRef> > idAreaMap;
size_t overallCount=job.areas.size();
IndexAreasByNodeIds(nodeUseMap,
job.areas,
idAreaMap);
progress.Info("Found "+NumberToString(idAreaMap.size())+" nodes as possible connection points for areas");
while (!job.areas.empty()) {
AreaRef area;
progress.SetProgress(overallCount-job.areas.size(),overallCount);
// Pop a area from the list of "to be processed" areas
area=job.areas.front();
job.areas.pop_front();
// This areas has already be "handled", ignore it
if (job.mergedAway.find(area->GetFileOffset())!=job.mergedAway.end()) {
continue;
}
// Delete all mentioning of this area in the idAreaMap cache
EraseAreaInCache(nodeUseMap,
area,
idAreaMap);
std::set<Id> finishedIds;
// Now try to merge it against candidates that share the same ids.
if (TryMerge(nodeUseMap,
*area,
idAreaMap,
finishedIds,
job.mergedAway)) {
job.merges.push_back(area);
while (TryMerge(nodeUseMap,
*area,
idAreaMap,
finishedIds,
job.mergedAway)) {
// no code
}
}
}
}
示例3: Import
bool NodeDataGenerator::Import(const TypeConfigRef& typeConfig,
const ImportParameter& parameter,
Progress& progress)
{
uint32_t rawNodeCount=0;
uint32_t nodesReadCount=0;
uint32_t nodesWrittenCount=0;
//
// Iterator over all raw nodes, hcekc they type, and convert them from raw nodes
// to nodes if the type is interesting (!=typeIgnore).
//
// Count the bounding box by the way...
//
progress.SetAction("Generating nodes.tmp");
FileScanner scanner;
FileWriter writer;
if (!scanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"rawnodes.dat"),
FileScanner::Sequential,
parameter.GetRawNodeDataMemoryMaped())) {
progress.Error("Cannot open 'rawnodes.dat'");
return false;
}
if (!scanner.Read(rawNodeCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
if (!writer.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"nodes.tmp"))) {
progress.Error("Cannot create 'nodes.tmp'");
return false;
}
writer.Write(nodesWrittenCount);
for (uint32_t n=1; n<=rawNodeCount; n++) {
progress.SetProgress(n,rawNodeCount);
RawNode rawNode;
Node node;
if (!rawNode.Read(typeConfig,
scanner)) {
progress.Error(std::string("Error while reading data entry ")+
NumberToString(n)+" of "+
NumberToString(rawNodeCount)+
" in file '"+
scanner.GetFilename()+"'");
return false;
}
nodesReadCount++;
if (!rawNode.GetType()->GetIgnore()) {
node.SetFeatures(rawNode.GetFeatureValueBuffer());
node.SetCoords(rawNode.GetCoords());
FileOffset fileOffset;
if (!writer.GetPos(fileOffset)) {
progress.Error(std::string("Error while reading current fileOffset in file '")+
writer.GetFilename()+"'");
return false;
}
writer.Write(rawNode.GetId());
node.Write(typeConfig,
writer);
nodesWrittenCount++;
}
}
if (!scanner.Close()) {
return false;
}
writer.SetPos(0);
writer.Write(nodesWrittenCount);
if (!writer.Close()) {
return false;
}
progress.Info(std::string("Read "+NumberToString(nodesReadCount)+" nodes, wrote "+NumberToString(nodesWrittenCount)+" nodes"));
return true;
}
示例4: Import
bool AreaAreaIndexGenerator::Import(const TypeConfigRef& typeConfig,
const ImportParameter& parameter,
Progress& progress)
{
FileScanner scanner;
size_t areas=0; // Number of areas found
size_t areasConsumed=0; // Number of areas consumed
std::vector<double> cellWidth;
std::vector<double> cellHeight;
std::map<Pixel,AreaLeaf> leafs;
std::map<Pixel,AreaLeaf> newAreaLeafs;
cellWidth.resize(parameter.GetAreaAreaIndexMaxMag()+1);
cellHeight.resize(parameter.GetAreaAreaIndexMaxMag()+1);
for (size_t i=0; i<cellWidth.size(); i++) {
cellWidth[i]=360.0/pow(2.0,(int)i);
}
for (size_t i=0; i<cellHeight.size(); i++) {
cellHeight[i]=180.0/pow(2.0,(int)i);
}
//
// Writing index file
//
progress.SetAction("Generating 'areaarea.idx'");
FileWriter writer;
FileOffset topLevelOffset=0;
FileOffset topLevelOffsetOffset; // Offset of the toplevel entry
if (!writer.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"areaarea.idx"))) {
progress.Error("Cannot create 'areaarea.idx'");
return false;
}
if (!scanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"areas.dat"),
FileScanner::Sequential,
parameter.GetWayDataMemoryMaped())) {
progress.Error("Cannot open 'areas.dat'");
return false;
}
writer.WriteNumber((uint32_t)parameter.GetAreaAreaIndexMaxMag()); // MaxMag
if (!writer.GetPos(topLevelOffsetOffset)) {
progress.Error("Cannot read current file position");
return false;
}
if (!writer.WriteFileOffset(topLevelOffset)) {
progress.Error("Cannot write top level entry offset");
return false;
}
int l=parameter.GetAreaAreaIndexMaxMag();
while (l>=0) {
size_t areaLevelEntries=0;
progress.Info(std::string("Storing level ")+NumberToString(l)+"...");
newAreaLeafs.clear();
SetOffsetOfChildren(leafs,newAreaLeafs);
leafs=newAreaLeafs;
// Areas
if (areas==0 ||
(areas>0 && areas>areasConsumed)) {
uint32_t areaCount=0;
progress.Info(std::string("Scanning areas.dat for areas of index level ")+NumberToString(l)+"...");
if (!scanner.GotoBegin()) {
progress.Error("Cannot go to begin of way file");
}
if (!scanner.Read(areaCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
areas=0;
for (uint32_t a=1; a<=areaCount; a++) {
progress.SetProgress(a,areaCount);
FileOffset offset;
Area area;
scanner.GetPos(offset);
if (!area.Read(typeConfig,
scanner)) {
//.........这里部分代码省略.........
示例5: ScanAreaNodeIds
/**
* Scans all areas. If an areas is of one of the given merge types, index all node ids
* into the given NodeUseMap for all outer rings of the given area.
*/
bool MergeAreasGenerator::ScanAreaNodeIds(Progress& progress,
const TypeConfig& typeConfig,
FileScanner& scanner,
const TypeInfoSet& mergeTypes,
std::unordered_set<Id>& nodeUseMap)
{
uint32_t areaCount=0;
progress.SetAction("Scanning for nodes joining areas from '"+scanner.GetFilename()+"'");
scanner.GotoBegin();
scanner.Read(areaCount);
uint8_t type;
Id id;
Area data;
std::unordered_set<Id> usedOnceSet;
for (uint32_t current=1; current<=areaCount; current++) {
progress.SetProgress(current,areaCount);
scanner.Read(type);
scanner.Read(id);
data.ReadImport(typeConfig,
scanner);
if (!mergeTypes.IsSet(data.GetType())) {
continue;
}
// We insert every node id only once per area, because we want to
// find nodes that are shared by *different* areas.
std::unordered_set<Id> nodeIds;
for (const auto& ring: data.rings) {
if (!ring.IsOuterRing()) {
continue;
}
for (const auto node : ring.nodes) {
Id id=node.GetId();
if (nodeIds.find(id)==nodeIds.end()) {
auto entry=usedOnceSet.find(id);
if (entry!=usedOnceSet.end()) {
nodeUseMap.insert(id);
}
else {
usedOnceSet.insert(id);
}
nodeIds.insert(id);
}
}
}
}
return true;
}
示例6: WriteMergeResult
bool MergeAreasGenerator::WriteMergeResult(Progress& progress,
const TypeConfig& typeConfig,
FileScanner& scanner,
FileWriter& writer,
const TypeInfoSet& loadedTypes,
std::vector<AreaMergeData>& mergeJob,
uint32_t& areasWritten)
{
uint32_t areaCount=0;
std::unordered_map<FileOffset,AreaRef> merges;
std::unordered_set<FileOffset> ignores;
for (const auto& type : loadedTypes) {
for (const auto& area : mergeJob[type->GetIndex()].merges) {
merges[area->GetFileOffset()]=area;
}
ignores.insert(mergeJob[type->GetIndex()].mergedAway.begin(),
mergeJob[type->GetIndex()].mergedAway.end());
}
scanner.GotoBegin();
scanner.Read(areaCount);
for (uint32_t a=1; a<=areaCount; a++) {
uint8_t type;
Id id;
AreaRef area=std::make_shared<Area>();
progress.SetProgress(a,areaCount);
scanner.Read(type);
scanner.Read(id);
area->ReadImport(typeConfig,
scanner);
if (loadedTypes.IsSet(area->GetType())) {
if (ignores.find(area->GetFileOffset())!=ignores.end()) {
continue;
}
writer.Write(type);
writer.Write(id);
const auto& merge=merges.find(area->GetFileOffset()) ;
if (merge!=merges.end()) {
area=merge->second;
}
area->WriteImport(typeConfig,
writer);
areasWritten++;
}
}
return true;
}
示例7: GetAreas
/**
* Load areas which has a one for the types given by types. If at leats one node
* in one of the outer rings of the areas is marked in nodeUseMap as "used at least twice",
* index it into the areas map.
*
* If the number of indexed areas is bigger than parameter.GetRawWayBlockSize() types are
* dropped form areas until the number is again below the lmit.
*/
bool MergeAreasGenerator::GetAreas(const ImportParameter& parameter,
Progress& progress,
const TypeConfig& typeConfig,
const TypeInfoSet& candidateTypes,
TypeInfoSet& loadedTypes,
const std::unordered_set<Id>& nodeUseMap,
FileScanner& scanner,
FileWriter& writer,
std::vector<AreaMergeData>& mergeJob,
uint32_t& areasWritten)
{
bool firstCall=areasWritten==0; // We are called for the first time
uint32_t areaCount=0;
size_t collectedAreasCount=0;
size_t typesWithAreas=0;
for (auto& data : mergeJob) {
data.areaCount=0;
}
loadedTypes=candidateTypes;
scanner.GotoBegin();
scanner.Read(areaCount);
for (uint32_t a=1; a<=areaCount; a++) {
uint8_t type;
Id id;
AreaRef area=std::make_shared<Area>();
progress.SetProgress(a,areaCount);
scanner.Read(type);
scanner.Read(id);
area->ReadImport(typeConfig,
scanner);
mergeJob[area->GetType()->GetIndex()].areaCount++;
// This is an area of a type that does not get merged,
// we directly store it in the target file.
if (!loadedTypes.IsSet(area->GetType())) {
if (firstCall) {
writer.Write(type);
writer.Write(id);
area->WriteImport(typeConfig,
writer);
areasWritten++;
}
continue;
}
bool isMergeCandidate=false;
for (const auto& ring: area->rings) {
if (!ring.IsOuterRing()) {
continue;
}
for (const auto node : ring.nodes) {
if (nodeUseMap.find(node.GetId())!=nodeUseMap.end()) {
isMergeCandidate=true;
break;
}
}
if (isMergeCandidate) {
break;
}
}
if (!isMergeCandidate) {
continue;
}
if (mergeJob[area->GetType()->GetIndex()].areas.empty()) {
typesWithAreas++;
}
mergeJob[area->GetType()->GetIndex()].areas.push_back(area);
collectedAreasCount++;
while (collectedAreasCount>parameter.GetRawWayBlockSize() &&
typesWithAreas>1) {
TypeInfoRef victimType;
//.........这里部分代码省略.........
示例8: ScanAreaIds
bool OptimizeAreaWayIdsGenerator::ScanAreaIds(const ImportParameter& parameter,
Progress& progress,
const TypeConfig& typeConfig,
NodeUseMap& nodeUseMap)
{
FileScanner scanner;
uint32_t dataCount=0;
progress.SetAction("Scanning ids from 'areas2.tmp'");
if (!scanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"areas2.tmp"),
FileScanner::Sequential,
parameter.GetAreaDataMemoryMaped())) {
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;
Area data;
progress.SetProgress(current,dataCount);
if (!scanner.Read(type) ||
!scanner.Read(id) ||
!data.ReadImport(typeConfig,
scanner)) {
progress.Error(std::string("Error while reading data entry ")+
NumberToString(current)+" of "+
NumberToString(dataCount)+
" in file '"+
scanner.GetFilename()+"'");
return false;
}
for (const auto& ring: data.rings) {
std::unordered_set<Id> nodeIds;
if (!ring.GetType()->CanRoute()) {
continue;
}
for (const auto id: ring.ids) {
if (nodeIds.find(id)==nodeIds.end()) {
nodeUseMap.SetNodeUsed(id);
nodeIds.insert(id);
}
}
}
}
if (!scanner.Close()) {
progress.Error(std::string("Error while closing file '")+
scanner.GetFilename()+"'");
return false;
}
return true;
}
示例9: CopyWays
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;
}
示例10: ScanWayIds
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;
}
示例11: Import
bool AreaNodeIndexGenerator::Import(const ImportParameter& parameter,
Progress& progress,
const TypeConfig& typeConfig)
{
FileScanner nodeScanner;
FileWriter writer;
std::set<TypeId> remainingNodeTypes; //! Set of types we still must process
std::vector<TypeData> nodeTypeData;
size_t level;
size_t maxLevel=0;
nodeTypeData.resize(typeConfig.GetTypes().size());
if (!nodeScanner.Open(AppendFileToDir(parameter.GetDestinationDirectory(),
"nodes.dat"),
FileScanner::Sequential,
true)) {
progress.Error("Cannot open 'nodes.dat'");
return false;
}
//
// Scanning distribution
//
progress.SetAction("Scanning level distribution of node types");
// Initially we must process all types that represents nodes and that should
// not be ignored
for (size_t i=0; i<typeConfig.GetTypes().size(); i++) {
if (typeConfig.GetTypeInfo(i).CanBeNode() &&
!typeConfig.GetTypeInfo(i).GetIgnore()) {
remainingNodeTypes.insert(i);
}
}
level=parameter.GetAreaNodeMinMag();
while (!remainingNodeTypes.empty()) {
uint32_t nodeCount=0;
std::set<TypeId> currentNodeTypes(remainingNodeTypes);
double cellWidth=360.0/pow(2.0,(int)level);
double cellHeight=180.0/pow(2.0,(int)level);
std::vector<std::map<Pixel,size_t> > cellFillCount;
cellFillCount.resize(typeConfig.GetTypes().size());
progress.Info("Scanning Level "+NumberToString(level)+" ("+NumberToString(remainingNodeTypes.size())+" types still to process)");
nodeScanner.GotoBegin();
if (!nodeScanner.Read(nodeCount)) {
progress.Error("Error while reading number of data entries in file");
return false;
}
for (uint32_t n=1; n<=nodeCount; n++) {
progress.SetProgress(n,nodeCount);
FileOffset offset;
Node node;
nodeScanner.GetPos(offset);
if (!node.Read(nodeScanner)) {
progress.Error(std::string("Error while reading data entry ")+
NumberToString(n)+" of "+
NumberToString(nodeCount)+
" in file '"+
nodeScanner.GetFilename()+"'");
return false;
}
// If we still need to handle this type,
// count number of entries per type and tile cell
if (currentNodeTypes.find(node.GetType())!=currentNodeTypes.end()) {
uint32_t xc=(uint32_t)floor((node.GetLon()+180.0)/cellWidth);
uint32_t yc=(uint32_t)floor((node.GetLat()+90.0)/cellHeight);
cellFillCount[node.GetType()][Pixel(xc,yc)]++;
}
}
// Check statistics for each type
// If statistics are within goal limits, use this level
// for this type (else try again with the next higher level)
for (size_t i=0; i<typeConfig.GetTypes().size(); i++) {
if (currentNodeTypes.find(i)!=currentNodeTypes.end()) {
size_t entryCount=0;
size_t max=0;
nodeTypeData[i].indexLevel=(uint32_t)level;
nodeTypeData[i].indexCells=cellFillCount[i].size();
nodeTypeData[i].indexEntries=0;
if (!cellFillCount[i].empty()) {
nodeTypeData[i].cellXStart=cellFillCount[i].begin()->first.x;
nodeTypeData[i].cellYStart=cellFillCount[i].begin()->first.y;
nodeTypeData[i].cellXEnd=nodeTypeData[i].cellXStart;
nodeTypeData[i].cellYEnd=nodeTypeData[i].cellYStart;
//.........这里部分代码省略.........
示例12: Import
bool PreprocessPBF::Import(const TypeConfigRef& typeConfig,
const ImportParameter& /*parameter*/,
Progress& progress,
const std::string& filename)
{
FileOffset fileSize;
FileOffset currentPosition;
progress.SetAction(std::string("Parsing *.osm.pbf file '")+filename+"'");
try {
fileSize=GetFileSize(filename);
FILE* file;
file=fopen(filename.c_str(),"rb");
if (file==NULL) {
progress.Error("Cannot open file!");
return false;
}
// BlockHeader
PBF::BlockHeader blockHeader;
if (!ReadBlockHeader(progress,file,blockHeader,false)) {
fclose(file);
return false;
}
if (blockHeader.type()!="OSMHeader") {
progress.Error("File '"+filename+"' is not an OSM PBF file!");
fclose(file);
return false;
}
PBF::HeaderBlock headerBlock;
if (!ReadHeaderBlock(progress,
file,
blockHeader,
headerBlock)) {
fclose(file);
return false;
}
for (int i=0; i<headerBlock.required_features_size(); i++) {
std::string feature=headerBlock.required_features(i);
if (feature!="OsmSchema-V0.6" &&
feature!="DenseNodes") {
progress.Error(std::string("Unsupported feature '")+feature+"'");
fclose(file);
return false;
}
}
nodes.reserve(20000);
members.reserve(2000);
std::future<void> currentBlockTask;
while (true) {
PBF::BlockHeader blockHeader;
if (!GetPos(file,
currentPosition)) {
progress.Error("Cannot read current position in '"+filename+"'!");
fclose(file);
return false;
}
progress.SetProgress(currentPosition,
fileSize);
if (!ReadBlockHeader(progress,
file,
blockHeader,
true)) {
fclose(file);
break;
}
if (blockHeader.type()!="OSMData") {
progress.Error("File '"+filename+"' is not an OSM PBF file!");
fclose(file);
return false;
}
std::unique_ptr<PBF::PrimitiveBlock> block(new PBF::PrimitiveBlock());
if (!ReadPrimitiveBlock(progress,
file,
blockHeader,
*block)) {
fclose(file);
return false;
}
if (currentBlockTask.valid()) {
//.........这里部分代码省略.........
示例13: Import
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,
//.........这里部分代码省略.........
示例14: Import
//.........这里部分代码省略.........
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();
}
示例15: CalculateDistribution
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);
//.........这里部分代码省略.........