コード例 #1
0
ファイル: NumericRisk.cpp プロジェクト: raphaelrpl/terrama2
int main(int argc, char* argv[])
{
  terrama2::core::TerraMA2Init terramaRaii("example", 0);
  terrama2::core::registerFactories();
  terrama2::services::alert::core::registerFactories();

  {
    auto dataManager = std::make_shared<terrama2::services::alert::core::DataManager>();

    dataManager->add(inputDataProvider());
    dataManager->add(inputDataSeries());
    dataManager->add(additionalDataProvider());
    dataManager->add(additionalDataSeries());
    auto alert = newAlert();
    dataManager->add(alert);

    auto now = terrama2::core::TimeUtils::nowUTC();

    terrama2::services::alert::core::runAlert(std::make_pair(alert->id, now), nullptr, dataManager);
  }

  

  return 0;
}
コード例 #2
0
int main(int argc, char* argv[])
{
  try
  {
    terrama2::core::TerraMA2Init terramaRaii("example", 0);
    terrama2::core::registerFactories();

    {
      QCoreApplication app(argc, argv);
      auto& serviceManager = terrama2::core::ServiceManager::getInstance();
      te::core::URI uri("pgsql://"+TERRAMA2_DATABASE_USERNAME+":"+TERRAMA2_DATABASE_PASSWORD+"@"+TERRAMA2_DATABASE_HOST+":"+TERRAMA2_DATABASE_PORT+"/"+TERRAMA2_DATABASE_DBNAME);
      serviceManager.setLogConnectionInfo(uri);
      serviceManager.setInstanceId(1);

      auto dataManager = std::make_shared<terrama2::services::collector::core::DataManager>();

      addInput(dataManager);
      addOutput(dataManager);

      terrama2::services::collector::core::Service service(dataManager);
      auto logger = std::make_shared<terrama2::services::collector::core::CollectorLogger>();
      logger->setConnectionInfo(uri);
      service.setLogger(logger);
      service.start();

      terrama2::services::collector::core::Collector* collector(new terrama2::services::collector::core::Collector());
      terrama2::services::collector::core::CollectorPtr collectorPtr(collector);
      collector->id = 777;
      collector->projectId = 1;
      collector->serviceInstanceId = 1;
      collector->filter.region = terrama2::core::ewktToGeom("SRID=4326;POLYGON((-73.8036991603083 -9.81412714740936,-73.8036991603083 2.24662115728613,-56.097053202293 2.24662115728613,-56.097053202293 -9.81412714740936,-73.8036991603083 -9.81412714740936))");
      collector->filter.cropRaster = true;
      collector->filter.discardBefore = terrama2::core::TimeUtils::stringToTimestamp("2016-11-25T06:00:00.000-02:00", terrama2::core::TimeUtils::webgui_timefacet);
      collector->filter.discardAfter = terrama2::core::TimeUtils::stringToTimestamp("2016-11-25T12:00:00.000-02:00", terrama2::core::TimeUtils::webgui_timefacet);

      collector->inputDataSeries = 1;
      collector->outputDataSeries = 2;
      collector->inputOutputMap.emplace(1, 2);

      dataManager->add(collectorPtr);

      service.addToQueue(collectorPtr->id, terrama2::core::TimeUtils::nowUTC());

      QTimer timer;
      QObject::connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit()));
      timer.start(10000);
      app.exec();

      service.stopService();
    }
  }
  catch(...)
  {
    std::cout << "\n\nException...\n" << std::endl;
  }

  return 0;
}
コード例 #3
0
int main(int argc, char* argv[])
{
  terrama2::core::TerraMA2Init terramaRaii("example", 0);

  {
    //DataProvider information
    terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider();
    terrama2::core::DataProviderPtr dataProviderPtr(dataProvider);
    dataProvider->uri = "file://";
    dataProvider->uri += TERRAMA2_DATA_DIR;
    dataProvider->uri += "/geotiff";

    dataProvider->intent = terrama2::core::DataProviderIntent::COLLECTOR_INTENT;
    dataProvider->dataProviderType = "FILE";
    dataProvider->active = true;


    auto& semanticsManager = terrama2::core::SemanticsManager::getInstance();

    //DataSeries information
    terrama2::core::DataSeries* dataSeries = new terrama2::core::DataSeries();
    terrama2::core::DataSeriesPtr dataSeriesPtr(dataSeries);
    dataSeries->semantics = semanticsManager.getSemantics("GRID-geotiff");

    terrama2::core::DataSetGrid* dataSet = new terrama2::core::DataSetGrid();
    dataSet->active = true;
    dataSet->format.emplace("mask", "L5219076_07620040908_r3g2b1.tif");

    dataSeries->datasetList.emplace_back(dataSet);

    //empty filter
    terrama2::core::Filter filter;
    //accessing data
    terrama2::core::DataAccessorGeoTiff accessor(dataProviderPtr, dataSeriesPtr);
    auto remover = std::make_shared<terrama2::core::FileRemover>();
    terrama2::core::GridSeriesPtr gridSeries = accessor.getGridSeries(filter, remover);

    assert(gridSeries->gridMap().size() == 1);

auto raster = gridSeries->gridMap().begin()->second;
    assert(raster->getSRID() != 0);

    std::cout << "SRID: " << raster->getSRID() << std::endl;

    std::string output = TERRAMA2_DATA_DIR;
    output+="/grid_output.tif";

    te::rp::Copy2DiskRaster(*raster, output);

    std::cout << "Tiff file copied to " << output << std::endl;
  }

  

  return 0;
}
コード例 #4
0
int main(int argc, char* argv[])
{
  terrama2::core::TerraMA2Init terramaRaii("example", 0);

  {
    //DataProvider information
    terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider();
    terrama2::core::DataProviderPtr dataProviderPtr(dataProvider);
    dataProvider->uri = "file://";
    dataProvider->uri+=TERRAMA2_DATA_DIR;
    dataProvider->uri+="/PCD_serrmar_INPE";

    dataProvider->intent = terrama2::core::DataProviderIntent::COLLECTOR_INTENT;
    dataProvider->dataProviderType = "FILE";
    dataProvider->active = true;

    //DataSeries information
    terrama2::core::DataSeries* dataSeries = new terrama2::core::DataSeries();
    terrama2::core::DataSeriesPtr dataSeriesPtr(dataSeries);
    auto& semanticsManager = terrama2::core::SemanticsManager::getInstance();
    dataSeries->semantics = semanticsManager.getSemantics("DCP-inpe");


    terrama2::core::DataSetDcp* dataSet = new terrama2::core::DataSetDcp();
    dataSet->active = true;
    dataSet->format.emplace("mask", "30885.txt");
    dataSet->format.emplace("timezone", "+00");

    dataSeries->datasetList.emplace_back(dataSet);

    //empty filter
    terrama2::core::Filter filter;
    filter.lastValue = true;

    //accessing data
    terrama2::core::DataAccessorDcpInpe accessor(dataProviderPtr, dataSeriesPtr);
    auto remover = std::make_shared<terrama2::core::FileRemover>();
    terrama2::core::DcpSeriesPtr dcpSeries = accessor.getDcpSeries(filter, remover);

    assert(dcpSeries->dcpSeriesMap().size() == 1);
    auto series = dcpSeries->getSeries().begin()->second;
    auto teDataSet = series.syncDataSet->dataset();

    std::cout << "dataset size: " << teDataSet->size() << std::endl;
  }

  

  return 0;
}
コード例 #5
0
int main(int argc, char* argv[])
{
  terrama2::core::TerraMA2Init terramaRaii("example", 0);

  {
    //DataProvider information
    terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider();
    terrama2::core::DataProviderPtr dataProviderPtr(dataProvider);
    dataProvider->uri = "file://";
    dataProvider->uri += TERRAMA2_DATA_DIR;
    dataProvider->uri += "/fire_system";

    dataProvider->intent = terrama2::core::DataProviderIntent::COLLECTOR_INTENT;
    dataProvider->dataProviderType = "FILE";
    dataProvider->active = true;

    //DataSeries information
    terrama2::core::DataSeries* dataSeries = new terrama2::core::DataSeries();
    terrama2::core::DataSeriesPtr dataSeriesPtr(dataSeries);
    auto& semanticsManager = terrama2::core::SemanticsManager::getInstance();
    dataSeries->semantics = semanticsManager.getSemantics("OCCURRENCE-wfp");

    terrama2::core::DataSetOccurrence* dataSet =new terrama2::core::DataSetOccurrence();
    dataSet->active = true;
    dataSet->format.emplace("mask", "exporta_%YYYY%MM%DD_%hh%mm.csv");
    dataSet->format.emplace("srid", "4326");
    dataSeries->datasetList.emplace_back(dataSet);

    //empty filter
    terrama2::core::Filter filter;
    //accessing data
    terrama2::core::DataAccessorOccurrenceWfp accessor(dataProviderPtr, dataSeriesPtr);
    auto remover = std::make_shared<terrama2::core::FileRemover>();
    terrama2::core::OccurrenceSeriesPtr occurrenceSeries = accessor.getOccurrenceSeries(filter, remover);

    std::cout << "Last data timestamp: " << accessor.lastDateTime()->toString() << std::endl;

    assert(occurrenceSeries->occurrencesMap().size() == 1);

    std::shared_ptr<te::da::DataSet> teDataSet = (*occurrenceSeries->occurrencesMap().begin()).second.syncDataSet->dataset();

    //Print column names and types (DateTime/Double)
    int dateColumn = -1;
    int geomColumn = -1;
    std::string names, types;
    for(int i = 0; i < teDataSet->getNumProperties(); ++i)
    {
      std::string name = teDataSet->getPropertyName(i);
      names+= name + "\t";
      if(name == "data_pas")
      {
        types+= "DataTime\t";
        dateColumn = i;
      }
      else if(name == "position")
      {
        types+= "Geometry\t";
        geomColumn = i;
      }
      else
        types+= "String\t";
    }

    std::cout << names << std::endl;
    std::cout << types << std::endl;

    //Print values
    teDataSet->moveBeforeFirst();
    while(teDataSet->moveNext())
    {
      for(int i = 0; i < teDataSet->getNumProperties(); ++i)
      {

        std::cout << teDataSet->getAsString(i) << "\t";
      }
      std::cout << std::endl;
    }

    std::cout << "\nDataSet size: " << teDataSet->size() << std::endl;
  }

  

  return 0;
}
コード例 #6
0
int main(int argc, char* argv[])
{
  try
  {
    terrama2::core::TerraMA2Init terramaRaii("example", 0);
    Q_UNUSED(terramaRaii);

    terrama2::core::registerFactories();
    {
      QCoreApplication app(argc, argv);

      auto& serviceManager = terrama2::core::ServiceManager::getInstance();

      auto dataManager = std::make_shared<terrama2::services::collector::core::DataManager>();

      auto loggerCopy = std::make_shared<terrama2::core::MockCollectorLogger>();

      EXPECT_CALL(*loggerCopy, setConnectionInfo(::testing::_)).WillRepeatedly(::testing::Return());
      EXPECT_CALL(*loggerCopy, setTableName(::testing::_)).WillRepeatedly(::testing::Return());
      EXPECT_CALL(*loggerCopy, getLastProcessTimestamp(::testing::_)).WillRepeatedly(::testing::Return(nullptr));
      EXPECT_CALL(*loggerCopy, getDataLastTimestamp(::testing::_)).WillRepeatedly(::testing::Return(nullptr));
      EXPECT_CALL(*loggerCopy, done(::testing::_, ::testing::_)).WillRepeatedly(::testing::Return());
      EXPECT_CALL(*loggerCopy, start(::testing::_)).WillRepeatedly(::testing::Return(0));
      EXPECT_CALL(*loggerCopy, isValid()).WillRepeatedly(::testing::Return(true));

      auto logger = std::make_shared<terrama2::core::MockCollectorLogger>();

      EXPECT_CALL(*logger, setConnectionInfo(::testing::_)).WillRepeatedly(::testing::Return());
      EXPECT_CALL(*logger, setTableName(::testing::_)).WillRepeatedly(::testing::Return());
      EXPECT_CALL(*logger, getLastProcessTimestamp(::testing::_)).WillRepeatedly(::testing::Return(nullptr));
      EXPECT_CALL(*logger, getDataLastTimestamp(::testing::_)).WillRepeatedly(::testing::Return(nullptr));
      EXPECT_CALL(*logger, done(::testing::_, ::testing::_)).WillRepeatedly(::testing::Return());
      EXPECT_CALL(*logger, start(::testing::_)).WillRepeatedly(::testing::Return(0));
      EXPECT_CALL(*logger, clone()).WillRepeatedly(::testing::Return(loggerCopy));
      EXPECT_CALL(*logger, isValid()).WillRepeatedly(::testing::Return(true));

      terrama2::services::collector::core::Service service(dataManager);
      serviceManager.setInstanceId(1);
      serviceManager.setLogger(logger);
      serviceManager.setLogConnectionInfo(te::core::URI(""));

      service.setLogger(logger);
      service.start();

      // DataProvider and DataSeries GradsFTP
      auto dataProviderFTP = terrama2::gradsftp::dataProviderGradsFTP();
      dataManager->add(dataProviderFTP);

      auto inputDataSeriesFTP = terrama2::gradsftp::dataSeriesGradsFTP(dataProviderFTP);
      dataManager->add(inputDataSeriesFTP);


      // DataProvider and DataSeries GradsFILE
      auto dataProviderFILE = terrama2::gradsftp::dataProviderGradsFILE();
      dataManager->add(dataProviderFILE);

      auto outputDataSeriesFILE = terrama2::gradsftp::dataSeriesGradsFILE(dataProviderFILE);
      dataManager->add(outputDataSeriesFILE);


      std::shared_ptr<terrama2::services::collector::core::Collector> collector = std::make_shared<terrama2::services::collector::core::Collector>();

      collector->id = 777;
      collector->projectId = 0;
      collector->serviceInstanceId = 1;
      collector->filter.region = terrama2::core::ewktToGeom("SRID=4326;POLYGON((-73.8036991603083 -9.81412714740936,-73.8036991603083 2.24662115728613,-56.097053202293 2.24662115728613,-56.097053202293 -9.81412714740936,-73.8036991603083 -9.81412714740936))");
      collector->filter.cropRaster = true;
      collector->filter.discardBefore = terrama2::core::TimeUtils::stringToTimestamp("2017-10-10T12:00:00.000-02:00", terrama2::core::TimeUtils::webgui_timefacet);
      collector->filter.discardAfter = terrama2::core::TimeUtils::stringToTimestamp("2017-10-10T13:00:00.000-02:00", terrama2::core::TimeUtils::webgui_timefacet);

      collector->inputDataSeries = inputDataSeriesFTP->id;
      collector->outputDataSeries = outputDataSeriesFILE->id;
      collector->inputOutputMap.emplace(inputDataSeriesFTP->id, outputDataSeriesFILE->id);

      dataManager->add(collector);

      service.addToQueue(collector, terrama2::core::TimeUtils::nowUTC());

      QTimer timer;
      QObject::connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit()));
      timer.start(10000);
      app.exec();

      service.stopService();
    }
  }
  catch(...)
  {
    std::cout << "\n\nException...\n" << std::endl;
  }

  return 0;
}
コード例 #7
0
ファイル: ListenToTcp.cpp プロジェクト: raphaelrpl/terrama2
int main(int argc, char* argv[])
{
  terrama2::core::TerraMA2Init terramaRaii("example", 0);
  QCoreApplication app(argc, argv);

  QJsonObject obj;
  QJsonArray providersArray;
  providersArray.push_back(terrama2::core::toJson(buildInputProvider()));
  obj.insert("DataProviders", providersArray);

  QJsonArray seriesArray;
  seriesArray.push_back(terrama2::core::toJson(buildInputDataSeries()));
  obj.insert("DataSeries", seriesArray);

  QJsonDocument doc(obj);

  std::shared_ptr<terrama2::core::DataManager> dataManager = std::make_shared<MockDataManager>();
  terrama2::core::TcpManager tcpManager(dataManager, std::weak_ptr<terrama2::core::ProcessLogger>());
  tcpManager.listen(QHostAddress::Any, 30000);

  QByteArray bytearray;
  QDataStream out(&bytearray, QIODevice::WriteOnly);


  QJsonObject logDb;
  logDb.insert("PG_HOST", QString::fromStdString(TERRAMA2_DATABASE_HOST));
  logDb.insert("PG_PORT", QString::fromStdString(TERRAMA2_DATABASE_PORT));
  logDb.insert("PG_USER", QString::fromStdString(TERRAMA2_DATABASE_USERNAME));
  logDb.insert("PG_PASSWORD", QString::fromStdString(TERRAMA2_DATABASE_PASSWORD));
  logDb.insert("PG_DB_NAME", QString::fromStdString(TERRAMA2_DATABASE_DBNAME));

  QJsonObject serviceConf;
  serviceConf.insert("instance_id", 1);
  serviceConf.insert("log_database", logDb);

  QJsonDocument serviceConfDoc(serviceConf);
  QByteArray serviceConfBytearray;
  QDataStream out2(&serviceConfBytearray, QIODevice::WriteOnly);
  auto jsonServiceConf = serviceConfDoc.toJson(QJsonDocument::Compact);
  out2 << static_cast<uint32_t>(0);
  out2 << static_cast<uint32_t>(terrama2::core::TcpSignal::UPDATE_SERVICE_SIGNAL);
  out2 << jsonServiceConf;
  serviceConfBytearray.remove(8, 4);//Remove QByteArray header
  out2.device()->seek(0);
  out2 << static_cast<uint32_t>(serviceConfBytearray.size() - sizeof(uint32_t));



  auto json = doc.toJson(QJsonDocument::Compact);
  out << static_cast<uint32_t>(0);
  out << static_cast<uint32_t>(terrama2::core::TcpSignal::ADD_DATA_SIGNAL);
  out << json;
  bytearray.remove(8, 4);//Remove QByteArray header
  out.device()->seek(0);
  out << static_cast<uint32_t>(bytearray.size() - sizeof(uint32_t));



  QTcpSocket socket;
  socket.connectToHost("localhost", 30000);
  socket.write(serviceConfBytearray);
  socket.waitForBytesWritten();
  socket.write(bytearray);

  QTimer timer;
  QObject::connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit()));
  timer.start(10000);
  app.exec();

  

  return 0;
}
コード例 #8
0
int main(int argc, char* argv[])
{
  try
  {
    terrama2::core::TerraMA2Init terramaRaii("example", 0);
    terrama2::core::registerFactories();

    {
      QCoreApplication app(argc, argv);
      auto& serviceManager = terrama2::core::ServiceManager::getInstance();
    te::core::URI uri("pgsql://"+TERRAMA2_DATABASE_USERNAME+":"+TERRAMA2_DATABASE_PASSWORD+"@"+TERRAMA2_DATABASE_HOST+":"+TERRAMA2_DATABASE_PORT+"/"+TERRAMA2_DATABASE_DBNAME);
      serviceManager.setLogConnectionInfo(uri);
      serviceManager.setInstanceId(1);

      auto dataManager = std::make_shared<terrama2::services::collector::core::DataManager>();

      addInput(dataManager);
      addOutput(dataManager);
      addGridSeries(dataManager);

      terrama2::services::collector::core::Service service(dataManager);
      auto logger = std::make_shared<terrama2::services::collector::core::CollectorLogger>();
      logger->setConnectionInfo(uri);
      service.setLogger(logger);
      service.start();

      terrama2::services::collector::core::Collector* collector(new terrama2::services::collector::core::Collector());
      terrama2::services::collector::core::CollectorPtr collectorPtr(collector);
      collector->id = 1;
      collector->projectId = 1;
      collector->serviceInstanceId = 1;

      collector->inputDataSeries = 1;
      collector->outputDataSeries = 2;
      collector->inputOutputMap.emplace(1, 2);

      terrama2::services::collector::core::Intersection* intersection(new terrama2::services::collector::core::Intersection());
      terrama2::services::collector::core::IntersectionPtr intersectionPtr(intersection);

      // Adds the attribute "SIGLA" to the collected occurrences.
      intersection->collectorId = collector->id;
      std::vector<std::string> attrVec{"2"};
      intersection->attributeMap[3] = attrVec;
      collector->intersection = intersectionPtr;

      dataManager->add(collectorPtr);
      service.addToQueue(collectorPtr->id, terrama2::core::TimeUtils::nowUTC());

      QTimer timer;
      QObject::connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit()));
      timer.start(10000);
      app.exec();

      service.stopService();
    }
  }
  catch(...)
  {
    std::cout << "\n\nException...\n" << std::endl;
  }

  return 0;
}
コード例 #9
0
int main(int, char**)
{
  terrama2::core::TerraMA2Init terramaRaii("example", 0);
  terrama2::core::registerFactories();

  //DataProvider information
  terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider();
  terrama2::core::DataProviderPtr dataProviderPtr(dataProvider);
  dataProvider->uri = "file://";
  dataProvider->uri+=TERRAMA2_DATA_DIR;

  dataProvider->intent = terrama2::core::DataProviderIntent::COLLECTOR_INTENT;
  dataProvider->dataProviderType = "FILE";
  dataProvider->active = true;

  //DataSeries information
  terrama2::core::DataSeries* dataSeries = new terrama2::core::DataSeries();
  terrama2::core::DataSeriesPtr dataSeriesPtr(dataSeries);
  auto& semanticsManager = terrama2::core::SemanticsManager::getInstance();
  dataSeries->semantics = semanticsManager.getSemantics("DCP-generic");


  terrama2::core::DataSetDcp* dataSet = new terrama2::core::DataSetDcp();
  dataSet->active = true;
  dataSet->format.emplace("folder", "/pcd_toa5/CPV/");
  dataSet->format.emplace("mask", "CPV_slow_%YYYY_%MM_%DD_%hh%mm.dat");
  dataSet->format.emplace("timezone", "+00");
  dataSet->format.emplace("srid", "4326");
  dataSet->format.emplace("header_size", "4");
  dataSet->format.emplace("properties_names_line", "2");
  dataSet->format.emplace("convert_all", "true");
  dataSet->format.emplace("default_type", "TEXT");

  QJsonArray fields;

  {
    QJsonObject obj;

    obj.insert("property_name", QString("TIMESTAMP"));
    obj.insert("alias", QString("datetime"));
    obj.insert("type", QString("DATETIME"));
    obj.insert("format", QString("%YYYY-%MM-%DD %hh:%mm:%ss"));

    fields.push_back(obj);
  }

  {
    QJsonObject obj;

    obj.insert("property_name", QString("RECORD"));
    obj.insert("alias", QString("record"));
    obj.insert("type", QString("INTEGER"));

    fields.push_back(obj);
  }

  {
    QJsonObject obj;

    obj.insert("property_name", QString("E_field_Avg"));
    obj.insert("alias", QString("efield"));
    obj.insert("type", QString("INTEGER"));

    fields.push_back(obj);
  }

  {
    QJsonObject obj;

    obj.insert("property_name", QString("panel_temp_Avg"));
    obj.insert("alias", QString("panel"));
    obj.insert("type", QString("INTEGER"));

    fields.push_back(obj);
  }

  {
    QJsonObject obj;

    obj.insert("property_name", QString("leakage_cur_Avg"));
    obj.insert("alias", QString("leak"));
    obj.insert("type", QString("FLOAT"));

    fields.push_back(obj);
  }

  {
    QJsonObject obj;

    obj.insert("property_name", QString("battery_volt_Avg"));
    obj.insert("alias", QString("bateria"));
    obj.insert("type", QString("FLOAT"));

    fields.push_back(obj);
  }

  {
    QJsonObject obj;

    obj.insert("property_name", QString("internal_RH_Avg"));
    obj.insert("alias", QString("interval"));
    obj.insert("type", QString("TEXT"));

    fields.push_back(obj);
  }

  QJsonObject obj;
  obj.insert("fields", fields);
  QJsonDocument doc(obj);

  dataSet->format.emplace("fields", QString(doc.toJson(QJsonDocument::Compact)).toStdString());

  dataSeries->datasetList.emplace_back(dataSet);

  //empty filter
  terrama2::core::Filter filter;

  //accessing data
  auto accessor = terrama2::core::DataAccessorFactory::getInstance().make(dataProviderPtr, dataSeriesPtr);
  auto remover = std::make_shared<terrama2::core::FileRemover>();
  auto uriMap = accessor->getFiles(filter, remover);

  auto dataMap = accessor->getSeries(uriMap, filter, remover);

  terrama2::core::DcpSeriesPtr dcpSeries = std::make_shared<terrama2::core::DcpSeries>();
  dcpSeries->addDcpSeries(dataMap);

  assert(dcpSeries->dcpSeriesMap().size() == 1);

  QUrl uri;
  uri.setScheme("postgis");
  uri.setHost("localhost");
  uri.setPort(5432);
  uri.setUserName("postgres");
  uri.setPassword("postgres");
  uri.setPath("/terrama2");

  //DataProvider information
  terrama2::core::DataProvider* dataProviderPostGIS = new terrama2::core::DataProvider();
  terrama2::core::DataProviderPtr dataProviderPostGISPtr(dataProviderPostGIS);
  dataProviderPostGIS->uri = uri.url().toStdString();

  dataProviderPostGIS->intent = terrama2::core::DataProviderIntent::PROCESS_INTENT;
  dataProviderPostGIS->dataProviderType = "POSTGIS";
  dataProviderPostGIS->active = true;

  //DataSeries information
  terrama2::core::DataSeries* outputDataSeries = new terrama2::core::DataSeries();
  terrama2::core::DataSeriesPtr outputDataSeriesPtr(outputDataSeries);
  outputDataSeries->semantics = semanticsManager.getSemantics("DCP-postgis");

  terrama2::core::DataSetDcp* dataSetOutput = new terrama2::core::DataSetDcp();
  terrama2::core::DataSetPtr dataSetOutputPtr(dataSetOutput);
  dataSetOutput->active = true;
  dataSetOutput->format.emplace("table_name", "dcp_generic");
  dataSetOutput->format.emplace("timestamp_column", "datetime");

  auto dataStorager = terrama2::core::DataStoragerFactory::getInstance().make(outputDataSeriesPtr, dataProviderPostGISPtr);

  for(auto& item : dataMap)
  {
    dataStorager->store( item.second, dataSetOutputPtr);
  }

  return 0;
}
コード例 #10
0
int main(int, char**)
{
  terrama2::core::TerraMA2Init terramaRaii("example", 0);
  terrama2::core::registerFactories();

  {
    //DataProvider information
    terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider();
    terrama2::core::DataProviderPtr dataProviderPtr(dataProvider);
    dataProvider->uri = "file://";
    dataProvider->uri += TERRAMA2_DATA_DIR;
    dataProvider->uri += "/grib";

    dataProvider->intent = terrama2::core::DataProviderIntent::COLLECTOR_INTENT;
    dataProvider->dataProviderType = "FILE";
    dataProvider->active = true;

    //DataSeries information
    terrama2::core::DataSeries* dataSeries = new terrama2::core::DataSeries();
    terrama2::core::DataSeriesPtr dataSeriesPtr(dataSeries);
    auto& semanticsManager = terrama2::core::SemanticsManager::getInstance();
    dataSeries->semantics = semanticsManager.getSemantics("GRID-grib");

    terrama2::core::DataSetGrid* dataSet = new terrama2::core::DataSetGrid();
    dataSet->active = true;
    dataSet->format.emplace("mask", "WRF_ams_09km_2016012900_2016012900.grb2");
    dataSet->format.emplace("timezone", "+00");
    dataSet->format.emplace("bands", "UGRD;VGRD");
    dataSet->format.emplace("iso_surface", "10000");

    dataSeries->datasetList.emplace_back(dataSet);

    //empty filter
    terrama2::core::Filter filter;
    //accessing data
    terrama2::core::DataAccessorGrib accessor(dataProviderPtr, dataSeriesPtr);
    auto remover = std::make_shared<terrama2::core::FileRemover>();
    terrama2::core::GridSeriesPtr gridSeries = accessor.getGridSeries(filter,remover);

    assert(gridSeries->gridMap().size() == 1);

    //DataProvider information
    terrama2::core::DataProvider* outputDataProvider = new terrama2::core::DataProvider();
    terrama2::core::DataProviderPtr outputDataProviderPtr(outputDataProvider);
    outputDataProvider->uri = "file://"+TERRAMA2_DATA_DIR+"/saida";

    terrama2::core::DataSeries* outputDataSeries = new terrama2::core::DataSeries();
    terrama2::core::DataSeriesPtr outputDataSeriesPtr(outputDataSeries);
    outputDataSeries->semantics = semanticsManager.getSemantics("GRID-gdal");

    terrama2::core::DataStoragerTiff dataStorager(outputDataSeriesPtr, outputDataProviderPtr);

    terrama2::core::DataSetGrid* outputDataSet = new terrama2::core::DataSetGrid();
    terrama2::core::DataSetGridPtr outputDataSetPtr(outputDataSet);
    outputDataSet->active = true;
    outputDataSet->format.emplace("mask", "ventos.tif");
    outputDataSeries->datasetList.push_back(outputDataSetPtr);

    auto seriesMap = gridSeries->getSeries();
    auto series = seriesMap.begin()->second;
    dataStorager.store(series, outputDataSetPtr);
  }



  return 0;
}
コード例 #11
0
ファイル: main.cpp プロジェクト: raphaelrpl/terrama2
int main(int argc, char* argv[])
{
  try
  {
    std::string appName = boost::filesystem::basename(argv[0]);

    po::options_description desc("Allowed options");
    desc.add_options()
        ("help,h", "show help message.")
        ("version,v", "Show TerraMA2 version.")
        ("service,s", po::value<std::string>()->required(), "Service to be started.\nValid options:\n\t- ANALYSIS\n\t- COLLECTOR\n\t- VIEW")
        ("port,p", po::value<int>()->required(), "Port the service will listen.")
    ;
    po::positional_options_description positionalOptions;
        positionalOptions.add("service", 1);
        positionalOptions.add("port", 1);

    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).options(desc)
                      .positional(positionalOptions).run(),
                    vm);

    if (vm.count("help")) {
        std::cout << "usage: "+appName+" [--version] [--help] service port" << "\n";
        std::cout << desc << std::endl;
        return 0;
    }

    if (vm.count("version")) {
        std::cout << "TerraMA2 " << TERRAMA2_VERSION_STRING << std::endl;
        return 0;
    }

    po::notify(vm);

    std::string serviceType(vm["service"].as<std::string>());
    std::transform(serviceType.begin(), serviceType.end(), serviceType.begin(), ::tolower);

    if(!checkServiceType(serviceType))
      return UNKNOWN_SERVICE_TYPE;

    int listeningPort = vm["port"].as<int>();

    terrama2::core::TerraMA2Init terramaRaii(serviceType, listeningPort);
    terrama2::core::registerFactories();


    auto& serviceManager = terrama2::core::ServiceManager::getInstance();
    serviceManager.setServiceType(serviceType);
    serviceManager.setListeningPort(listeningPort);

    // service context
    // this is needed for calling the destructor of the service before finalizing terralib
    {
      TERRAMA2_LOG_INFO() << QObject::tr("Initializing TerraMA2 service...");
      TERRAMA2_LOG_INFO() << QObject::tr("Starting %1 service.").arg(QString::fromStdString(serviceType));

      // Must initialize the python interpreter before creating any thread.
      terrama2::services::analysis::core::PythonInterpreterInit pythonInterpreterInit;

      QCoreApplication app(argc, argv);

      // Changes in the initialization order may cause locale problems
      std::locale::global(std::locale::classic());

      std::shared_ptr<terrama2::core::DataManager> dataManager;
      std::shared_ptr<terrama2::core::Service> service;
      std::shared_ptr<terrama2::core::ProcessLogger> logger;
      std::tie(dataManager, service, logger) = createService(serviceType);
      if(!service.get()
          || !dataManager.get()
          || !logger.get())
        return SERVICE_LOAD_ERROR;

      auto tcpManager = std::make_shared<terrama2::core::TcpManager>(dataManager, logger);
      if(!tcpManager->listen(QHostAddress::Any, serviceManager.listeningPort()))
      {
        std::cerr << QObject::tr("\nUnable to listen to port: ").toStdString() << serviceManager.listeningPort() << "\n" << std::endl;

        exit(TCP_SERVER_ERROR);
      }

      QObject::connect(&serviceManager, &terrama2::core::ServiceManager::listeningPortUpdated, tcpManager.get(), &terrama2::core::TcpManager::updateListeningPort);

      QObject::connect(tcpManager.get(), &terrama2::core::TcpManager::startProcess, service.get(), &terrama2::core::Service::addToQueue);
      QObject::connect(&serviceManager, &terrama2::core::ServiceManager::numberOfThreadsUpdated, service.get(), &terrama2::core::Service::updateNumberOfThreads);

      QObject::connect(&serviceManager, &terrama2::core::ServiceManager::logConnectionInfoUpdated, logger.get(), &terrama2::core::ProcessLogger::setConnectionInfo);

      QObject::connect(service.get(), &terrama2::core::Service::processFinishedSignal, tcpManager.get(), &terrama2::core::TcpManager::processFinishedSlot);
      QObject::connect(tcpManager.get(), &terrama2::core::TcpManager::stopSignal, service.get(), &terrama2::core::Service::stopService);
      QObject::connect(service.get(), &terrama2::core::Service::serviceFinishedSignal, &app, &QCoreApplication::quit);

      app.exec();
    }

    try
    {
      //Service closed by load error
      if(!serviceManager.serviceLoaded())
        return SERVICE_LOAD_ERROR;
    }
    catch(...)
    {
      return TERRAMA2_FINALIZATION_ERROR;
    }
  }
  catch(boost::program_options::error& e)
  {
    std::cout << "Invalid options.See 'terrama2_service --help'\n" << std::endl;
    TERRAMA2_LOG_ERROR() << e.what();
  }
  catch(boost::exception& e)
  {
    TERRAMA2_LOG_ERROR() << boost::diagnostic_information(e);
  }
  catch(std::exception& e)
  {
    TERRAMA2_LOG_ERROR() << e.what();
  }
  catch(...)
  {
    TERRAMA2_LOG_ERROR() << QObject::tr("\n\nUnknown Exception...\n");
  }

  return 0;
}
コード例 #12
0
int main(int argc, char* argv[])
{
    terrama2::core::TerraMA2Init terramaRaii("example", 0);

    {
        QUrl uri;
        uri.setScheme("postgis");
        uri.setHost(QString::fromStdString(TERRAMA2_DATABASE_HOST));
        uri.setPort(std::stoi(TERRAMA2_DATABASE_PORT));
        uri.setUserName(QString::fromStdString(TERRAMA2_DATABASE_USERNAME));
        uri.setPassword(QString::fromStdString(TERRAMA2_DATABASE_PASSWORD));
        uri.setPath(QString::fromStdString("/"+TERRAMA2_DATABASE_DBNAME));

        //DataProvider information
        terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider();
        terrama2::core::DataProviderPtr dataProviderPtr(dataProvider);
        dataProvider->uri = uri.url().toStdString();
        dataProvider->intent = terrama2::core::DataProviderIntent::COLLECTOR_INTENT;
        dataProvider->dataProviderType = "POSTGIS";
        dataProvider->active = true;

        auto& semanticsManager = terrama2::core::SemanticsManager::getInstance();

        //DataSeries information
        terrama2::core::DataSeries* dataSeries = new terrama2::core::DataSeries();
        terrama2::core::DataSeriesPtr dataSeriesPtr(dataSeries);
        dataSeries->semantics = semanticsManager.getSemantics("OCCURRENCE-postgis");

        //DataSet information
        terrama2::core::DataSetOccurrence* dataSet = new terrama2::core::DataSetOccurrence();
        dataSet->active = true;
        dataSet->format.emplace("table_name", "fires");
        dataSet->format.emplace("timestamp_property", "data_pas");
        dataSet->format.emplace("geometry_property", "geom");

        dataSeries->datasetList.emplace_back(dataSet);

        //accessing data
        terrama2::core::DataAccessorOccurrencePostGIS accessor(dataProviderPtr, dataSeriesPtr);
        //empty filter
        terrama2::core::Filter filter;
        boost::local_time::time_zone_ptr zone(new boost::local_time::posix_time_zone("+00"));

        std::string dateTime = "2015-08-26 16:38:50";
        boost::posix_time::ptime boostDate(boost::posix_time::time_from_string(dateTime));
        boost::local_time::local_date_time date(boostDate.date(), boostDate.time_of_day(), zone, true);
        filter.discardBefore = std::make_shared<te::dt::TimeInstantTZ>(date);

        std::string dateTimeAfter = "2015-08-26 16:38:55";
        boost::posix_time::ptime boostDateAfter(boost::posix_time::time_from_string(dateTimeAfter));
        boost::local_time::local_date_time dateAfter(boostDateAfter.date(), boostDateAfter.time_of_day(), zone, true);
        filter.discardAfter = std::make_shared<te::dt::TimeInstantTZ>(dateAfter);

        std::string boundingBoxWkt = "POLYGON((-51.11 -17.74, -41.11 -17.74, -41.11 -20.83, -51.11 -20.83, -51.11 -17.74))";
        te::gm::Geometry* geometry = te::gm::WKTReader::read(boundingBoxWkt.c_str());
        geometry->setSRID(4326);

        filter.region = std::shared_ptr<te::gm::Geometry>(geometry);

        auto remover = std::make_shared<terrama2::core::FileRemover>();
        terrama2::core::OccurrenceSeriesPtr occurrenceSeries = accessor.getOccurrenceSeries(filter, remover);

        assert(occurrenceSeries->occurrencesMap().size() == 1);

        auto teDataSet = (*occurrenceSeries->occurrencesMap().begin()).second.syncDataSet->dataset();


        //Print column names and types (DateTime/Double)
        int dateColumn = -1;
        int geomColumn = -1;
        std::string names, types;
        for(int i = 0; i < teDataSet->getNumProperties(); ++i)
        {
            std::string name = teDataSet->getPropertyName(i);
            names+= name + "\t";
            if(name == "data_pas")
            {
                types+= "DataTime\t";
                dateColumn = i;
            }
            else if(name == "geom")
            {
                types+= "Geometry\t";
                geomColumn = i;
            }
            else
                types+= "Int\t";
        }

        std::cout << names << std::endl;
        std::cout << types << std::endl;

        //Print values
        teDataSet->moveBeforeFirst();
        while(teDataSet->moveNext())
        {
            for(int i = 0; i < teDataSet->getNumProperties(); ++i)
            {
                if(teDataSet->isNull(i))
                {
                    std::cout << "NULL";
                    continue;
                }

                if(i == dateColumn)
                {
                    std::shared_ptr<te::dt::DateTime> dateTime =  teDataSet->getDateTime(i);
                    std::cout << dateTime->toString();
                }
                else if(i == geomColumn)
                {
                    std::cout << "<<Geometry>>";
                }
                else
                {
                    std::cout << teDataSet->getInt32(i);
                }

                std::cout << "\t";
            }
            std::cout << std::endl;
        }

        std::cout << "\ndataset size: " << teDataSet->size() << std::endl;
    }



    return 0;
}