27 #include <terralib_buildconfig.h> 34 #include "../Config.h" 37 #include <boost/test/unit_test.hpp> 38 #include <boost/shared_ptr.hpp> 42 bool loadSHPFile( const
std::
string& shpFileName,
43 std::vector<
te::gm::Geometry* >& geomPtrs )
45 std::string connInfo(
"file://");
46 connInfo += shpFileName;
47 std::unique_ptr< te::da::DataSource > ogrDataSourcePtr(
49 BOOST_CHECK( ogrDataSourcePtr.get() != 0 );
51 ogrDataSourcePtr->open();
53 BOOST_CHECK( ogrDataSourcePtr->isOpened() );
55 std::vector<std::string> dataSetNames = ogrDataSourcePtr->getDataSetNames();
56 std::unique_ptr< te::da::DataSourceTransactor > transactorPtr =
57 ogrDataSourcePtr->getTransactor();
59 for(
unsigned int dataSetNamesIdx = 0 ; dataSetNamesIdx < dataSetNames.size() ;
62 std::unique_ptr<te::da::DataSet> datasetPtr = transactorPtr->getDataSet(
63 dataSetNames[ dataSetNamesIdx ] );
65 const std::size_t nProperties = datasetPtr->getNumProperties();
67 BOOST_CHECK( datasetPtr->moveBeforeFirst() );
69 while( datasetPtr->moveNext() )
71 for( std::size_t propIdx = 0 ; propIdx < nProperties ; ++propIdx )
75 std::unique_ptr< te::gm::Geometry > geomPtr = datasetPtr->getGeometry(
80 geomPtrs.push_back( geomPtr.release() );
116 std::map<std::string, std::string> dsinfo;
117 dsinfo[
"URI"] =
"raster_metadata_persistence_test.tif";
122 std::vector<te::rst::BandProperty*> vecBandProp;
124 vecBandProp[ 0 ]->m_blkh = 100;
125 vecBandProp[ 0 ]->m_blkw = 100;
126 vecBandProp[ 0 ]->m_nblocksx = 1;
127 vecBandProp[ 0 ]->m_nblocksy = 1;
128 vecBandProp[ 0 ]->m_noDataValue = 0;
130 vecBandProp[ 0 ]->m_categoryNames.push_back(
"category_0" );
131 vecBandProp[ 0 ]->m_categoryNames.push_back(
"category_1" );
132 vecBandProp[ 0 ]->m_description =
"description0";
133 vecBandProp[ 0 ]->m_metadata.push_back(
134 std::pair<std::string, std::string>(
"meta0name",
"meta0value" ) );
135 vecBandProp[ 0 ]->m_metadata.push_back(
136 std::pair<std::string, std::string>(
"meta1name",
"meta1value" ) );
142 grid, vecBandProp, dsinfo));
144 BOOST_REQUIRE( rst.get() );
145 BOOST_CHECK( rst->getBand( 0 )->getProperty()->m_description
147 BOOST_REQUIRE( rst->getBand( 0 )->getProperty()->m_metadata.size()
149 BOOST_CHECK( rst->getBand( 0 )->getProperty()->m_metadata[ 0 ].first
151 BOOST_CHECK( rst->getBand( 0 )->getProperty()->m_metadata[ 0 ].second
153 BOOST_CHECK( rst->getBand( 0 )->getProperty()->m_metadata[ 1 ].first
155 BOOST_CHECK( rst->getBand( 0 )->getProperty()->m_metadata[ 1 ].second
157 BOOST_REQUIRE( rst->getBand( 0 )->getProperty()->m_categoryNames.size()
159 BOOST_CHECK( rst->getBand( 0 )->getProperty()->m_categoryNames[ 0 ]
161 BOOST_CHECK( rst->getBand( 0 )->getProperty()->m_categoryNames[ 1 ]
168 boost::shared_ptr< te::rst::Raster > inputRasterPtr (
171 BOOST_REQUIRE( inputRasterPtr.get() );
172 BOOST_CHECK( inputRasterPtr->getBand( 0 )->getProperty()->m_description
174 BOOST_REQUIRE( inputRasterPtr->getBand( 0 )->getProperty()->m_metadata.size()
176 BOOST_CHECK( inputRasterPtr->getBand( 0 )->getProperty()->m_metadata[ 0 ].first
178 BOOST_CHECK( inputRasterPtr->getBand( 0 )->getProperty()->m_metadata[ 0 ].second
180 BOOST_CHECK( inputRasterPtr->getBand( 0 )->getProperty()->m_metadata[ 1 ].first
182 BOOST_CHECK( inputRasterPtr->getBand( 0 )->getProperty()->m_metadata[ 1 ].second
184 BOOST_REQUIRE( inputRasterPtr->getBand( 0 )->getProperty()->m_categoryNames.size()
186 BOOST_CHECK( inputRasterPtr->getBand( 0 )->getProperty()->m_categoryNames[ 0 ]
188 BOOST_CHECK( inputRasterPtr->getBand( 0 )->getProperty()->m_categoryNames[ 1 ]
195 std::vector< te::gm::Geometry* > geomPtrs;
196 BOOST_CHECK( loadSHPFile( TERRALIB_DATA_DIR
"/shape/poligono_unico.shp",
199 std::vector<te::rst::BandProperty*> vecBandProp;
201 vecBandProp[ 0 ]->m_blkh = 100;
202 vecBandProp[ 0 ]->m_blkw = 100;
203 vecBandProp[ 0 ]->m_nblocksx = 1;
204 vecBandProp[ 0 ]->m_nblocksy = 1;
205 vecBandProp[ 0 ]->m_noDataValue = 0;
208 std::map<std::string, std::string> dsinfo;
209 dsinfo[
"URI"] =
"TsRastertcRasterize.tif";
212 vecBandProp[ 0 ]->m_blkw, (
unsigned int)vecBandProp[ 0 ]->m_blkh,
213 new te::gm::Envelope( *geomPtrs[ 0 ]->getMBR() ), geomPtrs[ 0 ]->getSRID() );
216 vecBandProp, dsinfo));
218 std::vector< double > values;
219 values.push_back( 1.0 );
221 rst->rasterize( geomPtrs, values, 0 );
228 std::map<std::string, std::string> auxRasterInfo;
230 auxRasterInfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers_rgb342_crop3_EPSG_22522.tif";
233 BOOST_CHECK( inputRasterPtr.get() );
237 unsigned int nCols = inputRasterPtr->getNumberOfColumns();
238 unsigned int nRows = inputRasterPtr->getNumberOfRows();
245 inputRasterPtr->getGrid()->gridToGeo( -0.5, -0.5, x, y );
246 linearRingPtr->setPoint(0, x, y );
247 inputRasterPtr->getGrid()->gridToGeo( (
double)( nCols / 2 ) , -0.5, x, y );
248 linearRingPtr->setPoint(1, x, y );
249 inputRasterPtr->getGrid()->gridToGeo( -0.5 , (
double)( nRows / 2 ), x, y );
250 linearRingPtr->setPoint(2, x, y );
251 inputRasterPtr->getGrid()->gridToGeo( -0.5, -0.5, x, y );
252 linearRingPtr->setPoint(3, x, y );
255 inputRasterPtr->getSRID() ) );
256 polygonPtr->add( linearRingPtr.release() );
260 std::vector< te::gm::Geometry const *> geometries;
261 geometries.push_back( polygonPtr.get() );
263 auxRasterInfo[
"URI"] =
"TsRaster_clipping.tif";
264 boost::shared_ptr< te::rst::Raster > outputRasterPtr(
265 inputRasterPtr->clip( geometries, auxRasterInfo,
"GDAL" ) );
266 BOOST_CHECK( outputRasterPtr.get() );
273 std::map<std::string, std::string> auxRasterInfo;
275 auxRasterInfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_with_color_table_and_multires.tif";
278 BOOST_CHECK( inputRasterPtr.get() );
280 BOOST_CHECK( inputRasterPtr->getNumberOfBands() == 1 );
282 BOOST_CHECK( inputRasterPtr->getMultiResLevelsCount() == 1 );
284 boost::shared_ptr< te::rst::Raster > inputRasterMultiRestLevel0Ptr( inputRasterPtr->getMultiResLevel( 0 ) );
285 BOOST_CHECK( inputRasterMultiRestLevel0Ptr.get() );
287 BOOST_CHECK( inputRasterMultiRestLevel0Ptr->getNumberOfBands() == 1 );
288 BOOST_CHECK( inputRasterMultiRestLevel0Ptr->getBand( 0 )->getProperty()->m_colorInterp ==
te::rst::PaletteIdxCInt );
290 const std::size_t palSize = inputRasterPtr->getBand( 0 )->getProperty()->m_palette.size();
291 BOOST_CHECK( palSize == 256 );
292 const std::vector< te::rst::BandProperty::ColorEntry >& pal1 =
293 inputRasterMultiRestLevel0Ptr->getBand( 0 )->getProperty()->m_palette;
294 const std::vector< te::rst::BandProperty::ColorEntry >& pal2 =
295 inputRasterPtr->getBand( 0 )->getProperty()->m_palette;
297 for( std::size_t cIdx = 0 ; cIdx < palSize ; ++cIdx )
299 BOOST_CHECK( pal1[ cIdx ].c1 == pal2[ cIdx ].c1 );
300 BOOST_CHECK( pal1[ cIdx ].c2 == pal2[ cIdx ].c2 );
301 BOOST_CHECK( pal1[ cIdx ].c3 == pal2[ cIdx ].c3 );
302 BOOST_CHECK( pal1[ cIdx ].c4 == pal2[ cIdx ].c4 );
309 std::map<std::string, std::string> dsinfo;
310 dsinfo[
"URI"] =
"raster_statistics_persistence_test.tif";
315 std::vector<te::rst::BandProperty*> vecBandProp;
317 vecBandProp[ 0 ]->m_blkh = 100;
318 vecBandProp[ 0 ]->m_blkw = 100;
319 vecBandProp[ 0 ]->m_nblocksx = 1;
320 vecBandProp[ 0 ]->m_nblocksy = 1;
321 vecBandProp[ 0 ]->m_noDataValue = 0;
323 vecBandProp[ 0 ]->m_min = 1;
324 vecBandProp[ 0 ]->m_max = 1;
325 vecBandProp[ 0 ]->m_mean = 1;
326 vecBandProp[ 0 ]->m_stdDev = 1;
332 grid, vecBandProp, dsinfo));
334 BOOST_REQUIRE( rst.get() );
335 BOOST_REQUIRE( rst->getBand( 0 )->getProperty()->m_min == 1 );
336 BOOST_REQUIRE( rst->getBand( 0 )->getProperty()->m_max == 1 );
337 BOOST_REQUIRE( rst->getBand( 0 )->getProperty()->m_mean == 1 );
338 BOOST_REQUIRE( rst->getBand( 0 )->getProperty()->m_stdDev == 1 );
344 boost::shared_ptr< te::rst::Raster > inputRasterPtr (
347 BOOST_REQUIRE( inputRasterPtr.get() );
348 BOOST_REQUIRE( inputRasterPtr->getBand( 0 )->getProperty()->m_min == 1 );
349 BOOST_REQUIRE( inputRasterPtr->getBand( 0 )->getProperty()->m_max == 1 );
350 BOOST_REQUIRE( inputRasterPtr->getBand( 0 )->getProperty()->m_mean == 1 );
351 BOOST_REQUIRE( inputRasterPtr->getBand( 0 )->getProperty()->m_stdDev == 1 );
355 BOOST_AUTO_TEST_SUITE_END ()
This file contains include headers for the Data Type module of TerraLib.
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
Palette indexes color interpretation.
MultiPolygon is a MultiSurface whose elements are Polygons.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
A raster band description.
A RAM cache adaptor to an external existent raster that must always be avaliable. ...
An utility struct for representing 2D coordinates.
unsigned int unsigned int nCols
A LinearRing is a LineString that is both closed and simple.
An Envelope defines a 2D rectangular region.
BOOST_AUTO_TEST_SUITE(raster_tests) bool loadSHPFile(const std
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
static Raster * make()
It creates and returns an empty raster with default raster driver.
BOOST_AUTO_TEST_CASE(rasterConstructor_test)
This file contains include headers for the Vector Geometry model of TerraLib.
A rectified grid is the spatial support for raster data.
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.