Beispiel #1
0
		Json::Value LineString::toJson()
		{
			Json::Value output;
			output["type"] = "LineString";

			for (auto pt : coordinates)
			{
				Json::Value ptCoords;
				ptCoords.append(pt.longitude); // LONGITUDE FIRST, then Latitude
				ptCoords.append(pt.latitude);
				output["coordinates"].append(ptCoords);
			}

			if (!getSrid().empty())
			{
				output["crs"]["properties"]["name"] = getSrid();
			}
			return output;
		}
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));
    }
  }
}
Beispiel #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);
  }
}