Esempio n. 1
0
void terrama2::core::DataStoragerTiff::store(DataSetSeries series, DataSetPtr outputDataSet) const
{
  if(!outputDataSet.get() || !series.syncDataSet.get())
  {
    QString errMsg = QObject::tr("Mandatory parameters not provided.");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw DataStoragerException() << ErrorDescription(errMsg);
  }

  QUrl uri(QString::fromStdString(dataProvider_->uri));
  auto path = uri.path().toStdString();
  try
  {
    std::string mask = getMask(outputDataSet);

    auto dataset = series.syncDataSet->dataset();
    size_t rasterColumn = te::da::GetFirstPropertyPos(dataset.get(), te::dt::RASTER_TYPE);
    if(!isValidColumn(rasterColumn))
    {
      QString errMsg = QObject::tr("No raster attribute.");
      TERRAMA2_LOG_ERROR() << errMsg;
      throw DataStoragerException() << ErrorDescription(errMsg);
    }

    size_t timestampColumn = te::da::GetFirstPropertyPos(dataset.get(), te::dt::DATETIME_TYPE);

    dataset->moveBeforeFirst();
    while(dataset->moveNext())
    {
      std::shared_ptr<te::rst::Raster> raster(dataset->isNull(rasterColumn) ? nullptr : dataset->getRaster(rasterColumn).release());
      std::shared_ptr<te::dt::DateTime> timestamp;
      if(!isValidColumn(timestampColumn) || dataset->isNull(timestampColumn))
        timestamp = nullptr;
      else
        timestamp.reset(dataset->getDateTime(timestampColumn).release());

      if(!raster.get())
      {
        QString errMsg = QObject::tr("Null raster found.");
        TERRAMA2_LOG_ERROR() << errMsg;
        continue;
      }

      std::string filename = replaceMask(mask, timestamp, outputDataSet);

      std::string output = path + "/" + filename;
      te::rp::Copy2DiskRaster(*raster, output);
    }
  }
  catch(const DataStoragerException&)
  {
    throw;
  }
  catch(...)
  {
    //TODO: fix DataStoragerTiff catch
  }
}
Esempio n. 2
0
terrama2::core::DataStorager::DataStorager(DataSeriesPtr outputDataSeries, DataProviderPtr outputDataProvider)
        : dataSeries_(outputDataSeries),
          dataProvider_(outputDataProvider)
{
  if(!dataProvider_.get())
  {
    QString errMsg = QObject::tr("Mandatory parameters not provided.");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw DataStoragerException() << ErrorDescription(errMsg);
  }
}
Esempio n. 3
0
void terrama2::core::DataAccessorGDAL::addToCompleteDataSet(terrama2::core::DataSetPtr dataSet,
                                                               std::shared_ptr<te::mem::DataSet> completeDataSet,
                                                               std::shared_ptr<te::da::DataSet> teDataSet,
                                                               std::shared_ptr< te::dt::TimeInstantTZ > fileTimestamp,
                                                               const std::string& filename) const
{
  completeDataSet->moveLast();

  size_t rasterColumn = te::da::GetFirstPropertyPos(teDataSet.get(), te::dt::RASTER_TYPE);
  if(!isValidColumn(rasterColumn))
  {
    QString errMsg = QObject::tr("No raster attribute.");
    TERRAMA2_LOG_ERROR() << errMsg;
    throw DataStoragerException() << ErrorDescription(errMsg);
  }

  size_t timestampColumn = te::da::GetFirstPropertyPos(completeDataSet.get(), te::dt::DATETIME_TYPE);

  int outputSrid = -1;
  try
  {
    outputSrid = getSrid(dataSet, false);
    verify::srid(outputSrid);
  }
  catch (const UndefinedTagException&)
  {
    //SRID is an optional parameter
  }

  teDataSet->moveBeforeFirst();
  while(teDataSet->moveNext())
  {
    std::unique_ptr<te::rst::Raster> raster(teDataSet->isNull(rasterColumn) ? nullptr : teDataSet->getRaster(rasterColumn).release());

    if(outputSrid > 0 && outputSrid != raster->getSRID())
    {
      try
      {
        verify::srid(raster->getSRID(), false);
        std::map<std::string, std::string> map{{"RTYPE", "EXPANSIBLE"}};
        auto temp = raster->transform(outputSrid, map);
        if(!temp)
        {
          QString errMsg = QObject::tr("Null raster found.\nError during transform.");
          TERRAMA2_LOG_ERROR() << errMsg;
          continue;
        }
        else
          raster.reset(temp);
      }
      catch (...)
      {
        auto grid = raster->getGrid();
        grid->setSRID(outputSrid);
      }
    }

    te::mem::DataSetItem* item = new te::mem::DataSetItem(completeDataSet.get());

    item->setRaster(rasterColumn, raster.release());
    if(isValidColumn(timestampColumn ))
      item->setDateTime(timestampColumn, fileTimestamp.get() ? static_cast<te::dt::DateTime*>(fileTimestamp->clone()) : nullptr);

    item->setString("filename", filename);
    completeDataSet->add(item);
  }
}