CoverageSeriesExamples.cpp
Go to the documentation of this file.
1 // Examples
2 #include "STExamples.h"
3 
4 //TerraLib
5 #include <terralib/common.h>
6 #include <terralib/dataaccess.h>
7 #include <terralib/geometry.h>
8 #include <terralib/datatype.h>
9 #include <terralib/st.h>
10 
11 // STL
12 #include <iostream>
13 
15 {
16  try
17  {
18  //Load coverage series from a set of geotif files
19  std::unique_ptr<te::st::CoverageSeries> cvs = LoadCoverageSeriesFromGeotif();
20 
21  //Print coverage series info
22  PrintCoverageSeriesInfo(cvs.get());
23 
24  //Extract time series from coverage series
25  //Load the centroide of the Angra city -> from a shapefile with the Angra city
26  const std::string connInfo("file://" TERRALIB_DATA_DIR "/st/coverage/angra_city.shp");
27  std::unique_ptr<te::da::DataSource> ds(te::da::DataSourceFactory::make("OGR", connInfo));
28  ds->open();
29 
30  std::unique_ptr<te::da::DataSet> dSet = ds->getDataSet("angra_city");
31  std::unique_ptr<te::gm::Geometry> geom;
32 
33  if(dSet->moveNext())
34  {
35  std::size_t geomPos = te::da::GetFirstPropertyPos(dSet.get(), te::dt::GEOMETRY_TYPE);
36  geom = dSet->getGeometry(geomPos);
37 
38  //Centroid operation is not implemented!
39  //We will use the center point of the MBR of the Angra geometry
40  const te::gm::Envelope* env = geom->getMBR();
41  te::gm::Coord2D coord = env->getCenter();
42  te::gm::Point point(coord.x, coord.y);
43 
44  std::unique_ptr<te::st::TimeSeries> result = cvs->getTimeSeries(point);
45 
46  //Print the result time series
47  PrintTimeSeries(result.get());
48  }
49  }
50  catch(const std::exception& e)
51  {
52  std::cout << std::endl << "An exception has occurred in CoverageExamples: " << e.what() << std::endl;
53  }
54  catch(...)
55  {
56  std::cout << std::endl << "An unexpected exception has occurred in CoverageExamples!" << std::endl;
57  }
58 }
59 
This file contains include headers for the Data Type module of TerraLib.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
double y
y-coordinate.
Definition: Coord2D.h:114
double x
x-coordinate.
Definition: Coord2D.h:113
void PrintTimeSeries(boost::ptr_vector< te::st::TimeSeries > &input)
It prints all observations of the time series (PrintTimeSeries.cpp)
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
static te::dt::Date ds(2010, 01, 01)
Examples on how to load/manipulate st types.
Coord2D getCenter() const
It returns the rectangle&#39;s center coordinate.
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
void PrintCoverageSeriesInfo(te::st::CoverageSeries *output)
It prints information about a coverage series (PrintCoverageSeries.cpp)
void CoverageSeriesExamples()
It contains examples about coverage.
This file contains include headers for the TerraLib Common Runtime module.
This file contains include headers for the TerraLib ST module.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
This file contains include headers for the Vector Geometry model of TerraLib.
This file contains include headers for the Data Access module of TerraLib.
std::unique_ptr< te::st::CoverageSeries > LoadCoverageSeriesFromGeotif()
It loads a coverage series from a set of geotif files.