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 } }
bool isValidSudoku(vector<vector<char>>& board) { for(int i = 0; i < 9; i++){ if( !isValidRow(board, i) ) return false; } for(int i = 0; i < 9; i++){ if( !isValidColumn(board, i) ) return false; } for(int i = 0; i < 9; i += 3){ for(int j = 0; j < 9; j += 3){ if( !isValidSubMatrix(board, i, j) ) return false; } } return true; }
void terrama2::core::DataAccessorOccurrenceLightning::adapt(DataSetPtr dataSet, std::shared_ptr<te::da::DataSetTypeConverter> converter) const { // only one timestamp column size_t lonPos = std::numeric_limits<size_t>::max(); size_t latPos = std::numeric_limits<size_t>::max(); Srid srid = getSrid(dataSet); auto timestampPropertyName = terrama2::core::simplifyString(getTimestampPropertyName(dataSet)); te::dt::DateTimeProperty* timestampProperty = new te::dt::DateTimeProperty(timestampPropertyName, te::dt::TIME_INSTANT); te::dt::SimpleProperty* latProperty = new te::dt::SimpleProperty(getLatitudePropertyName(dataSet), te::dt::DOUBLE_TYPE); te::dt::SimpleProperty* lonProperty = new te::dt::SimpleProperty(getLongitudePropertyName(dataSet), te::dt::DOUBLE_TYPE); te::gm::GeometryProperty* geomProperty = new te::gm::GeometryProperty("geom", srid, te::gm::PointType); // Find the right column to adapt std::vector<te::dt::Property*> properties = converter->getConvertee()->getProperties(); for(size_t i = 0, size = properties.size(); i < size; ++i) { te::dt::Property* property = properties.at(i); if(property->getName() == getTimestampPropertyName(dataSet)) { // datetime column found converter->add(i, timestampProperty, boost::bind(&terrama2::core::DataAccessorOccurrenceLightning::stringToTimestamp, this, _1, _2, _3, getTimeZone(dataSet))); } else if(property->getName() == getLatitudePropertyName(dataSet) || property->getName() == getLongitudePropertyName(dataSet)) { // update latitude column index if(property->getName() == getLatitudePropertyName(dataSet)) { latPos = i; converter->add(i, latProperty, boost::bind(&terrama2::core::DataAccessor::stringToDouble, this, _1, _2, _3)); } // update longitude column index if(property->getName() == getLongitudePropertyName(dataSet)) { lonPos = i; converter->add(i, lonProperty, boost::bind(&terrama2::core::DataAccessor::stringToDouble, this, _1, _2, _3)); } if(!isValidColumn(latPos) || !isValidColumn(lonPos)) continue; std::vector<size_t> latLonAttributes; latLonAttributes.push_back(lonPos); latLonAttributes.push_back(latPos); converter->add(latLonAttributes, geomProperty, boost::bind(&terrama2::core::DataAccessorOccurrenceLightning::stringToPoint, this, _1, _2, _3, srid)); } else { auto newName = terrama2::core::simplifyString(converter->getConvertee()->getProperty(i)->getName()); te::dt::SimpleProperty* property = new te::dt::SimpleProperty(newName, te::dt::DOUBLE_TYPE); converter->add(i, property, boost::bind(&terrama2::core::DataAccessor::stringToDouble, this, _1, _2, _3)); } } }
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); } }