TsExpansibleRaster.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 TsExpansibleRaster.cpp
22 
23  \brief A test suit for the Cached Raster class interface.
24 
25  */
26 
27 #include "TsExpansibleRaster.h"
28 #include "../Config.h"
29 
30 #include <terralib/raster.h>
31 #include <terralib/dataaccess.h>
32 
33 #include <boost/shared_ptr.hpp>
34 
36 
38 {
39  const unsigned int nBands = raster.getNumberOfBands();
40  const unsigned int nLines = raster.getNumberOfRows();
41  const unsigned int nCols = raster.getNumberOfColumns();
42  unsigned int band = 0;
43  unsigned int line = 0;
44  unsigned int col = 0;
45  double pixelValue = 0;
46 
47  for( band = 0 ; band < nBands ; ++band )
48  for( line = 0 ; line < nLines ; ++line )
49  for( col = 0 ; col < nCols ; ++col )
50  {
51  raster.setValue( col, line, pixelValue, band );
52  ++pixelValue;
53  }
54 }
55 
57 {
58  const unsigned int nBands = raster.getNumberOfBands();
59  const unsigned int nLines = raster.getNumberOfRows();
60  const unsigned int nCols = raster.getNumberOfColumns();
61  unsigned int band = 0;
62  unsigned int line = 0;
63  unsigned int col = 0;
64 
65  for( band = 0 ; band < nBands ; ++band )
66  {
67  const double noDataValue = raster.getBand( band )->getProperty()->m_noDataValue;
68 
69  for( line = 0 ; line < nLines ; ++line )
70  for( col = 0 ; col < nCols ; ++col )
71  {
72  raster.setValue( col, line, noDataValue, band );
73  }
74  }
75 }
76 
78 {
79  const unsigned int nBands = raster.getNumberOfBands();
80  const unsigned int nLines = raster.getNumberOfRows();
81  const unsigned int nCols = raster.getNumberOfColumns();
82  unsigned int band = 0;
83  unsigned int line = 0;
84  unsigned int col = 0;
85  double pixelValue = 0;
86  double readValue = 0;
87 
88  for( band = 0 ; band < nBands ; ++band )
89  for( line = 0 ; line < nLines ; ++line )
90  for( col = 0 ; col < nCols ; ++col )
91  {
92  raster.getValue( col, line, readValue, band );
93 
94  CPPUNIT_ASSERT( readValue == pixelValue );
95 
96  ++pixelValue;
97  }
98 }
99 
100 void TsExpansibleRaster::assertUniqueElement( const double& targetValue,
101  const unsigned int& requiredBand,
102  const unsigned int& requiredCol, const unsigned int& requiredLine,
103  const te::rst::Raster& raster )
104 {
105  const unsigned int nBands = raster.getNumberOfBands();
106  const unsigned int nLines = raster.getNumberOfRows();
107  const unsigned int nCols = raster.getNumberOfColumns();
108  unsigned int band = 0;
109  unsigned int line = 0;
110  unsigned int col = 0;
111  double readValue = 0;
112  bool elementFound = false;
113 
114  for( band = 0 ; band < nBands ; ++band )
115  for( line = 0 ; line < nLines ; ++line )
116  for( col = 0 ; col < nCols ; ++col )
117  {
118  raster.getValue( col, line, readValue, band );
119 
120  if( readValue == targetValue )
121  {
122  CPPUNIT_ASSERT( ! elementFound );
123  elementFound = true;
124 
125  CPPUNIT_ASSERT( band == requiredBand );
126  CPPUNIT_ASSERT( line == requiredLine );
127  CPPUNIT_ASSERT( col == requiredCol );
128  }
129  }
130 
131  CPPUNIT_ASSERT( elementFound );
132 }
133 
135 {
136  std::vector< te::rst::BandProperty * > bandsProps;
137  bandsProps.push_back( new te::rst::BandProperty( 0, te::dt::UINT32_TYPE ) );
138  bandsProps[ 0 ]->m_blkw = 5;
139  bandsProps[ 0 ]->m_blkh = 10;
140  bandsProps[ 0 ]->m_nblocksx = 2;
141  bandsProps[ 0 ]->m_nblocksy = 1;
142  bandsProps.push_back( new te::rst::BandProperty( 1, te::dt::UINT16_TYPE ) );
143  bandsProps[ 1 ]->m_blkw = 10;
144  bandsProps[ 1 ]->m_blkh = 10;
145  bandsProps[ 1 ]->m_nblocksx = 1;
146  bandsProps[ 1 ]->m_nblocksy = 1;
147  bandsProps.push_back( new te::rst::BandProperty( 2, te::dt::DOUBLE_TYPE ) );
148  bandsProps[ 2 ]->m_blkw = 10;
149  bandsProps[ 2 ]->m_blkh = 5;
150  bandsProps[ 2 ]->m_nblocksx = 1;
151  bandsProps[ 2 ]->m_nblocksy = 2;
152 
153  te::mem::ExpansibleRaster rasterInstance( new te::rst::Grid( 10, 10 ), bandsProps, 2 );
154 
155  writeValues( rasterInstance );
156  testValues( rasterInstance );
157 }
158 
159 
161 {
162  std::vector< te::rst::BandProperty * > bandsProps;
163  bandsProps.push_back( new te::rst::BandProperty( 0, te::dt::DOUBLE_TYPE ) );
164  bandsProps[ 0 ]->m_noDataValue = 0;
165  bandsProps[ 0 ]->m_blkw = 5;
166  bandsProps[ 0 ]->m_blkh = 10;
167  bandsProps[ 0 ]->m_nblocksx = 2;
168  bandsProps[ 0 ]->m_nblocksy = 1;
169  bandsProps.push_back( new te::rst::BandProperty( 1, te::dt::DOUBLE_TYPE ) );
170  bandsProps[ 1 ]->m_noDataValue = 0;
171  bandsProps[ 1 ]->m_blkw = 5;
172  bandsProps[ 1 ]->m_blkh = 10;
173  bandsProps[ 1 ]->m_nblocksx = 2;
174  bandsProps[ 1 ]->m_nblocksy = 1;
175  bandsProps.push_back( new te::rst::BandProperty( 2, te::dt::DOUBLE_TYPE ) );
176  bandsProps[ 2 ]->m_noDataValue = 0;
177  bandsProps[ 2 ]->m_blkw = 5;
178  bandsProps[ 2 ]->m_blkh = 10;
179  bandsProps[ 2 ]->m_nblocksx = 2;
180  bandsProps[ 2 ]->m_nblocksy = 1;
181 
182  te::mem::ExpansibleRaster rasterInstance( new te::rst::Grid( 10, 10 ), bandsProps, 2 );
183  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 3 );
184  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 10 );
185  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 10 );
186 
187  double readValue = 0;
188 
189  fillWithNoDataValues( rasterInstance );
190 
191  double xCoord = 0;
192  double yCoord = 0;
193  rasterInstance.getGrid()->gridToGeo( 5, 5, xCoord, yCoord );
194 
195  rasterInstance.getValue( 5, 5, readValue, 1 );
196  CPPUNIT_ASSERT( readValue == 0.0 );
197 
198  rasterInstance.setValue( 5, 5, 1, 1 );
199  rasterInstance.getValue( 5, 5, readValue, 1 );
200  CPPUNIT_ASSERT( readValue == 1.0 );
201 
202  rasterInstance.addTopLines( 3 );
203  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 3 );
204  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 20 );
205  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 10 );
206 
207  double col = 0;
208  double row = 0;
209  rasterInstance.getGrid()->geoToGrid( xCoord, yCoord, col, row );
210 
211  assertUniqueElement( 1.0, 1, (unsigned int)col, (unsigned int)row,
212  rasterInstance );
213 
214  writeValues( rasterInstance );
215  testValues( rasterInstance );
216 }
217 
219 {
220  std::vector< te::rst::BandProperty * > bandsProps;
221  bandsProps.push_back( new te::rst::BandProperty( 0, te::dt::DOUBLE_TYPE ) );
222  bandsProps[ 0 ]->m_noDataValue = 0;
223  bandsProps[ 0 ]->m_blkw = 5;
224  bandsProps[ 0 ]->m_blkh = 10;
225  bandsProps[ 0 ]->m_nblocksx = 2;
226  bandsProps[ 0 ]->m_nblocksy = 1;
227  bandsProps.push_back( new te::rst::BandProperty( 1, te::dt::DOUBLE_TYPE ) );
228  bandsProps[ 1 ]->m_noDataValue = 0;
229  bandsProps[ 1 ]->m_blkw = 5;
230  bandsProps[ 1 ]->m_blkh = 10;
231  bandsProps[ 1 ]->m_nblocksx = 2;
232  bandsProps[ 1 ]->m_nblocksy = 1;
233  bandsProps.push_back( new te::rst::BandProperty( 2, te::dt::DOUBLE_TYPE ) );
234  bandsProps[ 2 ]->m_noDataValue = 0;
235  bandsProps[ 2 ]->m_blkw = 5;
236  bandsProps[ 2 ]->m_blkh = 10;
237  bandsProps[ 2 ]->m_nblocksx = 2;
238  bandsProps[ 2 ]->m_nblocksy = 1;
239 
240  te::mem::ExpansibleRaster rasterInstance( new te::rst::Grid( 10, 10 ), bandsProps, 2 );
241  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 3 );
242  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 10 );
243  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 10 );
244 
245  double readValue = 0;
246 
247  fillWithNoDataValues( rasterInstance );
248 
249  double xCoord = 0;
250  double yCoord = 0;
251  rasterInstance.getGrid()->gridToGeo( 5, 5, xCoord, yCoord );
252 
253  rasterInstance.getValue( 5, 5, readValue, 1 );
254  CPPUNIT_ASSERT( readValue == 0.0 );
255 
256  rasterInstance.setValue( 5, 5, 1, 1 );
257  assertUniqueElement( 1.0, 1, (unsigned int)5, (unsigned int)5,
258  rasterInstance );
259 
260  rasterInstance.addBottomLines( 3 );
261  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 3 );
262  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 20 );
263  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 10 );
264 
265  double col = 0;
266  double row = 0;
267  rasterInstance.getGrid()->geoToGrid( xCoord, yCoord, col, row );
268 
269  assertUniqueElement( 1.0, 1, (unsigned int)col, (unsigned int)row,
270  rasterInstance );
271 
272  rasterInstance.getValue( 5, 19, readValue, 1 );
273  CPPUNIT_ASSERT( readValue == 0.0 );
274 
275  rasterInstance.setValue( 5, 19, 1, 1 );
276 
277  rasterInstance.getValue( 5, 19, readValue, 1 );
278  CPPUNIT_ASSERT( readValue == 1.0 );
279 
280  writeValues( rasterInstance );
281  testValues( rasterInstance );
282 
283  rasterInstance.addBottomLines( 10 );
284  writeValues( rasterInstance );
285  testValues( rasterInstance );
286 
287  rasterInstance.addBottomLines( 1 );
288  writeValues( rasterInstance );
289  testValues( rasterInstance );
290 }
291 
293 {
294  std::vector< te::rst::BandProperty * > bandsProps;
295  bandsProps.push_back( new te::rst::BandProperty( 0, te::dt::DOUBLE_TYPE ) );
296  bandsProps[ 0 ]->m_noDataValue = 0;
297  bandsProps[ 0 ]->m_blkw = 5;
298  bandsProps[ 0 ]->m_blkh = 10;
299  bandsProps[ 0 ]->m_nblocksx = 2;
300  bandsProps[ 0 ]->m_nblocksy = 1;
301  bandsProps.push_back( new te::rst::BandProperty( 1, te::dt::DOUBLE_TYPE ) );
302  bandsProps[ 1 ]->m_noDataValue = 0;
303  bandsProps[ 1 ]->m_blkw = 5;
304  bandsProps[ 1 ]->m_blkh = 10;
305  bandsProps[ 1 ]->m_nblocksx = 2;
306  bandsProps[ 1 ]->m_nblocksy = 1;
307  bandsProps.push_back( new te::rst::BandProperty( 2, te::dt::DOUBLE_TYPE ) );
308  bandsProps[ 2 ]->m_noDataValue = 0;
309  bandsProps[ 2 ]->m_blkw = 5;
310  bandsProps[ 2 ]->m_blkh = 10;
311  bandsProps[ 2 ]->m_nblocksx = 2;
312  bandsProps[ 2 ]->m_nblocksy = 1;
313 
314  te::mem::ExpansibleRaster rasterInstance( new te::rst::Grid( 10, 10 ), bandsProps, 2 );
315  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 3 );
316  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 10 );
317  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 10 );
318 
319  double readValue = 0;
320 
321  fillWithNoDataValues( rasterInstance );
322 
323  double xCoord = 0;
324  double yCoord = 0;
325  rasterInstance.getGrid()->gridToGeo( 5, 5, xCoord, yCoord );
326 
327  rasterInstance.getValue( 5, 5, readValue, 1 );
328  CPPUNIT_ASSERT( readValue == 0.0 );
329 
330  rasterInstance.setValue( 5, 5, 1, 1 );
331  assertUniqueElement( 1.0, 1, (unsigned int)5, (unsigned int)5,
332  rasterInstance );
333 
334  rasterInstance.addLeftColumns( 3 );
335  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 3 );
336  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 10 );
337  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 15 );
338 
339  double col = 0;
340  double row = 0;
341  rasterInstance.getGrid()->geoToGrid( xCoord, yCoord, col, row );
342 
343  assertUniqueElement( 1.0, 1, (unsigned int)col, (unsigned int)row,
344  rasterInstance );
345 
346  writeValues( rasterInstance );
347  testValues( rasterInstance );
348 }
349 
351 {
352  std::vector< te::rst::BandProperty * > bandsProps;
353  bandsProps.push_back( new te::rst::BandProperty( 0, te::dt::DOUBLE_TYPE ) );
354  bandsProps[ 0 ]->m_noDataValue = 0;
355  bandsProps[ 0 ]->m_blkw = 5;
356  bandsProps[ 0 ]->m_blkh = 10;
357  bandsProps[ 0 ]->m_nblocksx = 2;
358  bandsProps[ 0 ]->m_nblocksy = 1;
359  bandsProps.push_back( new te::rst::BandProperty( 1, te::dt::DOUBLE_TYPE ) );
360  bandsProps[ 1 ]->m_noDataValue = 0;
361  bandsProps[ 1 ]->m_blkw = 5;
362  bandsProps[ 1 ]->m_blkh = 10;
363  bandsProps[ 1 ]->m_nblocksx = 2;
364  bandsProps[ 1 ]->m_nblocksy = 1;
365  bandsProps.push_back( new te::rst::BandProperty( 2, te::dt::DOUBLE_TYPE ) );
366  bandsProps[ 2 ]->m_noDataValue = 0;
367  bandsProps[ 2 ]->m_blkw = 5;
368  bandsProps[ 2 ]->m_blkh = 10;
369  bandsProps[ 2 ]->m_nblocksx = 2;
370  bandsProps[ 2 ]->m_nblocksy = 1;
371 
372  te::mem::ExpansibleRaster rasterInstance( new te::rst::Grid( 10, 10 ), bandsProps, 2 );
373  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 3 );
374  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 10 );
375  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 10 );
376 
377  double readValue = 0;
378 
379  fillWithNoDataValues( rasterInstance );
380 
381  double xCoord = 0;
382  double yCoord = 0;
383  rasterInstance.getGrid()->gridToGeo( 5, 5, xCoord, yCoord );
384 
385  rasterInstance.getValue( 5, 5, readValue, 1 );
386  CPPUNIT_ASSERT( readValue == 0.0 );
387 
388  rasterInstance.setValue( 5, 5, 1, 1 );
389  assertUniqueElement( 1.0, 1, (unsigned int)5, (unsigned int)5,
390  rasterInstance );
391 
392  rasterInstance.addRightColumns( 3 );
393  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 3 );
394  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 10 );
395  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 15 );
396 
397  double col = 0;
398  double row = 0;
399  rasterInstance.getGrid()->geoToGrid( xCoord, yCoord, col, row );
400 
401  assertUniqueElement( 1.0, 1, (unsigned int)col, (unsigned int)row,
402  rasterInstance );
403 
404  rasterInstance.getValue( 14, 5, readValue, 1 );
405  CPPUNIT_ASSERT( readValue == 0.0 );
406 
407  rasterInstance.setValue( 14, 5, 1, 1 );
408  rasterInstance.getValue( 14, 5, readValue, 1 );
409  CPPUNIT_ASSERT( readValue == 1.0 );
410 
411  writeValues( rasterInstance );
412  testValues( rasterInstance );
413 
414  rasterInstance.addRightColumns( 10 );
415  writeValues( rasterInstance );
416  testValues( rasterInstance );
417 
418  rasterInstance.addRightColumns( 1 );
419  writeValues( rasterInstance );
420  testValues( rasterInstance );
421 }
422 
424 {
425  std::vector< te::rst::BandProperty * > bandsProps;
426  bandsProps.push_back( new te::rst::BandProperty( 0, te::dt::DOUBLE_TYPE ) );
427  bandsProps[ 0 ]->m_noDataValue = 0;
428  bandsProps[ 0 ]->m_blkw = 5;
429  bandsProps[ 0 ]->m_blkh = 10;
430  bandsProps[ 0 ]->m_nblocksx = 2;
431  bandsProps[ 0 ]->m_nblocksy = 1;
432  bandsProps.push_back( new te::rst::BandProperty( 1, te::dt::DOUBLE_TYPE ) );
433  bandsProps[ 1 ]->m_noDataValue = 0;
434  bandsProps[ 1 ]->m_blkw = 5;
435  bandsProps[ 1 ]->m_blkh = 10;
436  bandsProps[ 1 ]->m_nblocksx = 2;
437  bandsProps[ 1 ]->m_nblocksy = 1;
438  bandsProps.push_back( new te::rst::BandProperty( 2, te::dt::DOUBLE_TYPE ) );
439  bandsProps[ 2 ]->m_noDataValue = 0;
440  bandsProps[ 2 ]->m_blkw = 5;
441  bandsProps[ 2 ]->m_blkh = 10;
442  bandsProps[ 2 ]->m_nblocksx = 2;
443  bandsProps[ 2 ]->m_nblocksy = 1;
444 
445  te::mem::ExpansibleRaster rasterInstance( new te::rst::Grid( 10, 10 ), bandsProps, 2 );
446  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 3 );
447  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 10 );
448  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 10 );
449 
450  double readValue = 0;
451 
452  fillWithNoDataValues( rasterInstance );
453 
454  rasterInstance.getValue( 5, 5, readValue, 1 );
455  CPPUNIT_ASSERT( readValue == 0.0 );
456 
457  rasterInstance.setValue( 5, 5, 1, 1 );
458  assertUniqueElement( 1.0, 1, (unsigned int)5, (unsigned int)5,
459  rasterInstance );
460 
461  rasterInstance.addTopBands( 3 );
462  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 6 );
463  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 10 );
464  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 10 );
465 
466  assertUniqueElement( 1.0, 4, (unsigned int)5, (unsigned int)5,
467  rasterInstance );
468 
469  writeValues( rasterInstance );
470  testValues( rasterInstance );
471 }
472 
474 {
475  std::vector< te::rst::BandProperty * > bandsProps;
476  bandsProps.push_back( new te::rst::BandProperty( 0, te::dt::DOUBLE_TYPE ) );
477  bandsProps[ 0 ]->m_noDataValue = 0;
478  bandsProps[ 0 ]->m_blkw = 5;
479  bandsProps[ 0 ]->m_blkh = 10;
480  bandsProps[ 0 ]->m_nblocksx = 2;
481  bandsProps[ 0 ]->m_nblocksy = 1;
482  bandsProps.push_back( new te::rst::BandProperty( 1, te::dt::DOUBLE_TYPE ) );
483  bandsProps[ 1 ]->m_noDataValue = 0;
484  bandsProps[ 1 ]->m_blkw = 5;
485  bandsProps[ 1 ]->m_blkh = 10;
486  bandsProps[ 1 ]->m_nblocksx = 2;
487  bandsProps[ 1 ]->m_nblocksy = 1;
488  bandsProps.push_back( new te::rst::BandProperty( 2, te::dt::DOUBLE_TYPE ) );
489  bandsProps[ 2 ]->m_noDataValue = 0;
490  bandsProps[ 2 ]->m_blkw = 5;
491  bandsProps[ 2 ]->m_blkh = 10;
492  bandsProps[ 2 ]->m_nblocksx = 2;
493  bandsProps[ 2 ]->m_nblocksy = 1;
494 
495  te::mem::ExpansibleRaster rasterInstance( new te::rst::Grid( 10, 10 ), bandsProps, 2 );
496  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 3 );
497  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 10 );
498  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 10 );
499 
500  double readValue = 0;
501 
502  fillWithNoDataValues( rasterInstance );
503 
504  rasterInstance.getValue( 5, 5, readValue, 1 );
505  CPPUNIT_ASSERT( readValue == 0.0 );
506 
507  rasterInstance.setValue( 5, 5, 1, 1 );
508  assertUniqueElement( 1.0, 1, (unsigned int)5, (unsigned int)5,
509  rasterInstance );
510 
511  rasterInstance.addBottomBands( 3 );
512  CPPUNIT_ASSERT( rasterInstance.getNumberOfBands() == 6 );
513  CPPUNIT_ASSERT( rasterInstance.getNumberOfRows() == 10 );
514  CPPUNIT_ASSERT( rasterInstance.getNumberOfColumns() == 10 );
515 
516  assertUniqueElement( 1.0, 1, (unsigned int)5, (unsigned int)5,
517  rasterInstance );
518 
519  rasterInstance.getValue( 5, 5, readValue, 5 );
520  CPPUNIT_ASSERT( readValue == 0.0 );
521 
522  rasterInstance.setValue( 5, 5, 1, 5 );
523  rasterInstance.getValue( 5, 5, readValue, 5 );
524  CPPUNIT_ASSERT( readValue == 1.0 );
525 
526  writeValues( rasterInstance );
527  testValues( rasterInstance );
528 }
529 
531 {
532  std::vector< te::rst::BandProperty * > bandsProps;
533  bandsProps.push_back( new te::rst::BandProperty( 0, te::dt::UINT32_TYPE ) );
534  bandsProps[ 0 ]->m_blkw = 100;
535  bandsProps[ 0 ]->m_blkh = 1;
536  bandsProps[ 0 ]->m_nblocksx = 1;
537  bandsProps[ 0 ]->m_nblocksy = 100;
538  bandsProps.push_back( new te::rst::BandProperty( 1, te::dt::UINT32_TYPE ) );
539  bandsProps[ 1 ]->m_blkw = 100;
540  bandsProps[ 1 ]->m_blkh = 1;
541  bandsProps[ 1 ]->m_nblocksx = 1;
542  bandsProps[ 1 ]->m_nblocksy = 100;
543  bandsProps.push_back( new te::rst::BandProperty( 2, te::dt::UINT32_TYPE ) );
544  bandsProps[ 2 ]->m_blkw = 100;
545  bandsProps[ 2 ]->m_blkh = 1;
546  bandsProps[ 2 ]->m_nblocksx = 1;
547  bandsProps[ 2 ]->m_nblocksy = 100;
548 
549  te::mem::ExpansibleRaster rasterInstance( new te::rst::Grid( 100, 100 ), bandsProps, 2 );
550 
551  writeValues( rasterInstance );
552 
553  CPPUNIT_ASSERT( rasterInstance.getMultiResLevelsCount() == 0 );
554  CPPUNIT_ASSERT( rasterInstance.createMultiResolution( 3, te::rst::NearestNeighbor ) == true );
555  CPPUNIT_ASSERT( rasterInstance.getMultiResLevelsCount() == 3 );
556 
557  std::unique_ptr< te::rst::Raster > level0Ptr( rasterInstance.getMultiResLevel( 0 ) );
558  CPPUNIT_ASSERT( level0Ptr.get() != 0 );
559  CPPUNIT_ASSERT( level0Ptr->getNumberOfBands() == 3 );
560  CPPUNIT_ASSERT( level0Ptr->getNumberOfRows() == 100 );
561  CPPUNIT_ASSERT( level0Ptr->getNumberOfColumns() == 100 );
562 
563  std::unique_ptr< te::rst::Raster > level1Ptr( rasterInstance.getMultiResLevel( 1 ) );
564  CPPUNIT_ASSERT( level1Ptr.get() != 0 );
565  CPPUNIT_ASSERT( level1Ptr->getNumberOfBands() == 3 );
566  CPPUNIT_ASSERT( level1Ptr->getNumberOfRows() == 50 );
567  CPPUNIT_ASSERT( level1Ptr->getNumberOfColumns() == 50 );
568 
569  std::unique_ptr< te::rst::Raster > level2Ptr( rasterInstance.getMultiResLevel( 2 ) );
570  CPPUNIT_ASSERT( level2Ptr.get() != 0 );
571  CPPUNIT_ASSERT( level2Ptr->getNumberOfBands() == 3 );
572  CPPUNIT_ASSERT( level2Ptr->getNumberOfRows() == 25 );
573  CPPUNIT_ASSERT( level2Ptr->getNumberOfColumns() == 25 );
574 }
575 
577 {
578  std::vector< te::rst::BandProperty * > bandsProps;
579  bandsProps.push_back( new te::rst::BandProperty( 0, te::dt::UINT32_TYPE ) );
580  bandsProps[ 0 ]->m_blkw = 5;
581  bandsProps[ 0 ]->m_blkh = 10;
582  bandsProps[ 0 ]->m_nblocksx = 2;
583  bandsProps[ 0 ]->m_nblocksy = 1;
584  bandsProps.push_back( new te::rst::BandProperty( 1, te::dt::UINT16_TYPE ) );
585  bandsProps[ 1 ]->m_blkw = 10;
586  bandsProps[ 1 ]->m_blkh = 10;
587  bandsProps[ 1 ]->m_nblocksx = 1;
588  bandsProps[ 1 ]->m_nblocksy = 1;
589  bandsProps.push_back( new te::rst::BandProperty( 2, te::dt::DOUBLE_TYPE ) );
590  bandsProps[ 2 ]->m_blkw = 10;
591  bandsProps[ 2 ]->m_blkh = 5;
592  bandsProps[ 2 ]->m_nblocksx = 1;
593  bandsProps[ 2 ]->m_nblocksy = 2;
594 
595  te::mem::ExpansibleRaster rasterInstance( new te::rst::Grid( 10, 10 ), bandsProps, 2 );
596 
597  writeValues( rasterInstance );
598 
599  std::unique_ptr< te::mem::ExpansibleRaster > clonePtr(
600  (te::mem::ExpansibleRaster*)rasterInstance.clone() );
601 
602  testValues( *clonePtr );
603 }
virtual void setValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the attribute value in a band of a cell.
bool addTopLines(const unsigned int number)
New lines will be added at the top of the raster (before the first line).
unsigned int band
Near neighborhood interpolation method.
void assertUniqueElement(const double &targetValue, const unsigned int &requiredBand, const unsigned int &requiredCol, const unsigned int &requiredLine, const te::rst::Raster &raster)
bool createMultiResolution(const unsigned int levels, const te::rst::InterpolationMethod interpMethod)
Create a sub-sampled multi-resolution pyramid.
A raster band description.
Definition: BandProperty.h:61
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
A test suit for the Expansible Raster Class.
double pixelValue
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
Definition: BandProperty.h:136
std::size_t getNumberOfBands() const
Returns the number of bands (dimension of cells attribute values) in the raster.
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
unsigned int line
unsigned int unsigned int nCols
An abstract class for raster data strucutures.
bool addRightColumns(const unsigned int number)
New columns will be added at the right of the raster (after the last column).
unsigned int getNumberOfRows() const
Returns the raster number of rows.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
void fillWithNoDataValues(te::rst::Raster &raster)
BandProperty * getProperty()
Returns the band property.
bool addBottomBands(const unsigned int number)
New bands will be added at the bottom of the raster (after de the last band).
void testValues(te::rst::Raster &raster)
te::rst::Raster * getMultiResLevel(const unsigned int level) const
Returns the required level of a multi-resolution pyramid or NULL if that level does not exists...
bool addBottomLines(const unsigned int number)
New lines will be added at the bottom of the raster (after de the last line).
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
Grid * getGrid()
It returns the raster grid.
unsigned int getMultiResLevelsCount() const
Returns the current number of multi-resolution pyramid levels.
void writeValues(te::rst::Raster &raster)
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
A test suit for the Cached Raster class interface.
CPPUNIT_TEST_SUITE_REGISTRATION(TsExpansibleRaster)
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
te::dt::AbstractData * clone() const
It returns a clone of this object.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
This file contains include headers for the Data Access module of TerraLib.
bool addLeftColumns(const unsigned int number)
New columns will be added at the left of the raster (before the first column).
bool addTopBands(const unsigned int number)
New bands will be added at the top of the raster (before the first band).
unsigned int nLines
unsigned int col