SequenceMosaic.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/rp/SequenceMosaic.cpp
22  \brief Create mosaics from a sequence of overlapped rasters using an automatic tie-points detection method.
23 */
24 
25 #include "SequenceMosaic.h"
26 
27 #include "RasterHandler.h"
28 #include "Macros.h"
29 #include "Functions.h"
30 #include "../raster/Grid.h"
31 #include "../raster/BandProperty.h"
32 #include "../raster/Utils.h"
33 #include "../raster/RasterFactory.h"
34 #include "../memory/CachedRaster.h"
35 #include "../memory/ExpansibleRaster.h"
36 #include "../geometry/Envelope.h"
37 #include "../geometry/GeometricTransformation.h"
38 #include "../geometry/Polygon.h"
39 #include "../geometry/LinearRing.h"
40 #include "../geometry/MultiPolygon.h"
41 #include "../geometry/MultiPoint.h"
42 #include "../geometry/Point.h"
43 #include "../common/progress/TaskProgress.h"
44 #include "../common/PlatformUtils.h"
45 
46 #include <boost/lexical_cast.hpp>
47 
48 #include <memory>
49 #include <cmath>
50 
51 #define SEQUENCE_RASTER_MAX_MOSAIC_MEM_USE 10
52 
53 namespace te
54 {
55  namespace rp
56  {
57 
59  {
60  reset();
61  }
62 
64  {
65  reset();
66  operator=( other );
67  }
68 
70  {
71  reset();
72  }
73 
75  {
76  m_feederRasterPtr = nullptr;
77  m_inputRastersBands.clear();
78  m_geomTransfName = "Affine";
80  m_noDataValue = 0.0;
83  m_autoEqualize = true;
84  m_useRasterCache = true;
85  m_enableMultiThread = true;
86  m_enableProgress = false;
89  m_outDataSetsNameSufix.clear();
92  }
93 
95  const SequenceMosaic::InputParameters& params )
96  {
97  reset();
98 
103  m_noDataValue = params.m_noDataValue;
105  m_blendMethod = params.m_blendMethod;
116 
117  return *this;
118  }
119 
121  {
122  return new InputParameters( *this );
123  }
124 
125  // ----------------------------------------------------------------------
126 
128  {
129  reset();
130  }
131 
133  {
134  reset();
135  operator=( other );
136  }
137 
139  {
140  reset();
141  }
142 
144  {
145  m_outputDSPtr = nullptr;
146  m_sequencesInfo.clear();
147  }
148 
150  const SequenceMosaic::OutputParameters& params )
151  {
152  reset();
153 
154  m_outputDSPtr = params.m_outputDSPtr;
155  m_sequencesInfo = params.m_sequencesInfo;
156 
157  return *this;
158  }
159 
161  {
162  return new OutputParameters( *this );
163  }
164 
165  // ----------------------------------------------------------------------
166 
168 
170 
172  {
173  m_dataSetName.clear();
174  m_rasterFeederIndexes.clear();
175  m_tiePoints.clear();
176  }
177 
178  // ----------------------------------------------------------------------
179 
181  {
182  reset();
183  }
184 
186 
188  throw( te::rp::Exception )
189  {
190  if( ! m_isInitialized ) return false;
191 
192  SequenceMosaic::OutputParameters* outParamsPtr = dynamic_cast<
193  SequenceMosaic::OutputParameters* >( &outputParams );
194  TERP_TRUE_OR_THROW( outParamsPtr, "Invalid paramters" );
195 
197  "Invalid data source" );
199  "Invalid data source" );
200 
201  outParamsPtr->m_sequencesInfo.clear();
202 
203  // progress
204 
205  std::unique_ptr< te::common::TaskProgress > progressPtr;
207  {
208  progressPtr.reset( new te::common::TaskProgress );
209 
210  progressPtr->setTotalSteps( m_inputParameters.m_feederRasterPtr->getObjsCount() );
211 
212  progressPtr->setMessage( "Mosaicking" );
213  }
214 
215  // iterating over all rasters
216 
217  const std::vector< double > dummyRasterOffsets( m_inputParameters.m_inputRastersBands[ 0 ].size(), 0.0 );
218  const std::vector< double > dummyRasterScales( m_inputParameters.m_inputRastersBands[ 0 ].size(), 1.0 );
219 
220  std::vector< unsigned int > dummyRasterBandsIndexes;
221  {
222  for( unsigned int bandIdx = 0 ; bandIdx <
223  m_inputParameters.m_inputRastersBands[ 0 ].size(); ++bandIdx )
224  dummyRasterBandsIndexes.push_back( bandIdx );
225  }
226 
227  std::unique_ptr< te::mem::ExpansibleRaster > mosaicRasterHandler;
228  std::vector< double > mosaicTargetMeans;
229  std::vector< double > mosaicTargetVariances;
230  te::gm::MultiPolygon mosaicValidAreaPols( 0, te::gm::MultiPolygonType, 0 ); // the polygons delimiting the valid data inside the mosaic (mosaic world coods)
231  std::vector< double > mosaicBandsRangeMin;
232  std::vector< double > mosaicBandsRangeMax;
233  unsigned int prevRasterMosaicFirstCol = 0; // The last raster added to the mosaic position
234  unsigned int prevRasterMosaicFirstRow = 0; // The last raster added to the mosaic position
235  unsigned int prevRasterMosaicLastCol = 0; // The last raster added to the mosaic position
236  unsigned int prevRasterMosaicLastRow = 0; // The last raster added to the mosaic position
237  MosaicSequenceInfo currentMosaicSquenceInfo;
238 
241  {
242  const unsigned int inputRasterIdx =
244 
245  te::rst::Raster const* inputRasterPtr =
247 
248  std::unique_ptr< te::mem::CachedRaster > cachedInputRasterPtr;
250  {
251  cachedInputRasterPtr.reset( new te::mem::CachedRaster(
254  inputRasterPtr = cachedInputRasterPtr.get();
255  }
256 
257  // saving the current mosaic (debug purposes)
258 
259 // if( mosaicRasterHandler.get() )
260 // {
261 // if( ! createDiskRasterCopy( "Mosaic_" +
262 // boost::lexical_cast< std::string >( inputRasterIdx - 1 ) + ".tif",
263 // *mosaicRasterHandler ) )
264 // {
265 // return false;
266 // }
267 // }
268 
269  // Mosaicking
270 
271  if( mosaicRasterHandler.get() == nullptr )
272  {
273  // calculating the initial mosaic blocking scheme
274 
275  unsigned int mosaicNBlocksX = 4;
276  unsigned int mosaicNBlocksY = 4;
278  {
279  const unsigned int nProc = te::common::GetPhysProcNumber();
280 
281  if( ( mosaicNBlocksX * mosaicNBlocksY ) < nProc )
282  {
283  mosaicNBlocksX = mosaicNBlocksY = (unsigned int)std::ceil(
284  std::sqrt( (double)nProc ) );
285  }
286  }
287 
288  unsigned int mosaicBlockW = (unsigned int)std::ceil( ((double) inputRasterPtr->getNumberOfColumns())
289  / ((double)mosaicNBlocksX) );
290  unsigned int mosaicBlockH = (unsigned int)std::ceil( ((double)inputRasterPtr->getNumberOfRows())
291  / ((double)mosaicNBlocksY ) );
292 
293  unsigned int mosaicNCols = mosaicBlockW * mosaicNBlocksX;
294  unsigned int mosaicNRows = mosaicBlockH * mosaicNBlocksY;
295 
296  // creating the raster mosaic
297 
298  std::vector< te::rst::BandProperty* > bandsProperties;
299 
300  for( std::vector< unsigned int >::size_type inputRastersBandsIdx = 0 ;
301  inputRastersBandsIdx < m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size() ;
302  ++inputRastersBandsIdx )
303  {
304  te::rst::BandProperty const* const inBandPropPtr =
306  inputRasterIdx ][ inputRastersBandsIdx ] )->getProperty();
307 
308  bandsProperties.push_back( new te::rst::BandProperty( *inBandPropPtr ) );
309  bandsProperties[ inputRastersBandsIdx ]->m_colorInterp = te::rst::GrayIdxCInt;
310  bandsProperties[ inputRastersBandsIdx ]->m_noDataValue = m_inputParameters.m_noDataValue;
311  bandsProperties[ inputRastersBandsIdx ]->m_blkw = mosaicBlockW;
312  bandsProperties[ inputRastersBandsIdx ]->m_blkh = mosaicBlockH;
313  bandsProperties[ inputRastersBandsIdx ]->m_nblocksx = mosaicNBlocksX;
314  bandsProperties[ inputRastersBandsIdx ]->m_nblocksy = mosaicNBlocksY;
315  }
316 
317  te::gm::Coord2D uLC( inputRasterPtr->getGrid()->getExtent()->getLowerLeftX(),
318  inputRasterPtr->getGrid()->getExtent()->getUpperRightY() );
319 
320  te::rst::Grid* mosaicGridPtr = new te::rst::Grid(
321  mosaicNCols,
322  mosaicNRows,
323  inputRasterPtr->getGrid()->getResolutionX(),
324  inputRasterPtr->getGrid()->getResolutionY(),
325  &uLC,
326  inputRasterPtr->getSRID() );
327 
328  mosaicRasterHandler.reset(
330  mosaicGridPtr,
331  bandsProperties ) );
332  TERP_INSTANCE_TRUE_OR_RETURN_FALSE( mosaicRasterHandler.get(),
333  "Output raster creation error" );
334 
335  // updating the global mosaic variables
336 
337  mosaicBandsRangeMin.resize(
338  mosaicRasterHandler->getNumberOfBands(), 0 );
339  mosaicBandsRangeMax.resize(
340  mosaicRasterHandler->getNumberOfBands(), 0 );
341  for( unsigned int mosaicBandidx = 0 ; mosaicBandidx <
342  mosaicRasterHandler->getNumberOfBands() ; ++mosaicBandidx )
343  {
345  mosaicRasterHandler->getBand( mosaicBandidx )->getProperty()->m_type,
346  mosaicBandsRangeMin[ mosaicBandidx ],
347  mosaicBandsRangeMax[ mosaicBandidx ]);
348  }
349 
350  prevRasterMosaicFirstCol = 0;
351  prevRasterMosaicLastRow = inputRasterPtr->getNumberOfRows() - 1;
352  prevRasterMosaicLastCol = inputRasterPtr->getNumberOfColumns() - 1;
353  prevRasterMosaicFirstRow = 0;
354 
355  const double& mosaicLLX = mosaicRasterHandler->getGrid()->getExtent()->m_llx;
356  const double& mosaicLLY = mosaicRasterHandler->getGrid()->getExtent()->m_lly;
357  const double& mosaicURX = mosaicRasterHandler->getGrid()->getExtent()->m_urx;
358  const double& mosaicURY = mosaicRasterHandler->getGrid()->getExtent()->m_ury;
359 
361  auxLinearRingPtr->setPoint( 0, mosaicLLX, mosaicURY );
362  auxLinearRingPtr->setPoint( 1, mosaicURX, mosaicURY );
363  auxLinearRingPtr->setPoint( 2, mosaicURX, mosaicLLY );
364  auxLinearRingPtr->setPoint( 3, mosaicLLX, mosaicLLY );
365  auxLinearRingPtr->setPoint( 4, mosaicLLX, mosaicURY );
366  auxLinearRingPtr->setSRID( mosaicRasterHandler->getGrid()->getSRID() );
367 
369  mosaicRasterHandler->getGrid()->getSRID(), nullptr );
370  outPolPtr->add( auxLinearRingPtr );
371 
372  mosaicValidAreaPols.clear();
373  mosaicValidAreaPols.add( outPolPtr );
374  mosaicValidAreaPols.setSRID( mosaicRasterHandler->getGrid()->getSRID() );
375 
376  // fill the output mosaic raster
377 
378  {
379  const unsigned int nBands = static_cast<unsigned int>(mosaicRasterHandler->getNumberOfBands());
380  const unsigned int inputRasterNRows = inputRasterPtr->getNumberOfRows();
381  const unsigned int inputRasterNCols = inputRasterPtr->getNumberOfColumns();
382  const unsigned int mosaicNRows = mosaicRasterHandler->getNumberOfRows();
383  const unsigned int mosaicNCols = mosaicRasterHandler->getNumberOfColumns();
384  unsigned long int validPixelsNumber = 0;
385  unsigned int outCol = 0;
386  unsigned int outRow = 0;
387  double pixelValue = 0;
388 
389  mosaicTargetMeans.resize( nBands, 0.0 );
390  mosaicTargetVariances.resize( nBands, 0.0 );
391 
392  for( unsigned int inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
393  nBands ; ++inputRastersBandsIdx )
394  {
395  const unsigned int inputBandIdx =
396  m_inputParameters.m_inputRastersBands[ inputRasterIdx ][ inputRastersBandsIdx ] ;
397  te::rst::Band& outBand =
398  (*mosaicRasterHandler->getBand( inputRastersBandsIdx ));
399  const te::rst::Band& inBand =
400  (*inputRasterPtr->getBand( inputBandIdx ));
401  const double& inputBandNoDataValue = m_inputParameters.m_forceInputNoDataValue ?
402  m_inputParameters.m_noDataValue : inputRasterPtr->getBand( inputBandIdx
404  const double& outputBandNoDataValue = outBand.getProperty()->m_noDataValue;
405 
406  double mean = 0.0;
407 
408  for( outRow = 0 ; outRow < mosaicNRows ; ++outRow )
409  {
410  for( outCol = 0 ; outCol < mosaicNCols ; ++outCol )
411  {
412  if( ( outRow < inputRasterNRows ) && ( outCol < inputRasterNCols ) )
413  {
414  inBand.getValue( outCol, outRow, pixelValue );
415 
416  if( pixelValue != inputBandNoDataValue )
417  {
418  outBand.setValue( outCol, outRow, pixelValue );
419 
420  mean += pixelValue;
421  ++validPixelsNumber;
422  }
423  }
424  else
425  {
426  outBand.setValue( outCol, outRow, outputBandNoDataValue );
427  }
428  }
429  }
430 
431  // variance calcule
432 
433  if( m_inputParameters.m_autoEqualize && ( validPixelsNumber > 0 ) )
434  {
435  mean /= ( (double)validPixelsNumber );
436  mosaicTargetMeans[ inputRastersBandsIdx ] = mean;
437 
438  double& variance = mosaicTargetVariances[ inputRastersBandsIdx ];
439  variance = 0;
440 
441  double pixelValue = 0;
442 
443  for( outRow = 0 ; outRow < inputRasterNRows ; ++outRow )
444  {
445  for( outCol = 0 ; outCol < inputRasterNCols ; ++outCol )
446  {
447  outBand.getValue( outCol, outRow, pixelValue );
448 
449  if( pixelValue != inputBandNoDataValue )
450  {
451  variance += ( ( pixelValue - mean ) * ( pixelValue -
452  mean ) ) / ( (double)validPixelsNumber );
453  }
454  }
455  }
456  }
457  }
458  }
459 
460  // Updating the mosaic sequence info
461 
462  currentMosaicSquenceInfo.m_rasterFeederIndexes.push_back(
463  inputRasterIdx );
464  currentMosaicSquenceInfo.m_tiePoints.push_back(
465  std::vector< te::gm::GTParameters::TiePoint >() );
466 
467  // Move to the next raster
468 
469  cachedInputRasterPtr.reset();
470 
472 
474  {
475  progressPtr->pulse();
476  if( ! progressPtr->isActive() ) return false;
477  }
478  }
479  else
480  {
481  // Locating the tie points where te::gm::GTParameters::TiePoint::first
482  // are :mosaic indexed coods and te::gm::GTParameters::TiePoint::second are
483  // indexed coords from the current raster
484 
486 
487  {
489  locatorInParams = m_inputParameters.m_locatorParams;
490 
491  locatorInParams.m_inRaster1Ptr = mosaicRasterHandler.get();
492 
493  locatorInParams.m_inMaskRaster1Ptr = nullptr;
494 
495  locatorInParams.m_inRaster1Bands.clear();
496  locatorInParams.m_inRaster1Bands.push_back(
498 
499  locatorInParams.m_raster1TargetAreaColStart = prevRasterMosaicFirstCol;
500  locatorInParams.m_raster1TargetAreaLineStart = prevRasterMosaicFirstRow;
501  locatorInParams.m_raster1TargetAreaWidth = (unsigned int)(
502  prevRasterMosaicLastCol - prevRasterMosaicFirstCol + 1 );
503  locatorInParams.m_raster1TargetAreaHeight = (unsigned int)(
504  prevRasterMosaicLastRow - prevRasterMosaicFirstRow + 1 );
505 
506  locatorInParams.m_inRaster2Ptr = inputRasterPtr;
507 
508  locatorInParams.m_inMaskRaster2Ptr = nullptr;
509 
510  locatorInParams.m_inRaster2Bands.clear();
511  locatorInParams.m_inRaster2Bands.push_back(
512  m_inputParameters.m_inputRastersBands[ inputRasterIdx ][
514 
515  locatorInParams.m_raster2TargetAreaLineStart = 0;
516  locatorInParams.m_raster2TargetAreaColStart = 0;
517  locatorInParams.m_raster2TargetAreaWidth = 0;
518  locatorInParams.m_raster2TargetAreaHeight = 0;
519 
521 
522  locatorInParams.m_enableProgress = false;
523 
524  if( mosaicRasterHandler->getSRID() == inputRasterPtr->getSRID() )
525  {
526  locatorInParams.m_pixelSizeXRelation = mosaicRasterHandler->getResolutionX() /
527  inputRasterPtr->getResolutionX();
528  locatorInParams.m_pixelSizeYRelation = mosaicRasterHandler->getResolutionY() /
529  inputRasterPtr->getResolutionY();
530  }
531  else
532  {
533  te::gm::Envelope inputRasterExtent( *inputRasterPtr->getGrid()->getExtent() );
534  inputRasterExtent.transform( inputRasterPtr->getSRID(),
535  mosaicRasterHandler->getSRID() );
536 
537  locatorInParams.m_pixelSizeXRelation = mosaicRasterHandler->getResolutionX() /
538  ( inputRasterExtent.getWidth() / ((double)inputRasterPtr->getNumberOfColumns()) );
539  locatorInParams.m_pixelSizeYRelation = mosaicRasterHandler->getResolutionY() /
540  ( inputRasterExtent.getHeight() / ((double)inputRasterPtr->getNumberOfRows()) );
541  }
542 
544 
545  locatorInParams.m_enableGeometryFilter = true;
546 
548 
549  te::rp::TiePointsLocator locatorInstance;
551  locatorInParams ), "Tie points locator init error" );
552  if( ! locatorInstance.execute( locatorOutParams ) )
553  {
554  locatorInParams.reset();
555  }
556  }
557 
558  // The matching was accomplished successfully ?
559 
560  if(
561  ( locatorOutParams.m_transformationPtr.get() == nullptr )
562  ||
563  (
564  locatorOutParams.m_tiePoints.size()
565  <
566  (
567  2
568  *
569  locatorOutParams.m_transformationPtr->getMinRequiredTiePoints()
570  )
571  )
572  ||
573  (
574  (
575  te::rp::GetTPConvexHullArea( locatorOutParams.m_tiePoints, true )
576  /
577  (double)(
578  inputRasterPtr->getNumberOfColumns()
579  *
580  inputRasterPtr->getNumberOfRows()
581  )
582  )
583  <
584  (
586  /
587  100.0
588  )
589  )
590  )
591  {
592  // Saving the mosaic sequence info
593 
594  currentMosaicSquenceInfo.m_dataSetName = m_inputParameters.m_outDataSetsNamePrefix +
595  boost::lexical_cast< std::string >( outParamsPtr->m_sequencesInfo.size() ) +
597 
598  outParamsPtr->m_sequencesInfo.push_back( currentMosaicSquenceInfo );
599 
600  // Create the output data set
601 
602  assert( mosaicRasterHandler.get() );
604  currentMosaicSquenceInfo.m_dataSetName,
605  *( mosaicRasterHandler.get() ), outParamsPtr->m_outputDSPtr ),
606  "Data set creation error" );
607  mosaicRasterHandler.reset();
608 
609  currentMosaicSquenceInfo.clear();
610  }
611  else
612  {
613  // Generating the offset and gain info for eath band from the current raster
614 
615  std::vector< double > currentRasterBandsOffsets = dummyRasterOffsets;
616  std::vector< double > currentRasterBandsScales = dummyRasterScales;
617 
619  {
620  double currentRasterVariance = 0;
621  double currentRasterMean = 0;
622 
623  for( unsigned int inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
624  m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size() ;
625  ++inputRastersBandsIdx )
626  {
627  const unsigned int inputBandIdx = m_inputParameters.m_inputRastersBands[ inputRasterIdx ][
628  inputRastersBandsIdx ];
629 
630  if(
631  ( mosaicTargetMeans[ inputRastersBandsIdx ] != 0.0 )
632  &&
633  ( mosaicTargetVariances[ inputRastersBandsIdx ] != 0.0 )
634  )
635  {
636  calcBandStatistics( (*inputRasterPtr->getBand( inputBandIdx ) ),
639  currentRasterMean,
640  currentRasterVariance );
641 
642  currentRasterBandsScales[ inputRastersBandsIdx ] =
643  (
644  std::sqrt( mosaicTargetVariances[ inputRastersBandsIdx ] )
645  /
646  std::sqrt( currentRasterVariance )
647  );
648  currentRasterBandsOffsets[ inputRastersBandsIdx ] =
649  (
650  mosaicTargetMeans[ inputRastersBandsIdx ]
651  -
652  (
653  currentRasterBandsScales[ inputRastersBandsIdx ]
654  *
655  currentRasterMean
656  )
657  );
658  }
659  }
660  }
661 
662  // Updating the mosaic sequence info
663 
664  currentMosaicSquenceInfo.m_tiePoints.push_back(
665  locatorOutParams.m_tiePoints );
666  currentMosaicSquenceInfo.m_rasterFeederIndexes.push_back(
667  inputRasterIdx );
668 
669  // The indexed detailed extent of input raster
670 
671  te::gm::LinearRing inRasterIndexedDetailedExtent( te::gm::LineStringType, 0, nullptr );
673  *inputRasterPtr->getGrid(), inRasterIndexedDetailedExtent ),
674  "Error creating the raster detailed extent" );
675 
676  // Expanding the mosaic to fit the extent requirement allowing the
677  // merge of the current raster.
678  // Fiding the new geometric transformation between then.
679 
680  std::unique_ptr< te::gm::GeometricTransformation > geoTransPtr(
681  locatorOutParams.m_transformationPtr->clone() );
682 
683  {
684  // guessing the limits of the new blended raster over the old mosaic
685 
686  double mappedLRX = std::numeric_limits< double >::min();
687  double mappedLRY = std::numeric_limits< double >::min();
688  double mappedULX = std::numeric_limits< double >::max();
689  double mappedULY = std::numeric_limits< double >::max();
690  double mappedX = 0;
691  double mappedY = 0;
692  for( unsigned int inRasterDetExtentIdx = 0 ; inRasterDetExtentIdx <
693  inRasterIndexedDetailedExtent.size() ; ++inRasterDetExtentIdx )
694  {
695  locatorOutParams.m_transformationPtr->inverseMap(
696  inRasterIndexedDetailedExtent.getX( inRasterDetExtentIdx ),
697  inRasterIndexedDetailedExtent.getY( inRasterDetExtentIdx ),
698  mappedX,
699  mappedY);
700 
701  if( mappedLRX < mappedX ) mappedLRX = mappedX;
702  if( mappedLRY < mappedY ) mappedLRY = mappedY;
703  if( mappedULX > mappedX ) mappedULX = mappedX;
704  if( mappedULY > mappedY ) mappedULY = mappedY;
705  }
706 
707  // calc of old reference for future use
708 
709  double oldMosaicReferenceX = 0;
710  double oldMosaicReferenceY = 0;
711  mosaicRasterHandler->getGrid()->gridToGeo( 0.0, 0.0, oldMosaicReferenceX,
712  oldMosaicReferenceY );
713 
714  // expanding
715 
716  double mosaicReferenceHasChanged = false;
717 
718  if( mappedULX < 0.0 )
719  {
720  TERP_INSTANCE_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addLeftColumns(
721  (unsigned int)std::ceil( -1.0 * mappedULX ) ),
722  "Mosaic expansion error" );
723  mosaicReferenceHasChanged = true;
724  }
725 
726  if( mappedULY < 0.0 )
727  {
728  TERP_INSTANCE_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addTopLines(
729  (unsigned int)std::ceil( -1.0 * mappedULY ) ),
730  "Mosaic expansion error" );
731  mosaicReferenceHasChanged = true;
732  }
733 
734  if( mappedLRX > ((double)(mosaicRasterHandler->getNumberOfColumns() - 1) ) )
735  {
736  TERP_INSTANCE_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addRightColumns(
737  (unsigned int)std::ceil( mappedLRX -
738  ((double)(mosaicRasterHandler->getNumberOfColumns() - 1)) ) ),
739  "Mosaic expansion error" );
740  }
741 
742  if( mappedLRY > ((double)(mosaicRasterHandler->getNumberOfRows() - 1) ) )
743  {
744  TERP_INSTANCE_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addBottomLines(
745  (unsigned int)std::ceil( mappedLRY -
746  ((double)(mosaicRasterHandler->getNumberOfRows() - 1) ) ) ),
747  "Mosaic expansion error" );
748  }
749 
750  // updating the geometric transformation between both rasters
751 
752  if( mosaicReferenceHasChanged )
753  {
754  double expansionOffSetX = 0;
755  double expansionOffSetY = 0;
756  mosaicRasterHandler->getGrid()->geoToGrid( oldMosaicReferenceX,
757  oldMosaicReferenceY, expansionOffSetX, expansionOffSetY );
758 
759  te::gm::GTParameters newTransParams;
760  newTransParams.m_tiePoints =
761  geoTransPtr->getParameters().m_tiePoints;
762 
763  for( unsigned int tpIdx = 0 ; tpIdx <
764  newTransParams.m_tiePoints.size() ; ++tpIdx )
765  {
766  newTransParams.m_tiePoints[ tpIdx ].first.x += expansionOffSetX;
767  newTransParams.m_tiePoints[ tpIdx ].first.y += expansionOffSetY;
768  }
769 
770  TERP_INSTANCE_TRUE_OR_RETURN_FALSE( geoTransPtr->initialize( newTransParams ),
771  "Geometric transformation parameters calcule error" );
772  }
773  }
774 
775  // Blending the current raster into the mosaic
776 
777  {
778  te::rp::Blender blenderInstance;
779 
781  *( mosaicRasterHandler.get() ),
782  dummyRasterBandsIndexes,
783  *inputRasterPtr,
784  m_inputParameters.m_inputRastersBands[ inputRasterIdx ],
789  false,
791  dummyRasterOffsets,
792  dummyRasterScales,
793  currentRasterBandsOffsets,
794  currentRasterBandsScales,
795  &mosaicValidAreaPols,
796  nullptr,
797  *geoTransPtr,
799  false ),
800  "Blender initiazing error" );
801 
803  "Error blending images" );
804  }
805 
806  // The input rasters detailed extent over the expanded mosaic
807 
808  te::gm::LinearRing inRasterDetailedExtent(
809  inRasterIndexedDetailedExtent.size(), te::gm::LineStringType,
810  mosaicRasterHandler->getSRID(), (te::gm::Envelope*)nullptr );
811 
812  {
813  double mappedX = 0;
814  double mappedY = 0;
815 
816  for( unsigned int inRasterDetExtentIdx = 0 ; inRasterDetExtentIdx <
817  inRasterIndexedDetailedExtent.size() ; ++inRasterDetExtentIdx )
818  {
819  locatorOutParams.m_transformationPtr->inverseMap(
820  inRasterIndexedDetailedExtent.getX( inRasterDetExtentIdx ),
821  inRasterIndexedDetailedExtent.getY( inRasterDetExtentIdx ),
822  mappedX,
823  mappedY);
824 
825  inRasterDetailedExtent.setPoint( inRasterDetExtentIdx, mappedX, mappedY );
826  }
827  }
828 
829  // Updating the info about the position of the last blended raster
830 
831  {
832  prevRasterMosaicLastCol = 0;
833  prevRasterMosaicLastRow = 0;
834  prevRasterMosaicFirstCol = std::numeric_limits< unsigned int >::max();
835  prevRasterMosaicFirstRow = std::numeric_limits< unsigned int >::max();
836 
837  double mappedX = 0;
838  double mappedY = 0;
839  for( unsigned int inRasterDetExtentIdx = 0 ; inRasterDetExtentIdx <
840  inRasterDetailedExtent.size() ; ++inRasterDetExtentIdx )
841  {
842  geoTransPtr->inverseMap(
843  inRasterDetailedExtent.getX( inRasterDetExtentIdx ),
844  inRasterDetailedExtent.getY( inRasterDetExtentIdx ),
845  mappedX,
846  mappedY);
847 
848  mappedX = std::max( mappedX, 0.0 );
849  mappedX = std::min( mappedX,
850  (double)( mosaicRasterHandler->getNumberOfColumns() - 1 ) );
851 
852  mappedY = std::max( mappedY, 0.0 );
853  mappedY = std::min( mappedY,
854  (double)( mosaicRasterHandler->getNumberOfRows() - 1 ) );
855 
856  if (prevRasterMosaicLastCol < static_cast<unsigned int>(mappedX)) prevRasterMosaicLastCol = static_cast<unsigned int>(mappedX);
857  if (prevRasterMosaicLastRow < static_cast<unsigned int>(mappedY)) prevRasterMosaicLastRow = static_cast<unsigned int>(mappedY);
858  if (prevRasterMosaicFirstCol > static_cast<unsigned int>(mappedX)) prevRasterMosaicFirstCol = static_cast<unsigned int>(mappedX);
859  if (prevRasterMosaicFirstRow > static_cast<unsigned int>(mappedY)) prevRasterMosaicFirstRow = static_cast<unsigned int>(mappedY);
860  }
861  }
862 
863  // updating the mosaic related polygons
864 
865  {
866  // building a polygon of the blended raster over the mosaic (world coods)
867 
868  te::gm::Polygon lastMosaicAddedRasterPol( 0, te::gm::PolygonType, 0 ); //the polygon of the last added raster (mosaic world coords)
869  lastMosaicAddedRasterPol.push_back( new te::gm::LinearRing(
870  inRasterDetailedExtent ) );
871  lastMosaicAddedRasterPol.setSRID( mosaicRasterHandler->getSRID() );
872 
873  // union of the current raster box with the current mosaic valid area under the mosaic SRID
874 
875  std::unique_ptr< te::gm::Geometry > unionMultiPolPtr(
876  mosaicValidAreaPols.Union( &lastMosaicAddedRasterPol ) );
877  TERP_TRUE_OR_THROW( unionMultiPolPtr.get(), "Invalid pointer" );
878  unionMultiPolPtr->setSRID( mosaicRasterHandler->getSRID() );
879 
880  if(
881  ( unionMultiPolPtr->getGeomTypeId() == te::gm::MultiPolygonType )
882  ||
883  ( unionMultiPolPtr->getGeomTypeId() == te::gm::MultiPolygonZType )
884  ||
885  ( unionMultiPolPtr->getGeomTypeId() == te::gm::MultiPolygonMType )
886  ||
887  ( unionMultiPolPtr->getGeomTypeId() == te::gm::MultiPolygonZMType )
888  )
889  {
890  mosaicValidAreaPols = *( (te::gm::MultiPolygon*)unionMultiPolPtr.get() );
891  }
892  else if(
893  ( unionMultiPolPtr->getGeomTypeId() == te::gm::PolygonType )
894  ||
895  ( unionMultiPolPtr->getGeomTypeId() == te::gm::PolygonZType )
896  ||
897  ( unionMultiPolPtr->getGeomTypeId() == te::gm::PolygonMType )
898  ||
899  ( unionMultiPolPtr->getGeomTypeId() == te::gm::PolygonZMType )
900  )
901  {
902  mosaicValidAreaPols.clear();
903  mosaicValidAreaPols.setSRID( unionMultiPolPtr->getSRID() );
904  mosaicValidAreaPols.add( (te::gm::Polygon*)unionMultiPolPtr.release() );
905  }
906  else
907  {
908  TERP_LOGWARN( "Invalid union geometry type" );
909  }
910  }
911 
912  // Move to the next raster
913 
914  cachedInputRasterPtr.reset();
915 
917 
919  {
920  progressPtr->pulse();
921  if( ! progressPtr->isActive() ) return false;
922  }
923  }
924  }
925  }
926 
927  if( mosaicRasterHandler.get() )
928  {
929  // Saving the mosaic sequence info
930 
931  currentMosaicSquenceInfo.m_dataSetName = m_inputParameters.m_outDataSetsNamePrefix +
932  boost::lexical_cast< std::string >( outParamsPtr->m_sequencesInfo.size() ) +
934 
935  outParamsPtr->m_sequencesInfo.push_back( currentMosaicSquenceInfo );
936 
938  currentMosaicSquenceInfo.m_dataSetName,
939  *( mosaicRasterHandler.get() ), outParamsPtr->m_outputDSPtr ),
940  "Data set creation error" );
941 
942  currentMosaicSquenceInfo.clear();
943  }
944 
945  return true;
946  }
947 
948  void SequenceMosaic::reset() throw( te::rp::Exception )
949  {
951 
953  m_isInitialized = false;
954  }
955 
957  throw( te::rp::Exception )
958  {
959  reset();
960 
961  SequenceMosaic::InputParameters const* inputParamsPtr = dynamic_cast<
962  SequenceMosaic::InputParameters const* >( &inputParams );
963  TERP_TRUE_OR_THROW( inputParamsPtr, "Invalid paramters pointer" );
964 
965  m_inputParameters = *inputParamsPtr;
966 
967  // Checking the feeder
968 
970  "Invalid m_feederRasterPtr" )
971 
974  "Invalid number of rasters" )
975 
976  // checking m_inputRastersBands
977 
979  ((unsigned int)m_inputParameters.m_inputRastersBands.size()) ==
981  "Bands mismatch" );
982 
984 
985  for( std::vector< std::vector< unsigned int > >::size_type
986  inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
987  m_inputParameters.m_inputRastersBands.size() ; ++inputRastersBandsIdx )
988  {
990  != nullptr, "Invalid raster" )
991 
993  inputRastersBandsIdx ].size() > 0, "Invalid bands number" );
994 
996  inputRastersBandsIdx ].size() == m_inputParameters.m_inputRastersBands[
997  0 ].size(), "Bands number mismatch" );
998 
999  for( std::vector< unsigned int >::size_type currRasterBandidx = 0 ;
1000  currRasterBandidx < m_inputParameters.m_inputRastersBands[
1001  inputRastersBandsIdx ].size() ; ++currRasterBandidx )
1002  {
1004  inputRastersBandsIdx ][ currRasterBandidx ] <
1006  "Invalid band index" );
1007 
1009  m_inputParameters.m_inputRastersBands[ inputRastersBandsIdx ].size(),
1010  "Invalid parameter m_tiePointsLocationBandIndex" );
1011  }
1012 
1014  }
1015 
1019  "Invalid parameter m_minRequiredTiePointsCoveredAreaPercent" );
1020 
1021  m_isInitialized = true;
1022 
1023  return true;
1024  }
1025 
1027  {
1028  return m_isInitialized;
1029  }
1030 
1032  const bool& forceNoDataValue,
1033  const double& noDataValue,
1034  double& mean, double& variance )
1035  {
1036  mean = 0;
1037  variance = 0;
1038 
1039  double internalNoDataValue = 0;
1040  if( forceNoDataValue )
1041  internalNoDataValue = noDataValue;
1042  else
1043  internalNoDataValue = band.getProperty()->m_noDataValue;
1044 
1045  const unsigned int nCols = band.getProperty()->m_blkw *
1046  band.getProperty()->m_nblocksx;
1047  const unsigned int nLines = band.getProperty()->m_blkh *
1048  band.getProperty()->m_nblocksy;
1049 
1050  double pixelsNumber = 0;
1051  double value = 0;
1052  unsigned int col = 0;
1053  unsigned int line = 0;
1054 
1055  for( line = 0 ; line < nLines ; ++line )
1056  for( col = 0 ; col < nCols ; ++col )
1057  {
1058  band.getValue( col, line, value );
1059 
1060  if( value != internalNoDataValue )
1061  {
1062  mean += value;
1063  ++pixelsNumber;
1064  }
1065  }
1066 
1067  if( pixelsNumber != 0.0 )
1068  {
1069  mean /= pixelsNumber;
1070 
1071  for( line = 0 ; line < nLines ; ++line )
1072  for( col = 0 ; col < nCols ; ++col )
1073  {
1074  band.getValue( col, line, value );
1075 
1076  if( value != internalNoDataValue )
1077  {
1078  variance += ( ( value - mean ) * ( value - mean ) ) / pixelsNumber;
1079  }
1080  }
1081 
1082  }
1083  }
1084 
1085  bool SequenceMosaic::createRasterDataSet( const std::string& dataSetName,
1086  const te::rst::Raster& sourceRaster, te::da::DataSource* dataSourcePtr ) const
1087  {
1088  if( dataSetName.empty() ) return false;
1089  if( ! ( sourceRaster.getAccessPolicy() & te::common::RAccess ) ) return false;
1090  if( dataSourcePtr == nullptr ) return false;
1091  if( ! dataSourcePtr->isValid() ) return false;
1092 
1093  const unsigned int nRows = sourceRaster.getNumberOfRows();
1094  const unsigned int nCols = sourceRaster.getNumberOfColumns();
1095  const unsigned int nBands = static_cast<unsigned int>(sourceRaster.getNumberOfBands());
1096 
1097  std::vector< te::rst::BandProperty* > bandsProperties;
1098  unsigned int bandIdx = 0;
1099  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1100  {
1101  bandsProperties.push_back( new te::rst::BandProperty(
1102  *( sourceRaster.getBand( bandIdx )->getProperty()) ) );
1103  }
1104 
1105  te::rp::RasterHandler outRasterHandler;
1106  if( ! te::rp::CreateNewRaster( *( sourceRaster.getGrid() ),
1107  bandsProperties, dataSetName, *dataSourcePtr, outRasterHandler) )
1108  return false;
1109 
1110  unsigned int col = 0;
1111  unsigned int row = 0;
1112  double value = 0;
1113 
1114  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1115  {
1116  const te::rst::Band& inBand = *(sourceRaster.getBand( bandIdx ));
1117  te::rst::Band& outBand = *(outRasterHandler.getRasterPtr()->getBand( bandIdx ));
1118 
1119  for( row = 0 ; row < nRows ; ++row )
1120  {
1121  for( col = 0 ; col < nCols ; ++col )
1122  {
1123  inBand.getValue( col, row, value );
1124  outBand.setValue( col, row, value );
1125  }
1126  }
1127  }
1128 
1129  return true;
1130  }
1131 
1132  bool SequenceMosaic::createDiskRasterCopy( const std::string& fileName,
1133  const te::rst::Raster& sourceRaster ) const
1134  {
1135  std::map<std::string, std::string> rInfo;
1136  rInfo["URI"] = fileName;
1137 
1138  const unsigned int nBands = static_cast<unsigned int>(sourceRaster.getNumberOfBands());
1139 
1140  std::vector<te::rst::BandProperty*> bandsProperties;
1141  unsigned int bandIdx = 0;
1142  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1143  bandsProperties.push_back(new te::rst::BandProperty(
1144  *sourceRaster.getBand( bandIdx )->getProperty() ) );
1145 
1146  te::rst::Grid* newgrid = new te::rst::Grid( *sourceRaster.getGrid() );
1147 
1148  std::unique_ptr< te::rst::Raster > outputRasterPtr(
1149  te::rst::RasterFactory::make( "GDAL", newgrid, bandsProperties, rInfo, nullptr, nullptr));
1150  if( outputRasterPtr.get() == nullptr ) return false;
1151 
1152  unsigned int line = 0;
1153  unsigned int col = 0;
1154  const unsigned int nLines = sourceRaster.getNumberOfRows();
1155  const unsigned int nCols = sourceRaster.getNumberOfColumns();
1156 
1157  double value = 0;
1158 
1159  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1160  {
1161  const te::rst::Band& inBand = *sourceRaster.getBand( bandIdx );
1162  te::rst::Band& outBand = *outputRasterPtr->getBand( bandIdx );
1163 
1164  for( line = 0 ; line < nLines ; ++line )
1165  for( col = 0 ; col < nCols ; ++col )
1166  {
1167  inBand.getValue( col, line, value );
1168  outBand.setValue( col, line, value );
1169  }
1170  }
1171 
1172  return true;
1173  }
1174 
1175  } // end namespace rp
1176 } // end namespace te
1177 
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
void add(Curve *ring)
It adds the ring to the curve polygon.
virtual bool isValid() const =0
It checks if the data source is valid (available for using).
void push_back(Curve *ring)
It adds the curve to the curve polygon.
bool createDiskRasterCopy(const std::string &fileName, const te::rst::Raster &sourceRaster) const
Create copy of the given raster into a disk file.
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
unsigned int band
Near neighborhood interpolation method.
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
The generated tie-points (te::gm::GTParameters::TiePoint::first are raster 1 line/column indexes...
bool m_useRasterCache
Enable(true) or disable the use of raster caching (default:true).
std::vector< TiePoint > m_tiePoints
Tie points.
Definition: GTParameters.h:95
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
Index into a lookup table.
std::vector< unsigned int > m_inRaster2Bands
Bands to be used from the input raster 2.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
void setSRID(int srid)
It sets the Spatial Reference System ID of the geometry and all its parts if it is a GeometryCollecti...
bool m_enableProgress
Enable/Disable the progress interface (default:false).
unsigned int m_raster2TargetAreaLineStart
The first line of the raster 2 target area to process (default:0 - The entire raster will be consider...
A raster band description.
Definition: BandProperty.h:61
Blended pixel value calculation for two overlaped rasters.
Definition: Blender.h:58
Base exception class for plugin module.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
int m_nblocksx
The number of blocks in x.
Definition: BandProperty.h:145
double GetTPConvexHullArea(const ContainerT &tiePoints, const bool useTPSecondCoordPair)
Returns the tie points converx hull area.
static void calcBandStatistics(const te::rst::Band &band, const bool &forceNoDataValue, const double &noDataValue, double &mean, double &variance)
Raster band statistics calcule.
int m_nblocksy
The number of blocks in y.
Definition: BandProperty.h:146
std::vector< std::vector< te::gm::GTParameters::TiePoint > > m_tiePoints
The generated tie-pionts (te::gm::GTParameters::TiePoint::first are mosaic coods, te::gm::GTParameter...
te::rst::Raster const * m_inRaster2Ptr
Input raster 2.
te::rp::TiePointsLocator::InputParameters m_locatorParams
The parameters used by the tie-points locator when processing each rasters pair (leave untouched to u...
#define TERP_LOGWARN(message)
Logs a warning message.
Definition: Macros.h:128
bool m_enableProgress
Enable/Disable the progress interface (default:false).
bool m_enableMultiThread
Enable/Disable the use of multi-threads (default:true).
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
Raster Processing algorithm output parameters base interface.
double pixelValue
te::rp::Blender::BlendMethod m_blendMethod
The pixel blending method (default: NoBlendMethod).
std::string m_outDataSetsNamePrefix
The raster output data sets names prefix.
double m_noDataValue
The pixel value used where no raster data is avaliable (defaul:0).
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
Definition: BandProperty.h:136
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
virtual te::rst::Raster const * getCurrentObj() const =0
Return the current sequence object.
virtual Geometry * Union(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set union with another geometry.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
std::vector< MosaicSequenceInfo > m_sequencesInfo
No blending performed.
Definition: Blender.h:66
std::vector< std::vector< unsigned int > > m_inputRastersBands
Bands to process for each input raster.
const double & getY(std::size_t i) const
It returns the n-th y coordinate value.
bool blendIntoRaster1()
Execute blending of the given input rasters and write the result into raster1.
Definition: Blender.cpp:1351
double getResolutionY() const
Returns the grid vertical (y-axis) resolution.
unsigned int line
std::unique_ptr< te::gm::GeometricTransformation > m_transformationPtr
The generated geometric transformation with the base mininum required tie-points set ( depending on t...
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
const InputParameters & operator=(const InputParameters &params)
unsigned int unsigned int nCols
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
TECOMMONEXPORT unsigned int GetPhysProcNumber()
Returns the number of physical processors.
unsigned int m_raster1TargetAreaHeight
The raster 1 target area height (default:0 - The entire raster will be considered).
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
virtual void reset()=0
Reset the feeder to the first position (subsequent accesses will start from the first sequence obejct...
An Envelope defines a 2D rectangular region.
double m_pixelSizeXRelation
The pixel resolution relation m_pixelSizeXRelation = raster1_pixel_res_x / raster2_pixel_res_x (defau...
An abstract class for raster data strucutures.
void clear()
It deletes all the elements of the collection.
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.
bool m_enableGeometryFilter
Enable/disable the geometry filter/outliers remotion (default:true).
const double & getX(std::size_t i) const
It returns the n-th x coordinate value.
std::vector< unsigned int > m_inRaster1Bands
Bands to be used from the input raster 1.
BandProperty * getProperty()
Returns the band property.
URI C++ Library.
Definition: Attributes.h:37
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
SequenceMosaic::InputParameters m_inputParameters
Input execution parameters.
const OutputParameters & operator=(const OutputParameters &params)
Create mosaics from a sequence of overlapped rasters using an automatic tie-points detection method...
bool m_autoEqualize
Auto equalization will be performed using the overlaped image areas (default:true).
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
double getResolutionX() const
Returns the grid horizontal (x-axis) resolution.
Raster tuple.
double m_minRequiredTiePointsCoveredAreaPercent
The mininumum required tie-points covered area percent of each raster area - valid range [0...
A RAM cache adaptor to an external existent raster that must always be avaliable. ...
Definition: CachedRaster.h:52
RasterHandler.
Definition: RasterHandler.h:47
std::string m_outDataSetsNameSufix
The raster output data sets names sufix.
std::vector< unsigned int > m_rasterFeederIndexes
The indexes (inside the input rasters feeder) of the rasters written to this mosaic sequence...
A raster band description.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
Grid * getGrid()
It returns the raster grid.
#define SEQUENCE_RASTER_MAX_MOSAIC_MEM_USE
TiePointsLocator output parameters.
bool initialize(te::rst::Raster &raster1, const std::vector< unsigned int > &raster1Bands, const te::rst::Raster &raster2, const std::vector< unsigned int > &raster2Bands, const BlendMethod &blendMethod, const te::rst::Interpolator::Method &interpMethod1, const te::rst::Interpolator::Method &interpMethod2, const double &noDataValue, const bool forceRaster1NoDataValue, const bool forceRaster2NoDataValue, const std::vector< double > &pixelOffsets1, const std::vector< double > &pixelScales1, const std::vector< double > &pixelOffsets2, const std::vector< double > &pixelScales2, te::gm::MultiPolygon const *const r1ValidDataDelimiterPtr, te::gm::MultiPolygon const *const r2ValidDataDelimiterPtr, const te::gm::GeometricTransformation &geomTransformation, const unsigned int threadsNumber, const bool enableProgressInterface)
Inititate the blender instance.
Definition: Blender.cpp:178
te::rst::Raster const * m_inRaster1Ptr
Input raster 1.
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
bool CreateNewRaster(const te::rst::Grid &rasterGrid, const std::vector< te::rst::BandProperty * > &bandsProperties, const std::string &outDataSetName, const std::string &dataSourceType, RasterHandler &outRasterHandler)
Create a new raster into the givem data source.
bool m_forceInputNoDataValue
If true, m_noDataValue will be used as the no-data value for input rasters (defalt:false).
Tie points locator.
Abstract parameters base interface.
int getSRID() const
Returns the raster spatial reference system identifier.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
void setSRID(int srid)
It sets the Spatial Reference System ID of the geometry collection and all its parts.
unsigned int m_raster1TargetAreaWidth
The raster 1 target area width (default:0 - The entire raster will be considered).
double m_pixelSizeYRelation
The pixel resolution relation m_pixelSizeYRelation = raster1_pixel_res_y / raster2_pixel_res_y (defau...
unsigned int m_raster1TargetAreaLineStart
The first line of the raster 1 target area to process (default:0 - The entire raster will be consider...
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
unsigned int m_raster2TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
unsigned int m_raster2TargetAreaHeight
The raster 2 target area height (default:0 - The entire raster will be considered).
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
std::string m_dataSetName
The generated data set name for this mosaic sequence.
void add(Geometry *g)
It adds the geometry into the collection.
bool m_enableMultiThread
Enable/Disable the use of multi-threads (default:true).
bool m_isInitialized
Tells if this instance is initialized.
static Raster * make()
It creates and returns an empty raster with default raster driver.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
bool GetIndexedDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &indexedDetailedExtent)
Create a indexed (lines,columns) datailed extent from the given grid.
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
void setSRID(int srid)
It sets the Spatial Reference System ID of the linestring.
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
te::rst::Raster const * m_inMaskRaster1Ptr
Optional one band input mask raster 1 (tie-points will not be generated inside mask image areas marke...
Raster Processing algorithm input parameters base interface.
te::rst::Raster const * m_inMaskRaster2Ptr
Optional one band input mask raster 2 (tie-points will not be generated inside mask image areas marke...
te::rst::Raster * getRasterPtr()
Returns a pointer the the handled raster instance or NULL if no instance is handled.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
2D Geometric transformation parameters.
Definition: GTParameters.h:50
std::string m_geomTransfName
The name of the geometric transformation used to ensure tie-points consistency (see each te::gm::GTFa...
Raster Processing functions.
virtual bool moveNext()=0
Advances to the next sequence obeject.
AbstractParameters * clone() const
Create a clone copy of this instance.
int m_blkh
Block height (pixels).
Definition: BandProperty.h:144
virtual void reset() _NOEXCEPT_OP(false)
Clear all internal allocated objects and reset the algorithm to its initial state.
std::string m_geomTransfName
The name of the geometric transformation used if tie-points are supplied (see each te::gm::GTFactory ...
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
ColorInterp m_colorInterp
The color interpretation.
Definition: BandProperty.h:140
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
FeederConstRaster * m_feederRasterPtr
Input rasters feeder.
#define TERP_INSTANCE_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged, the current instance erro...
Definition: Macros.h:200
unsigned int nLines
void clear()
Clear the internal allocated resources.
unsigned int m_raster1TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
unsigned int m_raster2TargetAreaWidth
The raster 2 target area width (default:0 - The entire raster will be considered).
unsigned int col
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
Definition: Macros.h:150
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
std::size_t size() const
It returns the number of points (vertexes) in the geometry.
Definition: LineString.h:262
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
virtual unsigned int getCurrentOffset() const =0
Return the index of the current object.
AbstractParameters * clone() const
Create a clone copy of this instance.
virtual unsigned int getObjsCount() const =0
Return the total number of feeder objects.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
bool createRasterDataSet(const std::string &dataSetName, const te::rst::Raster &sourceRaster, te::da::DataSource *dataSourcePtr) const
Create a raster data set from the given raster.
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
unsigned int m_tiePointsLocationBandIndex
The band used to locate tie-points, this is the index inside each vector of m_inputRastersBands (defa...
te::da::DataSource * m_outputDSPtr
The mosaic sequences info.