Ejemplo n.º 1
0
int main(int argc, char* argv[])
{
  osmscout::ImportParameter parameter;
  osmscout::ConsoleProgress progress;
  bool                      parameterError=false;
  bool                      firstRouterOption=true;

  std::list<std::string>    mapfiles;

  osmscout::VehicleMask     defaultVehicleMask=osmscout::vehicleBicycle|osmscout::vehicleFoot|osmscout::vehicleCar;

  parameter.AddRouter(osmscout::ImportParameter::Router(defaultVehicleMask,
                                                        "router"));

  // Simple way to analyze command line parameters, but enough for now...
  int i=1;
  while (i<argc) {
    if (strcmp(argv[i],"-h")==0 ||
        strcmp(argv[i],"-?")==0 ||
        strcmp(argv[i],"--help")==0) {
      DumpHelp(parameter);

      return 0;
    }
    else if (strcmp(argv[i],"-s")==0) {
      size_t startStep;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             startStep)) {
        parameter.SetSteps(startStep,
                           parameter.GetEndStep());
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"-e")==0) {
      size_t endStep;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             endStep)) {
        parameter.SetSteps(parameter.GetStartStep(),
                           endStep);

      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"-d")==0) {
      progress.SetOutputDebug(true);

      i++;
    }
    else if (strcmp(argv[i],"--typefile")==0) {
      std::string typefile;

      if (ParseStringArgument(argc,
                              argv,
                              i,
                              typefile)) {
        parameter.SetTypefile(typefile);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--destinationDirectory")==0) {
      std::string destinationDirectory;

      if (ParseStringArgument(argc,
                              argv,
                              i,
                              destinationDirectory)) {
        parameter.SetDestinationDirectory(destinationDirectory);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--router")==0) {
      if (firstRouterOption) {
        parameter.ClearRouter();
        firstRouterOption=false;
      }

      osmscout::ImportParameter::RouterRef router=ParseRouterArgument(argc,
                                                                      argv,
                                                                      i);
      if (router) {
        parameter.AddRouter(*router);
      }
      else {
        parameterError=true;
      }

    }
    else if (strcmp(argv[i],"--strictAreas")==0) {
      bool strictAreas;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            strictAreas)) {
        parameter.SetStrictAreas(strictAreas);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--numericIndexPageSize")==0) {
      size_t numericIndexPageSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             numericIndexPageSize)) {
        parameter.SetNumericIndexPageSize(numericIndexPageSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--coordDataMemoryMaped")==0) {
      bool coordDataMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            coordDataMemoryMaped)) {
        parameter.SetCoordDataMemoryMaped(coordDataMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--rawNodeDataMemoryMaped")==0) {
      bool rawNodeDataMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            rawNodeDataMemoryMaped)) {
        parameter.SetRawNodeDataMemoryMaped(rawNodeDataMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--rawWayIndexMemoryMaped")==0) {
      bool rawWayIndexMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            rawWayIndexMemoryMaped)) {
        parameter.SetRawWayIndexMemoryMaped(rawWayIndexMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--rawWayDataMemoryMaped")==0) {
      bool rawWayDataMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            rawWayDataMemoryMaped)) {
        parameter.SetRawWayDataMemoryMaped(rawWayDataMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--rawWayIndexCacheSize")==0) {
      size_t rawWayIndexCacheSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             rawWayIndexCacheSize)) {
        parameter.SetRawWayIndexCacheSize(rawWayIndexCacheSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--rawWayBlockSize")==0) {
      size_t rawWayBlockSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             rawWayBlockSize)) {
        parameter.SetRawWayBlockSize(rawWayBlockSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"-noSort")==0) {
      parameter.SetSortObjects(false);

      i++;
    }
    else if (strcmp(argv[i],"--sortBlockSize")==0) {
      size_t sortBlockSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             sortBlockSize)) {
        parameter.SetSortBlockSize(sortBlockSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--areaDataMemoryMaped")==0) {
      bool areaDataMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            areaDataMemoryMaped)) {
        parameter.SetAreaDataMemoryMaped(areaDataMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--areaDataCacheSize")==0) {
      size_t areaDataCacheSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             areaDataCacheSize)) {
        parameter.SetAreaDataCacheSize(areaDataCacheSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--wayDataMemoryMaped")==0) {
      bool wayDataMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            wayDataMemoryMaped)) {
        parameter.SetWayDataMemoryMaped(wayDataMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--wayDataCacheSize")==0) {
      size_t wayDataCacheSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             wayDataCacheSize)) {
        parameter.SetWayDataCacheSize(wayDataCacheSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--routeNodeBlockSize")==0) {
      size_t routeNodeBlockSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             routeNodeBlockSize)) {
        parameter.SetRouteNodeBlockSize(routeNodeBlockSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strncmp(argv[i],"--",2)==0) {
      std::cerr << "Unknown option: " << argv[i] << std::endl;

      parameterError=true;
      i++;
    }
    else {
      mapfiles.push_back(argv[i]);

      i++;
    }
  }

  if (parameter.GetStartStep()==1 &&
      mapfiles.empty()) {
    parameterError=true;
  }

  if (parameterError) {
    DumpHelp(parameter);
    return 1;
  }

  parameter.SetMapfiles(mapfiles);

  parameter.SetOptimizationWayMethod(osmscout::TransPolygon::quality);

  progress.SetStep("Dump parameter");
  for (const auto& filename : parameter.GetMapfiles()) {
    progress.Info(std::string("Mapfile: ")+filename);
  }

  progress.Info(std::string("typefile: ")+parameter.GetTypefile());
  progress.Info(std::string("Destination directory: ")+parameter.GetDestinationDirectory());
  progress.Info(std::string("Steps: ")+
                osmscout::NumberToString(parameter.GetStartStep())+
                " - "+
                osmscout::NumberToString(parameter.GetEndStep()));

  for (const auto& router : parameter.GetRouter()) {
    progress.Info(std::string("Router: ")+VehcileMaskToString(router.GetVehicleMask())+ " - '"+router.GetFilenamebase()+"'");
  }

  progress.Info(std::string("StrictAreas: ")+
                (parameter.GetStrictAreas() ? "true" : "false"));

  progress.Info(std::string("NumericIndexPageSize: ")+
                osmscout::NumberToString(parameter.GetNumericIndexPageSize()));

  progress.Info(std::string("CoordDataMemoryMaped: ")+
                (parameter.GetCoordDataMemoryMaped() ? "true" : "false"));

  progress.Info(std::string("RawNodeDataMemoryMaped: ")+
                (parameter.GetRawNodeDataMemoryMaped() ? "true" : "false"));

  progress.Info(std::string("RawWayIndexMemoryMaped: ")+
                (parameter.GetRawWayIndexMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("RawWayDataMemoryMaped: ")+
                (parameter.GetRawWayDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("RawWayIndexCacheSize: ")+
                osmscout::NumberToString(parameter.GetRawWayIndexCacheSize()));
  progress.Info(std::string("RawWayBlockSize: ")+
                osmscout::NumberToString(parameter.GetRawWayBlockSize()));


  progress.Info(std::string("SortObjects: ")+
                (parameter.GetSortObjects() ? "true" : "false"));
  progress.Info(std::string("SortBlockSize: ")+
                osmscout::NumberToString(parameter.GetSortBlockSize()));

  progress.Info(std::string("AreaDataMemoryMaped: ")+
                (parameter.GetAreaDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("AreaDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetAreaDataCacheSize()));

  progress.Info(std::string("WayDataMemoryMaped: ")+
                (parameter.GetWayDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("WayDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetWayDataCacheSize()));

  progress.Info(std::string("RouteNodeBlockSize: ")+
                osmscout::NumberToString(parameter.GetRouteNodeBlockSize()));

  bool result=osmscout::Import(parameter,
                               progress);

  progress.SetStep("Summary");

  if (result) {

    double dataSize=0;

    if (!CountDataSize(parameter,
                       progress,
                       dataSize)) {
      progress.Error("Error while retrieving data size");
    }
    else {
      progress.Info(std::string("Resulting data size: ")+osmscout::ByteSizeToString(dataSize));
    }

    progress.Info("Import OK!");
  }
  else {
    progress.Error("Import failed!");
  }

  return 0;
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
  osmscout::ImportParameter parameter;
  osmscout::ConsoleProgress progress;
  bool                      parameterError=false;

  std::string               mapfile=parameter.GetMapfile();
  std::string               typefile=parameter.GetTypefile();
  std::string               destinationDirectory=parameter.GetDestinationDirectory();

  size_t                    startStep=parameter.GetStartStep();
  size_t                    endStep=parameter.GetEndStep();

  bool                      strictAreas=parameter.GetStrictAreas();

  size_t                    numericIndexPageSize=parameter.GetNumericIndexPageSize();

  size_t                    sortBlockSize=parameter.GetSortBlockSize();

  bool                      coordDataMemoryMaped=parameter.GetCoordDataMemoryMaped();

  bool                      rawNodeDataMemoryMaped=parameter.GetRawNodeDataMemoryMaped();
  size_t                    rawNodeDataCacheSize=parameter.GetRawNodeDataCacheSize();

  bool                      rawWayIndexMemoryMaped=parameter.GetRawWayIndexMemoryMaped();
  bool                      rawWayDataMemoryMaped=parameter.GetRawWayDataMemoryMaped();
  size_t                    rawWayDataCacheSize=parameter.GetRawWayDataCacheSize();
  size_t                    rawWayIndexCacheSize=parameter.GetRawWayIndexCacheSize();
  size_t                    rawWayBlockSize=parameter.GetRawWayBlockSize();

  bool                      areaDataMemoryMaped=parameter.GetAreaDataMemoryMaped();
  size_t                    areaDataCacheSize=parameter.GetAreaDataCacheSize();

  bool                      wayDataMemoryMaped=parameter.GetWayDataMemoryMaped();
  size_t                    wayDataCacheSize=parameter.GetWayDataCacheSize();

  size_t                    routeNodeBlockSize=parameter.GetRouteNodeBlockSize();

  // Simple way to analyse command line parameters, but enough for now...
  int i=1;
  while (i<argc) {
    if (strcmp(argv[i],"-s")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         startStep);
    }
    else if (strcmp(argv[i],"-e")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         endStep);
    }
    else if (strcmp(argv[i],"-d")==0) {
      progress.SetOutputDebug(true);

      i++;
    }
    else if (strcmp(argv[i],"-h")==0) {
      DumpHelp(parameter);

      return 0;
    }
    else if (strcmp(argv[i],"--help")==0) {
      DumpHelp(parameter);

      return 0;
    }
    else if (strcmp(argv[i],"--typefile")==0) {
      parameterError=!ParseStringArgument(argc,
                                          argv,
                                          i,
                                          typefile);
    }
    else if (strcmp(argv[i],"--destinationDirectory")==0) {
      parameterError=!ParseStringArgument(argc,
                                          argv,
                                          i,
                                          destinationDirectory);
    }
    else if (strcmp(argv[i],"--strictAreas")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        strictAreas);
    }
    else if (strcmp(argv[i],"--numericIndexPageSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         numericIndexPageSize);
    }
    else if (strcmp(argv[i],"--coordDataMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        coordDataMemoryMaped);
    }
    else if (strcmp(argv[i],"--rawNodeDataMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        rawNodeDataMemoryMaped);
    }
    else if (strcmp(argv[i],"--rawNodeDataCacheSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         rawNodeDataCacheSize);
    }
    else if (strcmp(argv[i],"--rawWayIndexMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        rawWayIndexMemoryMaped);
    }
    else if (strcmp(argv[i],"--rawWayDataMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        rawWayDataMemoryMaped);
    }
    else if (strcmp(argv[i],"--rawWayDataCacheSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         rawWayDataCacheSize);
    }
    else if (strcmp(argv[i],"--rawWayIndexCacheSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         rawWayIndexCacheSize);
    }
    else if (strcmp(argv[i],"--rawWayBlockSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         rawWayBlockSize);
    }
    else if (strcmp(argv[i],"-noSort")==0) {
      parameter.SetSortObjects(false);

      i++;
    }
    else if (strcmp(argv[i],"--sortBlockSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         sortBlockSize);
    }
    else if (strcmp(argv[i],"--areaDataMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        areaDataMemoryMaped);
    }
    else if (strcmp(argv[i],"--areaDataCacheSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         areaDataCacheSize);
    }
    else if (strcmp(argv[i],"--wayDataMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        wayDataMemoryMaped);
    }
    else if (strcmp(argv[i],"--wayDataCacheSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         wayDataCacheSize);
    }
    else if (strcmp(argv[i],"--routeNodeBlockSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         routeNodeBlockSize);
    }
    else if (mapfile.empty()) {
      mapfile=argv[i];

      i++;
    }
    else {
      std::cerr << "Unknown option: " << argv[i] << std::endl;

      parameterError=true;
      i++;
    }
  }

  if (startStep==1 &&
      mapfile.empty()) {
    parameterError=true;
  }

  if (parameterError) {
    DumpHelp(parameter);
    return 1;
  }

  parameter.SetMapfile(mapfile);
  parameter.SetTypefile(typefile);
  parameter.SetDestinationDirectory(destinationDirectory);
  parameter.SetSteps(startStep,endStep);

  parameter.SetStrictAreas(strictAreas);

  parameter.SetNumericIndexPageSize(numericIndexPageSize);

  parameter.SetSortBlockSize(sortBlockSize);

  parameter.SetCoordDataMemoryMaped(coordDataMemoryMaped);

  parameter.SetRawNodeDataMemoryMaped(rawNodeDataMemoryMaped);
  parameter.SetRawNodeDataCacheSize(rawNodeDataCacheSize);

  parameter.SetRawWayIndexMemoryMaped(rawWayIndexMemoryMaped);
  parameter.SetRawWayDataMemoryMaped(rawWayDataMemoryMaped);
  parameter.SetRawWayDataCacheSize(rawWayDataCacheSize);
  parameter.SetRawWayIndexCacheSize(rawWayIndexCacheSize);
  parameter.SetRawWayBlockSize(rawWayBlockSize);

  parameter.SetAreaDataMemoryMaped(areaDataMemoryMaped);
  parameter.SetAreaDataCacheSize(areaDataCacheSize);

  parameter.SetWayDataMemoryMaped(wayDataMemoryMaped);
  parameter.SetWayDataCacheSize(wayDataCacheSize);

  parameter.SetRouteNodeBlockSize(routeNodeBlockSize);

  parameter.SetOptimizationWayMethod(osmscout::TransPolygon::quality);

  progress.SetStep("Dump parameter");
  progress.Info(std::string("Mapfile: ")+parameter.GetMapfile());
  progress.Info(std::string("typefile: ")+parameter.GetTypefile());
  progress.Info(std::string("Destination directory: ")+parameter.GetDestinationDirectory());
  progress.Info(std::string("Steps: ")+
                osmscout::NumberToString(parameter.GetStartStep())+
                " - "+
                osmscout::NumberToString(parameter.GetEndStep()));

  progress.Info(std::string("StrictAreas: ")+
                (parameter.GetStrictAreas() ? "true" : "false"));

  progress.Info(std::string("NumericIndexPageSize: ")+
                osmscout::NumberToString(parameter.GetNumericIndexPageSize()));

  progress.Info(std::string("CoordDataMemoryMaped: ")+
                (parameter.GetCoordDataMemoryMaped() ? "true" : "false"));

  progress.Info(std::string("RawNodeDataMemoryMaped: ")+
                (parameter.GetRawNodeDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("RawNodeDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetRawNodeDataCacheSize()));

  progress.Info(std::string("RawWayIndexMemoryMaped: ")+
                (parameter.GetRawWayIndexMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("RawWayDataMemoryMaped: ")+
                (parameter.GetRawWayDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("RawWayDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetRawWayDataCacheSize()));
  progress.Info(std::string("RawWayIndexCacheSize: ")+
                osmscout::NumberToString(parameter.GetRawWayIndexCacheSize()));
  progress.Info(std::string("RawWayBlockSize: ")+
                osmscout::NumberToString(parameter.GetRawWayBlockSize()));


  progress.Info(std::string("SortObjects: ")+
                (parameter.GetSortObjects() ? "true" : "false"));
  progress.Info(std::string("SortBlockSize: ")+
                osmscout::NumberToString(parameter.GetSortBlockSize()));

  progress.Info(std::string("AreaDataMemoryMaped: ")+
                (parameter.GetAreaDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("AreaDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetAreaDataCacheSize()));

  progress.Info(std::string("WayDataMemoryMaped: ")+
                (parameter.GetWayDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("WayDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetWayDataCacheSize()));

  progress.Info(std::string("RouteNodeBlockSize: ")+
                osmscout::NumberToString(parameter.GetRouteNodeBlockSize()));

  if (osmscout::Import(parameter,progress)) {
    std::cout << "Import OK!" << std::endl;
  }
  else {
    std::cerr << "Import failed!" << std::endl;
  }

  return 0;
}