Пример #1
0
  bool Preprocess::Callback::StoreCoord(OSMId id,
                                        const GeoCoord& coord)
  {
    PageId     relatedId=id-std::numeric_limits<Id>::min();
    PageId     pageId=relatedId/coordPageSize;
    FileOffset coordPageIndex=relatedId%coordPageSize;

    if (currentPageId!=std::numeric_limits<PageId>::max()) {
      if (currentPageId==pageId) {
        coords[coordPageIndex]=coord;
        isSet[coordPageIndex]=true;

        return true;
      }
      else {
        StoreCurrentPage();
      }
    }

    CoordPageOffsetMap::const_iterator pageOffsetEntry=coordIndex.find(pageId);

    // Do we write a coord to a page, we have not yet written and
    // thus must begin a new page?
    if (pageOffsetEntry==coordIndex.end()) {
      isSet.assign(coordPageSize,false);

      coords[coordPageIndex]=coord;
      isSet[coordPageIndex]=true;

      FileOffset pageOffset=coordPageCount*coordPageSize*coordByteSize;

      currentPageId=pageId;
      currentPageOffset=pageOffset;

      pageOffsetEntry=coordIndex.insert(std::make_pair(pageId,pageOffset)).first;

      coordPageCount++;

      return true;
    }

    // We have to update a coord in a page we have already written
    if (!coordWriter.SetPos(pageOffsetEntry->second+coordPageIndex*coordByteSize)) {
      return false;
    }

    return coordWriter.WriteCoord(coord);
  }
Пример #2
0
  bool Preprocess::StoreCoord(OSMId id,
                              double lat,
                              double lon)
  {
    PageId relatedId=id-std::numeric_limits<Id>::min();
    PageId pageId=relatedId/coordPageSize;
    FileOffset coordPageOffset=relatedId%coordPageSize;

    if (currentPageId!=std::numeric_limits<PageId>::max()) {
      if (currentPageId==pageId) {
        lats[coordPageOffset]=lat;
        lons[coordPageOffset]=lon;
        isSet[coordPageOffset]=true;

        return true;
      }
      else {
        StoreCurrentPage();
      }
    }

    CoordPageOffsetMap::const_iterator pageOffsetEntry=coordIndex.find(pageId);

    if (pageOffsetEntry==coordIndex.end()) {
      isSet.assign(coordPageSize,false);

      lats[coordPageOffset]=lat;
      lons[coordPageOffset]=lon;
      isSet[coordPageOffset]=true;

      FileOffset pageOffset=coordPageCount*coordPageSize*2*sizeof(uint32_t);

      currentPageId=pageId;
      currentPageOffset=pageOffset;

      pageOffsetEntry=coordIndex.insert(std::make_pair(pageId,pageOffset)).first;

      coordPageCount++;

      return true;
    }

    if (!coordWriter.SetPos(pageOffsetEntry->second+coordPageOffset*2*sizeof(uint32_t))) {
      return false;
    }

    return coordWriter.WriteCoord(lat,lon);
  }
Пример #3
0
  bool Preprocess::Callback::Cleanup(bool success)
  {
    if (currentPageId!=0) {
      StoreCurrentPage();
    }

    nodeWriter.SetPos(0);
    nodeWriter.Write(nodeCount);

    wayWriter.SetPos(0);
    wayWriter.Write(wayCount+areaCount);

    coastlineWriter.SetPos(0);
    coastlineWriter.Write(coastlineCount);

    turnRestrictionWriter.SetPos(0);
    turnRestrictionWriter.Write(turnRestrictionCount);

    multipolygonWriter.SetPos(0);
    multipolygonWriter.Write(multipolygonCount);

    coordWriter.SetPos(0);

    coordWriter.Write(coordPageSize);

    FileOffset coordIndexOffset=coordPageCount*coordPageSize*2*sizeof(uint32_t);

    coordWriter.Write(coordIndexOffset);

    coordWriter.SetPos(coordIndexOffset);
    coordWriter.Write((uint32_t)coordIndex.size());

    for (CoordPageOffsetMap::const_iterator entry=coordIndex.begin();
         entry!=coordIndex.end();
         ++entry) {
      coordWriter.Write(entry->first);
      coordWriter.Write(entry->second);
    }

    nodeWriter.Close();
    wayWriter.Close();
    coastlineWriter.Close();
    coordWriter.Close();
    turnRestrictionWriter.Close();
    multipolygonWriter.Close();

    if (success) {
      progress.Info(std::string("Coords:           ")+NumberToString(coordCount));
      progress.Info(std::string("Coord pages:      ")+NumberToString(coordIndex.size()));
      progress.Info(std::string("Nodes:            ")+NumberToString(nodeCount));
      progress.Info(std::string("Ways/Areas/Sum:   ")+NumberToString(wayCount)+" "+
                    NumberToString(areaCount)+" "+
                    NumberToString(wayCount+areaCount));
      progress.Info(std::string("Relations:        ")+NumberToString(relationCount));
      progress.Info(std::string("Coastlines:       ")+NumberToString(coastlineCount));
      progress.Info(std::string("Turnrestrictions: ")+NumberToString(turnRestrictionCount));
      progress.Info(std::string("Multipolygons:    ")+NumberToString(multipolygonCount));

      for (const auto &type : typeConfig->GetTypes()) {
        size_t      i=type->GetIndex();
        bool        isEmpty=(type->CanBeNode() && nodeStat[i]==0) ||
                            (type->CanBeArea() && areaStat[i]==0) ||
                            (type->CanBeWay() && wayStat[i]==0);
        bool        isImportant=!type->GetIgnore() &&
                                !type->GetName().empty() &&
                                type->GetName()[0]!='_';

        if (isEmpty &&
            isImportant) {
          progress.Warning("Type "+type->GetName()+ ": "+NumberToString(nodeStat[i])+" node(s), "+NumberToString(areaStat[i])+" area(s), "+NumberToString(wayStat[i])+" ways(s)");
        }
        else {
          progress.Info("Type "+type->GetName()+ ": "+NumberToString(nodeStat[i])+" node(s), "+NumberToString(areaStat[i])+" area(s), "+NumberToString(wayStat[i])+" ways(s)");
        }
      }
    }

    //std::cout << "Bounding box: " << "[" << minCoord.GetLat() << "," << minCoord.GetLon() << " x " << maxCoord.GetLat() << "," << maxCoord.GetLon() << "]" << std::endl;

    if (nodeSortingError) {
      progress.Error("Nodes are not sorted by increasing id");
    }

    if (waySortingError) {
      progress.Error("Ways are not sorted by increasing id");
    }

    if (relationSortingError) {
      progress.Error("Relations are not sorted by increasing id");
    }

    if (nodeSortingError || waySortingError || relationSortingError) {
      return false;
    }

    if (success) {
      if (!DumpDistribution()) {
        return false;
      }

      if (!DumpBoundingBox()) {
        return false;
      }
    }

    return true;
  }
Пример #4
0
  bool Preprocess::Cleanup(Progress& progress)
  {
    if (currentPageId!=0) {
      StoreCurrentPage();
    }

    nodeWriter.SetPos(0);
    nodeWriter.Write(nodeCount);

    wayWriter.SetPos(0);
    wayWriter.Write(wayCount+areaCount);

    relationWriter.SetPos(0);
    relationWriter.Write(relationCount);

    coastlineWriter.SetPos(0);
    coastlineWriter.Write(coastlineCount);

    coordWriter.SetPos(0);

    coordWriter.Write(coordPageSize);

    FileOffset coordIndexOffset=coordPageCount*coordPageSize*2*sizeof(uint32_t);

    coordWriter.Write(coordIndexOffset);

    coordWriter.SetPos(coordIndexOffset);
    coordWriter.Write((uint32_t)coordIndex.size());

    for (CoordPageOffsetMap::const_iterator entry=coordIndex.begin();
         entry!=coordIndex.end();
         ++entry) {
      coordWriter.Write(entry->first);
      coordWriter.Write(entry->second);
    }

    nodeWriter.Close();
    wayWriter.Close();
    relationWriter.Close();
    coastlineWriter.Close();
    coordWriter.Close();

    progress.Info(std::string("Nodes:          ")+NumberToString(nodeCount));
    progress.Info(std::string("Ways/Areas/Sum: ")+NumberToString(wayCount)+" "+
                  NumberToString(areaCount)+" "+
                  NumberToString(wayCount+areaCount));
    progress.Info(std::string("Relations:      ")+NumberToString(relationCount));
    progress.Info(std::string("Coastlines:     ")+NumberToString(coastlineCount));
    progress.Info(std::string("Coord pages:    ")+NumberToString(coordIndex.size()));

    if (nodeSortingError) {
      progress.Error("Nodes are not sorted by increasing id");
    }

    if (waySortingError) {
      progress.Error("Ways are not sorted by increasing id");
    }

    if (relationSortingError) {
      progress.Error("Relations are not sorted by increasing id");
    }

    if (nodeSortingError || waySortingError || relationSortingError) {
      return false;
    }

    return true;
  }