All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
74  void SequenceMosaic::InputParameters::reset() throw( te::rp::Exception )
75  {
76  m_feederRasterPtr = 0;
77  m_inputRastersBands.clear();
78  m_geomTransfName = "Affine";
79  m_interpMethod = te::rst::NearestNeighbor;
80  m_noDataValue = 0.0;
81  m_forceInputNoDataValue = false;
82  m_blendMethod = te::rp::Blender::NoBlendMethod;
83  m_autoEqualize = true;
84  m_useRasterCache = true;
85  m_enableMultiThread = true;
86  m_enableProgress = false;
87  m_tiePointsLocationBandIndex = 0;
88  m_outDataSetsNamePrefix.clear();
89  m_outDataSetsNameSufix.clear();
90  m_minRequiredTiePointsCoveredAreaPercent = 25.0;
91  m_locatorParams.reset();
92  }
93 
95  const SequenceMosaic::InputParameters& params )
96  {
97  reset();
98 
99  m_feederRasterPtr = params.m_feederRasterPtr;
100  m_inputRastersBands = params.m_inputRastersBands;
101  m_geomTransfName = params.m_geomTransfName;
102  m_interpMethod = params.m_interpMethod;
103  m_noDataValue = params.m_noDataValue;
104  m_forceInputNoDataValue = params.m_forceInputNoDataValue;
105  m_blendMethod = params.m_blendMethod;
106  m_autoEqualize = params.m_autoEqualize;
107  m_useRasterCache = params.m_useRasterCache;
108  m_enableMultiThread = params.m_enableMultiThread;
109  m_enableProgress = params.m_enableProgress;
110  m_tiePointsLocationBandIndex = params.m_tiePointsLocationBandIndex;
111  m_outDataSetsNamePrefix = params.m_outDataSetsNamePrefix;
112  m_outDataSetsNameSufix = params.m_outDataSetsNameSufix;
113  m_minRequiredTiePointsCoveredAreaPercent =
115  m_locatorParams = params.m_locatorParams;
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 
143  void SequenceMosaic::OutputParameters::reset() throw( te::rp::Exception )
144  {
145  m_outputDSPtr = 0;
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  {
169  }
170 
172  {
173  }
174 
176  {
177  m_dataSetName.clear();
178  m_rasterFeederIndexes.clear();
179  m_tiePoints.clear();
180  }
181 
182  // ----------------------------------------------------------------------
183 
185  {
186  reset();
187  }
188 
190  {
191  }
192 
194  throw( te::rp::Exception )
195  {
196  if( ! m_isInitialized ) return false;
197 
198  SequenceMosaic::OutputParameters* outParamsPtr = dynamic_cast<
199  SequenceMosaic::OutputParameters* >( &outputParams );
200  TERP_TRUE_OR_THROW( outParamsPtr, "Invalid paramters" );
201 
203  "Invalid data source" );
205  "Invalid data source" );
206 
207  outParamsPtr->m_sequencesInfo.clear();
208 
209  // progress
210 
211  std::auto_ptr< te::common::TaskProgress > progressPtr;
213  {
214  progressPtr.reset( new te::common::TaskProgress );
215 
216  progressPtr->setTotalSteps( m_inputParameters.m_feederRasterPtr->getObjsCount() );
217 
218  progressPtr->setMessage( "Mosaicking" );
219  }
220 
221  // iterating over all rasters
222 
223  const std::vector< double > dummyRasterOffsets( m_inputParameters.m_inputRastersBands[ 0 ].size(), 0.0 );
224  const std::vector< double > dummyRasterScales( m_inputParameters.m_inputRastersBands[ 0 ].size(), 1.0 );
225 
226  std::vector< unsigned int > dummyRasterBandsIndexes;
227  {
228  for( unsigned int bandIdx = 0 ; bandIdx <
229  m_inputParameters.m_inputRastersBands[ 0 ].size(); ++bandIdx )
230  dummyRasterBandsIndexes.push_back( bandIdx );
231  }
232 
233  std::auto_ptr< te::mem::ExpansibleRaster > mosaicRasterHandler;
234  std::vector< double > mosaicTargetMeans;
235  std::vector< double > mosaicTargetVariances;
236  te::gm::MultiPolygon mosaicValidAreaPols( 0, te::gm::MultiPolygonType, 0 ); // the polygons delimiting the valid data inside the mosaic (mosaic world coods)
237  std::vector< double > mosaicBandsRangeMin;
238  std::vector< double > mosaicBandsRangeMax;
239  unsigned int prevRasterMosaicFirstCol = 0; // The last raster added to the mosaic position
240  unsigned int prevRasterMosaicFirstRow = 0; // The last raster added to the mosaic position
241  unsigned int prevRasterMosaicLastCol = 0; // The last raster added to the mosaic position
242  unsigned int prevRasterMosaicLastRow = 0; // The last raster added to the mosaic position
243  MosaicSequenceInfo currentMosaicSquenceInfo;
244 
247  {
248  const unsigned int inputRasterIdx =
250 
251  te::rst::Raster const* inputRasterPtr =
253 
254  std::auto_ptr< te::mem::CachedRaster > cachedInputRasterPtr;
256  {
257  cachedInputRasterPtr.reset( new te::mem::CachedRaster(
260  inputRasterPtr = cachedInputRasterPtr.get();
261  }
262 
263  // saving the current mosaic (debug purposes)
264 
265 // if( mosaicRasterHandler.get() )
266 // {
267 // if( ! createDiskRasterCopy( "Mosaic_" +
268 // boost::lexical_cast< std::string >( inputRasterIdx - 1 ) + ".tif",
269 // *mosaicRasterHandler ) )
270 // {
271 // return false;
272 // }
273 // }
274 
275  // Mosaicking
276 
277  if( mosaicRasterHandler.get() == 0 )
278  {
279  // calculating the initial mosaic blocking scheme
280 
281  unsigned int mosaicNBlocksX = 4;
282  unsigned int mosaicNBlocksY = 4;
284  {
285  const unsigned int nProc = te::common::GetPhysProcNumber();
286 
287  if( ( mosaicNBlocksX * mosaicNBlocksY ) < nProc )
288  {
289  mosaicNBlocksX = mosaicNBlocksY = (unsigned int)std::ceil(
290  std::sqrt( (double)nProc ) );
291  }
292  }
293 
294  unsigned int mosaicBlockW = (unsigned int)std::ceil( ((double) inputRasterPtr->getNumberOfColumns())
295  / ((double)mosaicNBlocksX) );
296  unsigned int mosaicBlockH = (unsigned int)std::ceil( ((double)inputRasterPtr->getNumberOfRows())
297  / ((double)mosaicNBlocksY ) );
298 
299  unsigned int mosaicNCols = mosaicBlockW * mosaicNBlocksX;
300  unsigned int mosaicNRows = mosaicBlockH * mosaicNBlocksY;
301 
302  // creating the raster mosaic
303 
304  std::vector< te::rst::BandProperty* > bandsProperties;
305 
306  for( std::vector< unsigned int >::size_type inputRastersBandsIdx = 0 ;
307  inputRastersBandsIdx < m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size() ;
308  ++inputRastersBandsIdx )
309  {
310  te::rst::BandProperty const* const inBandPropPtr =
312  inputRasterIdx ][ inputRastersBandsIdx ] )->getProperty();
313 
314  bandsProperties.push_back( new te::rst::BandProperty( *inBandPropPtr ) );
315  bandsProperties[ inputRastersBandsIdx ]->m_colorInterp = te::rst::GrayIdxCInt;
316  bandsProperties[ inputRastersBandsIdx ]->m_noDataValue = m_inputParameters.m_noDataValue;
317  bandsProperties[ inputRastersBandsIdx ]->m_blkw = mosaicBlockW;
318  bandsProperties[ inputRastersBandsIdx ]->m_blkh = mosaicBlockH;
319  bandsProperties[ inputRastersBandsIdx ]->m_nblocksx = mosaicNBlocksX;
320  bandsProperties[ inputRastersBandsIdx ]->m_nblocksy = mosaicNBlocksY;
321  }
322 
323  te::gm::Coord2D uLC( inputRasterPtr->getGrid()->getExtent()->getLowerLeftX(),
324  inputRasterPtr->getGrid()->getExtent()->getUpperRightY() );
325 
326  te::rst::Grid* mosaicGridPtr = new te::rst::Grid(
327  mosaicNCols,
328  mosaicNRows,
329  inputRasterPtr->getGrid()->getResolutionX(),
330  inputRasterPtr->getGrid()->getResolutionY(),
331  &uLC,
332  inputRasterPtr->getSRID() );
333 
334  mosaicRasterHandler.reset(
336  mosaicGridPtr,
337  bandsProperties ) );
338  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler.get(),
339  "Output raster creation error" );
340 
341  // updating the global mosaic variables
342 
343  mosaicBandsRangeMin.resize(
344  mosaicRasterHandler->getNumberOfBands(), 0 );
345  mosaicBandsRangeMax.resize(
346  mosaicRasterHandler->getNumberOfBands(), 0 );
347  for( unsigned int mosaicBandidx = 0 ; mosaicBandidx <
348  mosaicRasterHandler->getNumberOfBands() ; ++mosaicBandidx )
349  {
351  mosaicRasterHandler->getBand( mosaicBandidx )->getProperty()->m_type,
352  mosaicBandsRangeMin[ mosaicBandidx ],
353  mosaicBandsRangeMax[ mosaicBandidx ]);
354  }
355 
356  prevRasterMosaicFirstCol = 0;
357  prevRasterMosaicLastRow = inputRasterPtr->getNumberOfRows() - 1;
358  prevRasterMosaicLastCol = inputRasterPtr->getNumberOfColumns() - 1;
359  prevRasterMosaicFirstRow = 0;
360 
361  const double& mosaicLLX = mosaicRasterHandler->getGrid()->getExtent()->m_llx;
362  const double& mosaicLLY = mosaicRasterHandler->getGrid()->getExtent()->m_lly;
363  const double& mosaicURX = mosaicRasterHandler->getGrid()->getExtent()->m_urx;
364  const double& mosaicURY = mosaicRasterHandler->getGrid()->getExtent()->m_ury;
365 
367  auxLinearRingPtr->setPoint( 0, mosaicLLX, mosaicURY );
368  auxLinearRingPtr->setPoint( 1, mosaicURX, mosaicURY );
369  auxLinearRingPtr->setPoint( 2, mosaicURX, mosaicLLY );
370  auxLinearRingPtr->setPoint( 3, mosaicLLX, mosaicLLY );
371  auxLinearRingPtr->setPoint( 4, mosaicLLX, mosaicURY );
372  auxLinearRingPtr->setSRID( mosaicRasterHandler->getGrid()->getSRID() );
373 
375  mosaicRasterHandler->getGrid()->getSRID(), 0 );
376  outPolPtr->add( auxLinearRingPtr );
377 
378  mosaicValidAreaPols.clear();
379  mosaicValidAreaPols.add( outPolPtr );
380  mosaicValidAreaPols.setSRID( mosaicRasterHandler->getGrid()->getSRID() );
381 
382  // fill the output mosaic raster
383 
384  {
385  const unsigned int nBands = mosaicRasterHandler->getNumberOfBands();
386  const unsigned int inputRasterNRows = inputRasterPtr->getNumberOfRows();
387  const unsigned int inputRasterNCols = inputRasterPtr->getNumberOfColumns();
388  const unsigned int mosaicNRows = mosaicRasterHandler->getNumberOfRows();
389  const unsigned int mosaicNCols = mosaicRasterHandler->getNumberOfColumns();
390  unsigned int validPixelsNumber = 0;
391  unsigned int outCol = 0;
392  unsigned int outRow = 0;
393  double pixelValue = 0;
394 
395  mosaicTargetMeans.resize( nBands, 0.0 );
396  mosaicTargetVariances.resize( nBands, 0.0 );
397 
398  for( unsigned int inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
399  nBands ; ++inputRastersBandsIdx )
400  {
401  const unsigned int inputBandIdx =
402  m_inputParameters.m_inputRastersBands[ inputRasterIdx ][ inputRastersBandsIdx ] ;
403  te::rst::Band& outBand =
404  (*mosaicRasterHandler->getBand( inputRastersBandsIdx ));
405  const te::rst::Band& inBand =
406  (*inputRasterPtr->getBand( inputBandIdx ));
407  const double& inputBandNoDataValue = m_inputParameters.m_forceInputNoDataValue ?
408  m_inputParameters.m_noDataValue : inputRasterPtr->getBand( inputBandIdx
410  const double& outputBandNoDataValue = outBand.getProperty()->m_noDataValue;
411 
412  double& mean = mosaicTargetMeans[ inputRastersBandsIdx ];
413  mean = 0;
414 
415  for( outRow = 0 ; outRow < mosaicNRows ; ++outRow )
416  {
417  for( outCol = 0 ; outCol < mosaicNCols ; ++outCol )
418  {
419  if( ( outRow < inputRasterNRows ) && ( outCol < inputRasterNCols ) )
420  {
421  inBand.getValue( outCol, outRow, pixelValue );
422 
423  if( pixelValue != inputBandNoDataValue )
424  {
425  outBand.setValue( outCol, outRow, pixelValue );
426 
427  mean += pixelValue;
428  ++validPixelsNumber;
429  }
430  }
431  else
432  {
433  outBand.setValue( outCol, outRow, outputBandNoDataValue );
434  }
435  }
436  }
437 
438  mean /= ( (double)validPixelsNumber );
439 
440  // variance calcule
441 
443  {
444  double& variance = mosaicTargetVariances[ inputRastersBandsIdx ];
445  variance = 0;
446 
447  double pixelValue = 0;
448 
449  for( outRow = 0 ; outRow < inputRasterNRows ; ++outRow )
450  {
451  for( outCol = 0 ; outCol < inputRasterNCols ; ++outCol )
452  {
453  outBand.getValue( outCol, outRow, pixelValue );
454 
455  if( pixelValue != inputBandNoDataValue )
456  {
457  variance += ( ( pixelValue - mean ) * ( pixelValue -
458  mean ) ) / ( (double)validPixelsNumber );
459  }
460  }
461  }
462  }
463  }
464  }
465 
466  // Updating the mosaic sequence info
467 
468  currentMosaicSquenceInfo.m_rasterFeederIndexes.push_back(
469  inputRasterIdx );
470  currentMosaicSquenceInfo.m_tiePoints.push_back(
471  std::vector< te::gm::GTParameters::TiePoint >() );
472 
473  // Move to the next raster
474 
475  cachedInputRasterPtr.reset();
476 
478 
480  {
481  progressPtr->pulse();
482  if( ! progressPtr->isActive() ) return false;
483  }
484  }
485  else
486  {
487  // Locating the tie points where te::gm::GTParameters::TiePoint::first
488  // are :mosaic indexed coods and te::gm::GTParameters::TiePoint::second are
489  // indexed coords from the current raster
490 
492 
493  {
495  locatorInParams = m_inputParameters.m_locatorParams;
496 
497  locatorInParams.m_inRaster1Ptr = mosaicRasterHandler.get();
498 
499  locatorInParams.m_inMaskRaster1Ptr = 0;
500 
501  locatorInParams.m_inRaster1Bands.clear();
502  locatorInParams.m_inRaster1Bands.push_back(
504 
505  locatorInParams.m_raster1TargetAreaColStart = prevRasterMosaicFirstCol;
506  locatorInParams.m_raster1TargetAreaLineStart = prevRasterMosaicFirstRow;
507  locatorInParams.m_raster1TargetAreaWidth = (unsigned int)(
508  prevRasterMosaicLastCol - prevRasterMosaicFirstCol + 1 );
509  locatorInParams.m_raster1TargetAreaHeight = (unsigned int)(
510  prevRasterMosaicLastRow - prevRasterMosaicFirstRow + 1 );
511 
512  locatorInParams.m_inRaster2Ptr = inputRasterPtr;
513 
514  locatorInParams.m_inMaskRaster2Ptr = 0;
515 
516  locatorInParams.m_inRaster2Bands.clear();
517  locatorInParams.m_inRaster2Bands.push_back(
518  m_inputParameters.m_inputRastersBands[ inputRasterIdx ][
520 
521  locatorInParams.m_raster2TargetAreaLineStart = 0;
522  locatorInParams.m_raster2TargetAreaColStart = 0;
523  locatorInParams.m_raster2TargetAreaWidth = 0;
524  locatorInParams.m_raster2TargetAreaHeight = 0;
525 
527 
528  locatorInParams.m_enableProgress = false;
529 
530  if( mosaicRasterHandler->getSRID() == inputRasterPtr->getSRID() )
531  {
532  locatorInParams.m_pixelSizeXRelation = mosaicRasterHandler->getResolutionX() /
533  inputRasterPtr->getResolutionX();
534  locatorInParams.m_pixelSizeYRelation = mosaicRasterHandler->getResolutionY() /
535  inputRasterPtr->getResolutionY();
536  }
537  else
538  {
539  te::gm::Envelope inputRasterExtent( *inputRasterPtr->getGrid()->getExtent() );
540  inputRasterExtent.transform( inputRasterPtr->getSRID(),
541  mosaicRasterHandler->getSRID() );
542 
543  locatorInParams.m_pixelSizeXRelation = mosaicRasterHandler->getResolutionX() /
544  ( inputRasterExtent.getWidth() / ((double)inputRasterPtr->getNumberOfColumns()) );
545  locatorInParams.m_pixelSizeYRelation = mosaicRasterHandler->getResolutionY() /
546  ( inputRasterExtent.getHeight() / ((double)inputRasterPtr->getNumberOfRows()) );
547  }
548 
550 
551  locatorInParams.m_enableGeometryFilter = true;
552 
554 
555  te::rp::TiePointsLocator locatorInstance;
556  TERP_TRUE_OR_RETURN_FALSE( locatorInstance.initialize(
557  locatorInParams ), "Tie points locator init error" );
558  if( ! locatorInstance.execute( locatorOutParams ) )
559  {
560  locatorInParams.reset();
561  }
562  }
563 
564  // The matching was accomplished successfully ?
565 
566  if(
567  ( locatorOutParams.m_transformationPtr.get() == 0 )
568  ||
569  (
570  locatorOutParams.m_tiePoints.size()
571  <
572  (
573  2
574  *
575  locatorOutParams.m_transformationPtr->getMinRequiredTiePoints()
576  )
577  )
578  ||
579  (
580  (
581  te::rp::GetTPConvexHullArea( locatorOutParams.m_tiePoints, true )
582  /
583  (double)(
584  inputRasterPtr->getNumberOfColumns()
585  *
586  inputRasterPtr->getNumberOfRows()
587  )
588  )
589  <
590  (
592  /
593  100.0
594  )
595  )
596  )
597  {
598  // Saving the mosaic sequence info
599 
600  currentMosaicSquenceInfo.m_dataSetName = m_inputParameters.m_outDataSetsNamePrefix +
601  boost::lexical_cast< std::string >( outParamsPtr->m_sequencesInfo.size() ) +
603 
604  outParamsPtr->m_sequencesInfo.push_back( currentMosaicSquenceInfo );
605 
606  // Create the output data set
607 
608  assert( mosaicRasterHandler.get() );
610  currentMosaicSquenceInfo.m_dataSetName,
611  *( mosaicRasterHandler.get() ), outParamsPtr->m_outputDSPtr ),
612  "Data set creation error" );
613  mosaicRasterHandler.reset();
614 
615  currentMosaicSquenceInfo.clear();
616  }
617  else
618  {
619  // Generating the offset and gain info for eath band from the current raster
620 
621  std::vector< double > currentRasterBandsOffsets;
622  std::vector< double > currentRasterBandsScales;
623 
625  {
626  double currentRasterVariance = 0;
627  double currentRasterMean = 0;
628 
629  for( unsigned int inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
630  m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size() ;
631  ++inputRastersBandsIdx )
632  {
633  const unsigned int inputBandIdx = m_inputParameters.m_inputRastersBands[ inputRasterIdx ][
634  inputRastersBandsIdx ];
635 
636  calcBandStatistics( (*inputRasterPtr->getBand( inputBandIdx ) ),
639  currentRasterMean,
640  currentRasterVariance );
641 
642  currentRasterBandsScales.push_back(
643  std::sqrt( mosaicTargetVariances[ inputRastersBandsIdx ] )
644  /
645  std::sqrt( currentRasterVariance ) );
646  currentRasterBandsOffsets.push_back( mosaicTargetMeans[ inputRastersBandsIdx ]
647  - ( currentRasterBandsScales[ inputRastersBandsIdx ] * currentRasterMean ) );
648  }
649  }
650  else
651  {
652  currentRasterBandsOffsets = dummyRasterOffsets;
653  currentRasterBandsScales = dummyRasterScales;
654  }
655 
656  // Updating the mosaic sequence info
657 
658  currentMosaicSquenceInfo.m_tiePoints.push_back(
659  locatorOutParams.m_tiePoints );
660  currentMosaicSquenceInfo.m_rasterFeederIndexes.push_back(
661  inputRasterIdx );
662 
663  // The indexed detailed extent of input raster
664 
665  te::gm::LinearRing inRasterIndexedDetailedExtent( te::gm::LineStringType, 0, 0 );
667  *inputRasterPtr->getGrid(), inRasterIndexedDetailedExtent ),
668  "Error creating the raster detailed extent" );
669 
670  // Expanding the mosaic to fit the extent requirement allowing the
671  // merge of the current raster.
672  // Fiding the new geometric transformation between then.
673 
674  std::auto_ptr< te::gm::GeometricTransformation > geoTransPtr(
675  locatorOutParams.m_transformationPtr->clone() );
676 
677  {
678  // guessing the limits of the new blended raster over the old mosaic
679 
680  double mappedLRX = std::numeric_limits< double >::min();
681  double mappedLRY = std::numeric_limits< double >::min();
682  double mappedULX = std::numeric_limits< double >::max();
683  double mappedULY = std::numeric_limits< double >::max();
684  double mappedX = 0;
685  double mappedY = 0;
686  for( unsigned int inRasterDetExtentIdx = 0 ; inRasterDetExtentIdx <
687  inRasterIndexedDetailedExtent.size() ; ++inRasterDetExtentIdx )
688  {
689  locatorOutParams.m_transformationPtr->inverseMap(
690  inRasterIndexedDetailedExtent.getX( inRasterDetExtentIdx ),
691  inRasterIndexedDetailedExtent.getY( inRasterDetExtentIdx ),
692  mappedX,
693  mappedY);
694 
695  if( mappedLRX < mappedX ) mappedLRX = mappedX;
696  if( mappedLRY < mappedY ) mappedLRY = mappedY;
697  if( mappedULX > mappedX ) mappedULX = mappedX;
698  if( mappedULY > mappedY ) mappedULY = mappedY;
699  }
700 
701  // calc of old reference for future use
702 
703  double oldMosaicReferenceX = 0;
704  double oldMosaicReferenceY = 0;
705  mosaicRasterHandler->getGrid()->gridToGeo( 0.0, 0.0, oldMosaicReferenceX,
706  oldMosaicReferenceY );
707 
708  // expanding
709 
710  double mosaicReferenceHasChanged = false;
711 
712  if( mappedULX < 0.0 )
713  {
714  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addLeftColumns(
715  (unsigned int)std::ceil( -1.0 * mappedULX ) ),
716  "Mosaic expansion error" );
717  mosaicReferenceHasChanged = true;
718  }
719 
720  if( mappedULY < 0.0 )
721  {
722  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addTopLines(
723  (unsigned int)std::ceil( -1.0 * mappedULY ) ),
724  "Mosaic expansion error" );
725  mosaicReferenceHasChanged = true;
726  }
727 
728  if( mappedLRX > ((double)(mosaicRasterHandler->getNumberOfColumns() - 1) ) )
729  {
730  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addRightColumns(
731  (unsigned int)std::ceil( mappedLRX -
732  ((double)(mosaicRasterHandler->getNumberOfColumns() - 1)) ) ),
733  "Mosaic expansion error" );
734  }
735 
736  if( mappedLRY > ((double)(mosaicRasterHandler->getNumberOfRows() - 1) ) )
737  {
738  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addBottomLines(
739  (unsigned int)std::ceil( mappedLRY -
740  ((double)(mosaicRasterHandler->getNumberOfRows() - 1) ) ) ),
741  "Mosaic expansion error" );
742  }
743 
744  // updating the geometric transformation between both rasters
745 
746  if( mosaicReferenceHasChanged )
747  {
748  double expansionOffSetX = 0;
749  double expansionOffSetY = 0;
750  mosaicRasterHandler->getGrid()->geoToGrid( oldMosaicReferenceX,
751  oldMosaicReferenceY, expansionOffSetX, expansionOffSetY );
752 
753  te::gm::GTParameters newTransParams;
754  newTransParams.m_tiePoints =
755  geoTransPtr->getParameters().m_tiePoints;
756 
757  for( unsigned int tpIdx = 0 ; tpIdx <
758  newTransParams.m_tiePoints.size() ; ++tpIdx )
759  {
760  newTransParams.m_tiePoints[ tpIdx ].first.x += expansionOffSetX;
761  newTransParams.m_tiePoints[ tpIdx ].first.y += expansionOffSetY;
762  }
763 
764  TERP_TRUE_OR_RETURN_FALSE( geoTransPtr->initialize( newTransParams ),
765  "Geometric transformation parameters calcule error" );
766  }
767  }
768 
769  // Blending the current raster into the mosaic
770 
771  {
772  te::rp::Blender blenderInstance;
773 
774  TERP_TRUE_OR_RETURN_FALSE( blenderInstance.initialize(
775  *( mosaicRasterHandler.get() ),
776  dummyRasterBandsIndexes,
777  *inputRasterPtr,
778  m_inputParameters.m_inputRastersBands[ inputRasterIdx ],
783  false,
785  dummyRasterOffsets,
786  dummyRasterScales,
787  currentRasterBandsOffsets,
788  currentRasterBandsScales,
789  &mosaicValidAreaPols,
790  0,
791  *geoTransPtr,
793  false ),
794  "Blender initiazing error" );
795 
796  TERP_TRUE_OR_RETURN_FALSE( blenderInstance.blendIntoRaster1(),
797  "Error blending images" );
798  }
799 
800  // The input rasters detailed extent over the expanded mosaic
801 
802  te::gm::LinearRing inRasterDetailedExtent(
803  inRasterIndexedDetailedExtent.size(), te::gm::LineStringType,
804  mosaicRasterHandler->getSRID(), (te::gm::Envelope*)0 );
805 
806  {
807  double mappedX = 0;
808  double mappedY = 0;
809 
810  for( unsigned int inRasterDetExtentIdx = 0 ; inRasterDetExtentIdx <
811  inRasterIndexedDetailedExtent.size() ; ++inRasterDetExtentIdx )
812  {
813  locatorOutParams.m_transformationPtr->inverseMap(
814  inRasterIndexedDetailedExtent.getX( inRasterDetExtentIdx ),
815  inRasterIndexedDetailedExtent.getY( inRasterDetExtentIdx ),
816  mappedX,
817  mappedY);
818 
819  inRasterDetailedExtent.setPoint( inRasterDetExtentIdx, mappedX, mappedY );
820  }
821  }
822 
823  // Updating the info about the position of the last blended raster
824 
825  {
826  prevRasterMosaicLastCol = 0;
827  prevRasterMosaicLastRow = 0;
828  prevRasterMosaicFirstCol = std::numeric_limits< unsigned int >::max();
829  prevRasterMosaicFirstRow = std::numeric_limits< unsigned int >::max();
830 
831  double mappedX = 0;
832  double mappedY = 0;
833  for( unsigned int inRasterDetExtentIdx = 0 ; inRasterDetExtentIdx <
834  inRasterDetailedExtent.size() ; ++inRasterDetExtentIdx )
835  {
836  geoTransPtr->inverseMap(
837  inRasterDetailedExtent.getX( inRasterDetExtentIdx ),
838  inRasterDetailedExtent.getY( inRasterDetExtentIdx ),
839  mappedX,
840  mappedY);
841 
842  mappedX = std::max( mappedX, 0.0 );
843  mappedX = std::min( mappedX,
844  (double)( mosaicRasterHandler->getNumberOfColumns() - 1 ) );
845 
846  mappedY = std::max( mappedY, 0.0 );
847  mappedY = std::min( mappedY,
848  (double)( mosaicRasterHandler->getNumberOfRows() - 1 ) );
849 
850  if( prevRasterMosaicLastCol < mappedX ) prevRasterMosaicLastCol = mappedX;
851  if( prevRasterMosaicLastRow < mappedY ) prevRasterMosaicLastRow = mappedY;
852  if( prevRasterMosaicFirstCol > mappedX ) prevRasterMosaicFirstCol = mappedX;
853  if( prevRasterMosaicFirstRow > mappedY ) prevRasterMosaicFirstRow = mappedY;
854  }
855  }
856 
857  // updating the mosaic related polygons
858 
859  {
860  // building a polygon of the blended raster over the mosaic (world coods)
861 
862  te::gm::Polygon lastMosaicAddedRasterPol( 0, te::gm::PolygonType, 0 ); //the polygon of the last added raster (mosaic world coords)
863  lastMosaicAddedRasterPol.push_back( new te::gm::LinearRing(
864  inRasterDetailedExtent ) );
865  lastMosaicAddedRasterPol.setSRID( mosaicRasterHandler->getSRID() );
866 
867  // union of the current raster box with the current mosaic valid area under the mosaic SRID
868 
869  std::auto_ptr< te::gm::Geometry > unionMultiPolPtr(
870  mosaicValidAreaPols.Union( &lastMosaicAddedRasterPol ) );
871  TERP_TRUE_OR_THROW( unionMultiPolPtr.get(), "Invalid pointer" );
872  unionMultiPolPtr->setSRID( mosaicRasterHandler->getSRID() );
873 
874  if( unionMultiPolPtr->getGeomTypeId() == te::gm::MultiPolygonType )
875  {
876  mosaicValidAreaPols = *( (te::gm::MultiPolygon*)unionMultiPolPtr.get() );
877  }
878  else if( unionMultiPolPtr->getGeomTypeId() == te::gm::PolygonType )
879  {
880  mosaicValidAreaPols.clear();
881  mosaicValidAreaPols.setSRID( unionMultiPolPtr->getSRID() );
882  mosaicValidAreaPols.add( (te::gm::Polygon*)unionMultiPolPtr.release() );
883  }
884  else
885  {
886  TERP_LOG_AND_RETURN_FALSE( "Invalid union geometry type" );
887  }
888  }
889 
890  // Move to the next raster
891 
892  cachedInputRasterPtr.reset();
893 
895 
897  {
898  progressPtr->pulse();
899  if( ! progressPtr->isActive() ) return false;
900  }
901  }
902  }
903  }
904 
905  if( mosaicRasterHandler.get() )
906  {
907  // Saving the mosaic sequence info
908 
909  currentMosaicSquenceInfo.m_dataSetName = m_inputParameters.m_outDataSetsNamePrefix +
910  boost::lexical_cast< std::string >( outParamsPtr->m_sequencesInfo.size() ) +
912 
913  outParamsPtr->m_sequencesInfo.push_back( currentMosaicSquenceInfo );
914 
916  currentMosaicSquenceInfo.m_dataSetName,
917  *( mosaicRasterHandler.get() ), outParamsPtr->m_outputDSPtr ),
918  "Data set creation error" );
919 
920  currentMosaicSquenceInfo.clear();
921  }
922 
923  return true;
924  }
925 
926  void SequenceMosaic::reset() throw( te::rp::Exception )
927  {
929  m_isInitialized = false;
930  }
931 
933  throw( te::rp::Exception )
934  {
935  reset();
936 
937  SequenceMosaic::InputParameters const* inputParamsPtr = dynamic_cast<
938  SequenceMosaic::InputParameters const* >( &inputParams );
939  TERP_TRUE_OR_THROW( inputParamsPtr, "Invalid paramters pointer" );
940 
941  m_inputParameters = *inputParamsPtr;
942 
943  // Checking the feeder
944 
946  "Invalid m_feederRasterPtr" )
947 
950  "Invalid number of rasters" )
951 
952  // checking m_inputRastersBands
953 
955  ((unsigned int)m_inputParameters.m_inputRastersBands.size()) ==
957  "Bands mismatch" );
958 
960 
961  for( std::vector< std::vector< unsigned int > >::size_type
962  inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
963  m_inputParameters.m_inputRastersBands.size() ; ++inputRastersBandsIdx )
964  {
966  != 0, "Invalid raster" )
967 
969  inputRastersBandsIdx ].size() > 0, "Invalid bands number" );
970 
972  inputRastersBandsIdx ].size() == m_inputParameters.m_inputRastersBands[
973  0 ].size(), "Bands number mismatch" );
974 
975  for( std::vector< unsigned int >::size_type currRasterBandidx = 0 ;
976  currRasterBandidx < m_inputParameters.m_inputRastersBands[
977  inputRastersBandsIdx ].size() ; ++currRasterBandidx )
978  {
980  inputRastersBandsIdx ][ currRasterBandidx ] <
982  "Invalid band index" );
983 
985  m_inputParameters.m_inputRastersBands[ inputRastersBandsIdx ].size(),
986  "Invalid parameter m_tiePointsLocationBandIndex" );
987  }
988 
990  }
991 
995  "Invalid parameter m_minRequiredTiePointsCoveredAreaPercent" );
996 
997  m_isInitialized = true;
998 
999  return true;
1000  }
1001 
1003  {
1004  return m_isInitialized;
1005  }
1006 
1008  const bool& forceNoDataValue,
1009  const double& noDataValue,
1010  double& mean, double& variance )
1011  {
1012  mean = 0;
1013  variance = 0;
1014 
1015  double internalNoDataValue = 0;
1016  if( forceNoDataValue )
1017  internalNoDataValue = noDataValue;
1018  else
1019  internalNoDataValue = band.getProperty()->m_noDataValue;
1020 
1021  const unsigned int nCols = band.getProperty()->m_blkw *
1022  band.getProperty()->m_nblocksx;
1023  const unsigned int nLines = band.getProperty()->m_blkh *
1024  band.getProperty()->m_nblocksy;
1025 
1026  double pixelsNumber = 0;
1027  double value = 0;
1028  unsigned int col = 0;
1029  unsigned int line = 0;
1030 
1031  for( line = 0 ; line < nLines ; ++line )
1032  for( col = 0 ; col < nCols ; ++col )
1033  {
1034  band.getValue( col, line, value );
1035 
1036  if( value != internalNoDataValue )
1037  {
1038  mean += value;
1039  ++pixelsNumber;
1040  }
1041  }
1042 
1043  if( pixelsNumber != 0.0 )
1044  {
1045  mean /= pixelsNumber;
1046 
1047  for( line = 0 ; line < nLines ; ++line )
1048  for( col = 0 ; col < nCols ; ++col )
1049  {
1050  band.getValue( col, line, value );
1051 
1052  if( value != internalNoDataValue )
1053  {
1054  variance += ( ( value - mean ) * ( value - mean ) ) / pixelsNumber;
1055  }
1056  }
1057 
1058  }
1059  }
1060 
1061  bool SequenceMosaic::createRasterDataSet( const std::string& dataSetName,
1062  const te::rst::Raster& sourceRaster, te::da::DataSource* dataSourcePtr ) const
1063  {
1064  if( dataSetName.empty() ) return false;
1065  if( ! ( sourceRaster.getAccessPolicy() & te::common::RAccess ) ) return false;
1066  if( dataSourcePtr == 0 ) return false;
1067  if( ! dataSourcePtr->isValid() ) return false;
1068 
1069  const unsigned int nRows = sourceRaster.getNumberOfRows();
1070  const unsigned int nCols = sourceRaster.getNumberOfColumns();
1071  const unsigned int nBands = sourceRaster.getNumberOfBands();
1072 
1073  std::vector< te::rst::BandProperty* > bandsProperties;
1074  unsigned int bandIdx = 0;
1075  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1076  {
1077  bandsProperties.push_back( new te::rst::BandProperty(
1078  *( sourceRaster.getBand( bandIdx )->getProperty()) ) );
1079  }
1080 
1081  te::rp::RasterHandler outRasterHandler;
1082  if( ! te::rp::CreateNewRaster( *( sourceRaster.getGrid() ),
1083  bandsProperties, dataSetName, *dataSourcePtr, outRasterHandler) )
1084  return false;
1085 
1086  unsigned int col = 0;
1087  unsigned int row = 0;
1088  double value = 0;
1089 
1090  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1091  {
1092  const te::rst::Band& inBand = *(sourceRaster.getBand( bandIdx ));
1093  te::rst::Band& outBand = *(outRasterHandler.getRasterPtr()->getBand( bandIdx ));
1094 
1095  for( row = 0 ; row < nRows ; ++row )
1096  {
1097  for( col = 0 ; col < nCols ; ++col )
1098  {
1099  inBand.getValue( col, row, value );
1100  outBand.setValue( col, row, value );
1101  }
1102  }
1103  }
1104 
1105  return true;
1106  }
1107 
1108  bool SequenceMosaic::createDiskRasterCopy( const std::string& fileName,
1109  const te::rst::Raster& sourceRaster ) const
1110  {
1111  std::map<std::string, std::string> rInfo;
1112  rInfo["URI"] = fileName;
1113 
1114  const unsigned int nBands = sourceRaster.getNumberOfBands();
1115 
1116  std::vector<te::rst::BandProperty*> bandsProperties;
1117  unsigned int bandIdx = 0;
1118  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1119  bandsProperties.push_back(new te::rst::BandProperty(
1120  *sourceRaster.getBand( bandIdx )->getProperty() ) );
1121 
1122  te::rst::Grid* newgrid = new te::rst::Grid( *sourceRaster.getGrid() );
1123 
1124  std::auto_ptr< te::rst::Raster > outputRasterPtr(
1125  te::rst::RasterFactory::make( "GDAL", newgrid, bandsProperties, rInfo, 0, 0));
1126  if( outputRasterPtr.get() == 0 ) return false;
1127 
1128  unsigned int line = 0;
1129  unsigned int col = 0;
1130  const unsigned int nLines = sourceRaster.getNumberOfRows();
1131  const unsigned int nCols = sourceRaster.getNumberOfColumns();
1132 
1133  double value = 0;
1134 
1135  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1136  {
1137  const te::rst::Band& inBand = *sourceRaster.getBand( bandIdx );
1138  te::rst::Band& outBand = *outputRasterPtr->getBand( bandIdx );
1139 
1140  for( line = 0 ; line < nLines ; ++line )
1141  for( col = 0 ; col < nCols ; ++col )
1142  {
1143  inBand.getValue( col, line, value );
1144  outBand.setValue( col, line, value );
1145  }
1146  }
1147 
1148  return true;
1149  }
1150 
1151  } // end namespace rp
1152 } // end namespace te
1153 
virtual unsigned int getObjsCount() const =0
Return the total number of feeder objects.
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
void add(Curve *ring)
It adds the ring to the curve polygon.
Definition: CurvePolygon.h:267
void push_back(Curve *ring)
It adds the curve to the curve polygon.
Definition: CurvePolygon.h:279
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
virtual bool isValid() const =0
It checks if the data source is valid (available for using).
Near neighborhood interpolation method.
Definition: Enums.h:95
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.
Definition: Utils.cpp:334
Index into a lookup table.
Definition: Enums.h:57
std::vector< unsigned int > m_inRaster2Bands
Bands to be used from the input raster 2.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
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
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
Definition: Raster.cpp:213
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.
Definition: Functions.h:633
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
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...
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.
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. ...
Definition: DataSource.h:118
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits::max().
Definition: BandProperty.h:136
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:420
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.
Definition: LineString.cpp:391
bool blendIntoRaster1()
Execute blending of the given input rasters and write the result into raster1.
Definition: Blender.cpp:1060
Raster Processing functions.
double getResolutionY() const
Returns the grid vertical (y-axis) resolution.
Definition: Grid.cpp:259
#define TERP_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged and a return of context wi...
Definition: Macros.h:183
const Algorithm & operator=(const Algorithm &)
Definition: Algorithm.cpp:43
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
Definition: Raster.cpp:89
const InputParameters & operator=(const InputParameters &params)
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.
Definition: LineString.cpp:353
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.
Definition: Envelope.h:51
std::auto_ptr< te::gm::GeometricTransformation > m_transformationPtr
The generated geometric transformation with the base mininum required tie-points set ( depending on t...
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.
Definition: Raster.h:71
void clear()
It deletes all the elements of the collection.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
Definition: Raster.cpp:208
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.
Definition: LineString.cpp:385
std::vector< unsigned int > m_inRaster1Bands
Bands to be used from the input raster 1.
BandProperty * getProperty()
Returns the band property.
Definition: Band.cpp:428
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
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.
Definition: Raster.cpp:218
double getResolutionX() const
Returns the grid horizontal (x-axis) resolution.
Definition: Grid.cpp:253
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.
Definition: Band.h:63
Grid * getGrid()
It returns the raster grid.
Definition: Raster.cpp:94
#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:170
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.
Definition: Functions.cpp:119
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.
Definition: Raster.cpp:203
#define TERP_LOG_AND_RETURN_FALSE(message)
Logs a warning message will and return false.
Definition: Macros.h:236
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.
Definition: Envelope.h:390
bool GetIndexedDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &indexedDetailedExtent)
Create a indexed (lines,columns) datailed extent from the given grid.
Definition: Functions.cpp:2298
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.
Definition: Grid.cpp:275
void setSRID(int srid)
It sets the Spatial Reference System ID of the linestring.
Definition: LineString.cpp:176
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
Definition: Raster.cpp:223
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...
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 Geometry * Union(const Geometry *const rhs) const
It returns a geometric object that represents the point set union with another geometry.
Definition: Geometry.cpp:544
virtual te::rst::Raster const * getCurrentObj() const =0
Return the current sequence object.
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: 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.
Definition: Envelope.cpp:92
FeederConstRaster * m_feederRasterPtr
Input rasters feeder.
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).
virtual unsigned int getCurrentOffset() const =0
Return the index of the current object.
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
Definition: Macros.h:149
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
AbstractParameters * clone() const
Create a clone copy of this instance.
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.