Welcome to mirror list, hosted at ThFree Co, Russian Federation.

srtm_coverage_checker.cpp « srtm_coverage_checker « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 28b366ea05670fcaaf9f3e9653ec5d1c7e43b300 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "generator/srtm_parser.hpp"

#include "map/feature_vec_model.hpp"

#include "routing/routing_integration_tests/routing_test_tools.hpp"

#include "indexer/feature_altitude.hpp"

#include "coding/file_name_utils.hpp"

#include "platform/country_file.hpp"
#include "platform/local_country_file_utils.hpp"

#include "base/logging.hpp"

#include "std/algorithm.hpp"

#include "3party/gflags/src/gflags/gflags.h"

DEFINE_string(srtm_path, "", "Path to directory with SRTM files");
DEFINE_string(mwm_path, "", "Path to mwm files (writable dir)");

int main(int argc, char * argv[])
{
  google::SetUsageMessage("SRTM coverage checker.");
  google::ParseCommandLineFlags(&argc, &argv, true);

  Platform & platform = GetPlatform();
  if (!FLAGS_mwm_path.empty())
    platform.SetWritableDirForTests(FLAGS_mwm_path);

  if (FLAGS_srtm_path.empty())
  {
    LOG(LERROR, ("SRTM files directory is not specified."));
    return -1;
  }

  LOG(LINFO, ("writable dir =", platform.WritableDir()));
  LOG(LINFO, ("srtm dir =", FLAGS_srtm_path));

  vector<platform::LocalCountryFile> localFiles;
  platform::FindAllLocalMapsAndCleanup(numeric_limits<int64_t>::max() /* latestVersion */,
                                       localFiles);

  auto fetcher = integration::CreateFeaturesFetcher(localFiles);
  generator::SrtmTileManager manager(FLAGS_srtm_path);

  for (auto & file : localFiles)
  {
    file.SyncWithDisk();
    if (file.GetFiles() != MapOptions::MapWithCarRouting)
    {
      LOG(LINFO, ("Warning! Routing file not found for:", file.GetCountryName()));
      continue;
    }

    FilesMappingContainer container(file.GetPath(MapOptions::CarRouting));
    if (!container.IsExist(ROUTING_FTSEG_FILE_TAG))
    {
      LOG(LINFO, ("Warning! Mwm file has not routing ftseg section:", file.GetCountryName()));
      continue;
    }

    routing::TDataFacade dataFacade;
    dataFacade.Load(container);

    OsrmFtSegMapping segMapping;
    segMapping.Load(container, file);
    segMapping.Map(container);

    size_t all = 0;
    size_t good = 0;

    for (TOsrmNodeId i = 0; i < dataFacade.GetNumberOfNodes(); ++i)
    {
      buffer_vector<OsrmMappingTypes::FtSeg, 8> buffer;
      segMapping.ForEachFtSeg(i, MakeBackInsertFunctor(buffer));

      vector<m2::PointD> path;
      for (size_t k = 0; k < buffer.size(); ++k)
      {
        auto const & segment = buffer[k];
        if (!segment.IsValid())
          continue;
        // Load data from drive.
        FeatureType ft;
        Index::FeaturesLoaderGuard loader(
            fetcher->GetIndex(), fetcher->GetIndex().GetMwmIdByCountryFile(file.GetCountryFile()));
        if (!loader.GetFeatureByIndex(segment.m_fid, ft))
          continue;
        ft.ParseGeometry(FeatureType::BEST_GEOMETRY);

        // Get points in proper direction.
        auto const startIdx = segment.m_pointStart;
        auto const endIdx = segment.m_pointEnd;
        for (auto idx = min(startIdx, endIdx); idx <= max(startIdx, endIdx); ++idx)
          path.push_back(ft.GetPoint(idx));

        all += path.size();
        for (auto const & point : path)
        {
          auto const height = manager.GetHeight(MercatorBounds::ToLatLon(point));
          if (height != feature::kInvalidAltitude)
            good++;
        }
      }
    }

    auto const bad = all - good;
    auto const percent = all == 0 ? 0.0 : bad * 100.0 / all;
    if (percent > 10.0)
    {
      LOG(LINFO, ("Huge error rate in:", file.GetCountryName(), "good:", good, "bad:", bad, "all:",
                  all, "%:", percent));
    }
  }

  return 0;
}