TsRasterVectorizer.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/unittest/raster/TsRasterVectorizer.cpp
22 
23  \brief A test suit for the Raster Vectorizer class.
24  */
25 
26 // TerraLib
27 #include <terralib_buildconfig.h>
28 
29 #include <terralib/geometry.h>
30 #include <terralib/raster.h>
31 #include <terralib/dataaccess.h>
32 #include <terralib/memory.h>
33 #include "../Config.h"
34 
35 // STL
36 #include <memory>
37 #include <cstdio>
38 
39 // Boost
40 #include <boost/test/unit_test.hpp>
41 #include <boost/shared_ptr.hpp>
42 
43 BOOST_AUTO_TEST_SUITE ( rasterVectorizer_tests )
44 
45 BOOST_AUTO_TEST_CASE (rasterVectorizer_test)
46 {
47  /* Define raster info and load */
48 
49  std::map<std::string, std::string> rinfo;
50  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/pattern1.tif";
51  std::unique_ptr< te::rst::Raster > inrasterPtr( te::rst::RasterFactory::open(rinfo) );
52 
53  std::vector<te::gm::Geometry*> polygons;
54  std::vector< double > polygonsValues;
55 
56  te::rst::Vectorizer vectorizerInstance( inrasterPtr.get(), 0, 0, false );
57  vectorizerInstance.run( polygons, &polygonsValues);
58  BOOST_CHECK( !polygons.empty() );
59  BOOST_CHECK( polygons.size() == polygonsValues.size() );
60 
61  /* Checking geometries */
62 
63  {
64  for( unsigned int polygonsIdx = 0 ; polygonsIdx < polygons.size() ; ++polygonsIdx )
65  {
66  BOOST_CHECK( polygons[ polygonsIdx ]->isValid() );
67  }
68  }
69 
70  /* Exporting to disk */
71 
72  {
73  std::unique_ptr<te::da::DataSetType> dataSetTypePtr1(new te::da::DataSetType("RasterVectorizerTestPolygons"));
74 
75  dataSetTypePtr1->add( new te::dt::SimpleProperty("value", te::dt::DOUBLE_TYPE, true) );
76  dataSetTypePtr1->add( new te::dt::SimpleProperty("id", te::dt::DOUBLE_TYPE, true) );
77  dataSetTypePtr1->add( new te::gm::GeometryProperty("polygon", inrasterPtr->getSRID(),
78  te::gm::PolygonType, true) );
79 
80  std::unique_ptr<te::da::DataSetType> dataSetTypePtr2( new te::da::DataSetType( *dataSetTypePtr1 ) );
81 
82  std::unique_ptr< te::mem::DataSet > memDataSetPtr( new te::mem::DataSet( dataSetTypePtr1.get()) );
83 
84  for( unsigned int polygonsIdx = 0 ; polygonsIdx < polygons.size() ; ++polygonsIdx )
85  {
86  te::mem::DataSetItem* dsItemPtr = new te::mem::DataSetItem(memDataSetPtr.get());
87  dsItemPtr->setDouble( 0, polygonsValues[ polygonsIdx ] );
88  dsItemPtr->setDouble( 1, polygonsIdx );
89  dsItemPtr->setGeometry( 2, polygons[ polygonsIdx ] );
90 
91  memDataSetPtr->add( dsItemPtr );
92  }
93 
94  remove( "RasterVectorizerTestPolygons.dbf" );
95  remove( "RasterVectorizerTestPolygons.prj" );
96  remove( "RasterVectorizerTestPolygons.shp" );
97  remove( "RasterVectorizerTestPolygons.shx" );
98 
99  std::string connInfo("file://RasterVectorizerTestPolygons.shp");
100  std::unique_ptr<te::da::DataSource> dsOGR( te::da::DataSourceFactory::make("OGR", connInfo) );
101  dsOGR->open();
102 
103  memDataSetPtr->moveBeforeFirst();
104 
105  te::da::Create(dsOGR.get(), dataSetTypePtr2.get(), memDataSetPtr.get());
106 
107  dsOGR->close();
108  }
109 }
110 
111 BOOST_AUTO_TEST_SUITE_END()
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
Geometric property.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
This file contains include headers for the memory data source of TerraLib.
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
An atomic property like an integer or double.
BOOST_AUTO_TEST_SUITE(rasterVectorizer_tests) BOOST_AUTO_TEST_CASE(rasterVectorizer_test)
A class that models the description of a dataset.
Definition: DataSetType.h:72
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
TEDATAACCESSEXPORT void Create(DataSource *ds, DataSetType *dt, DataSet *d, std::size_t limit=0)
It creates the dataset definition in a data source and then fill it with data from the input dataset...
It implements the vectorizer, based on TerraLib 4 algorithm.
Definition: Vectorizer.h:64
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
BOOST_AUTO_TEST_CASE(encoding_test_utf8_latin1)
bool run(std::vector< te::gm::Geometry * > &polygons, std::vector< double > *const polygonsValues=0)
Returns true if current algorithm implementation runs ok, false otherwise.
Definition: Vectorizer.cpp:117
This file contains include headers for the Vector Geometry model of TerraLib.
This file contains include headers for the Data Access module of TerraLib.
static Raster * open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
It opens a raster with the given parameters and default raster driver.