27 #include "../../../common/progress/ProgressManager.h" 28 #include "../../../geometry/Envelope.h" 29 #include "../../../dataaccess/dataset/DataSet.h" 30 #include "../../../dataaccess/utils/Utils.h" 31 #include "../../../geometry/Geometry.h" 32 #include "../../../geometry/GeometryCollection.h" 33 #include "../../../raster/Grid.h" 34 #include "../../../raster/Interpolator.h" 35 #include "../../../raster/PositionIterator.h" 36 #include "../../../raster/Raster.h" 37 #include "../../../raster/RasterFactory.h" 38 #include "../../../raster/Utils.h" 39 #include "../../../maptools/Utils.h" 40 #include "../../../rp/Module.h" 41 #include "../help/HelpPushButton.h" 42 #include "../layer/search/LayerSearchWidget.h" 43 #include "../layer/search/LayerSearchWizardPage.h" 44 #include "../progress/ProgressViewerDialog.h" 47 #include "../raster/RasterInfoWidget.h" 55 #include <QApplication> 56 #include <QMessageBox> 57 #include <QActionGroup> 63 this->setWizardStyle(QWizard::ModernStyle);
64 this->setWindowTitle(tr(
"Clipping"));
67 this->setOption(QWizard::HaveHelpButton,
true);
68 this->setOption(QWizard::HelpButtonOnRight,
false);
72 this->setButton(QWizard::HelpButton, helpButton);
76 connect(
this, SIGNAL(currentIdChanged(
int)), SLOT(
onPageChanged(
int)));
90 std::list<te::map::AbstractLayerPtr> list =
m_layerSearchPage->getSearchWidget()->getSelecteds();
92 if(list.empty() ==
false)
106 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select at least one band."));
169 QMessageBox::warning(
this, tr(
"Clipping"), tr(
"File already exists."));
176 QApplication::setOverrideCursor(Qt::WaitCursor);
196 catch(
const std::exception& e)
198 QMessageBox::warning(
this, tr(
"Clipping"), e.what());
200 QApplication::restoreOverrideCursor();
206 QMessageBox::warning(
this, tr(
"Clipping"), tr(
"An exception has occurred!"));
208 QApplication::restoreOverrideCursor();
213 QApplication::restoreOverrideCursor();
233 QMessageBox::warning(
this, tr(
"Clipping"), tr(
"Selected area do not intersects the raster extent."));
237 std::map<std::string, std::string> info =
m_rasterInfoPage->getWidget()->getInfo();
256 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Clipping ended sucessfully."));
260 QMessageBox::critical(
this, tr(
"Clipping"), tr(
"Clipping execution error.") +
277 int x, y, width, height;
281 std::map<std::string, std::string> info =
m_rasterInfoPage->getWidget()->getInfo();
283 if (y + height > (
int)inputRst->getNumberOfRows() ||
284 x + width > (
int)inputRst->getNumberOfColumns())
286 QMessageBox::warning(
this, tr(
"Clipping"), tr(
"Selected area beyond the raster boundaries."));
307 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Clipping ended sucessfully."));
311 QMessageBox::critical(
this, tr(
"Clipping"), tr(
"Clipping execution error.") +
328 std::vector<te::gm::Geometry*> geomVec;
338 for(std::size_t i = 0; i < geomVec.size(); ++i)
340 if (geomVec[i]->getSRID() != inputRst->getSRID())
344 geomVec[i]->transform(inputRst->getSRID());
348 QMessageBox::critical(
this, tr(
"Clipping"), tr(
"Layer reprojection failed."));
350 const std::size_t geomVecSize = geomVec.size();
351 for( std::size_t geomVecIdx = 0 ; geomVecIdx < geomVecSize ; ++geomVecIdx )
353 delete geomVec[ geomVecIdx ];
363 std::unique_ptr<te::rst::Raster> outputRst;
367 std::vector<te::rst::BandProperty*>
bands;
369 for (std::size_t t = 0; t < inputRst->getNumberOfBands(); ++t)
372 b->
m_type = inputRst->getBand(t)->getProperty()->getType();
373 b->
m_noDataValue = inputRst->getBand(t)->getProperty()->m_noDataValue;
379 std::unique_ptr< te::gm::Envelope > envPtr;
383 double llx = std::numeric_limits< double >::max();
384 double lly = std::numeric_limits< double >::max();
385 double urx = -1.0 * std::numeric_limits< double >::max();
386 double ury = -1.0 * std::numeric_limits< double >::max();
388 const std::size_t geomVecSize = geomVec.size();
389 for( std::size_t geomVecIdx = 0 ; geomVecIdx < geomVecSize ; ++geomVecIdx )
391 llx = std::min( llx, geomVec[ geomVecIdx ]->getMBR()->getLowerLeftX() );
392 lly = std::min( lly, geomVec[ geomVecIdx ]->getMBR()->getLowerLeftY() );
393 urx = std::max( urx, geomVec[ geomVecIdx ]->getMBR()->getUpperRightX() );
394 ury = std::max( ury, geomVec[ geomVecIdx ]->getMBR()->getUpperRightY() );
401 inputRst->getGrid()->geoToGrid( llx, lly, llCol, llRow );
405 inputRst->getGrid()->geoToGrid( urx, ury, urCol, urRow );
408 inputRst->getGrid()->gridToGeo( (
double)std::floor( llCol ) - 0.5,
409 (
double)std::floor( llRow ) - 0.5, envPtr->m_llx, envPtr->m_lly );
410 inputRst->getGrid()->gridToGeo( (
double)std::ceil( urCol ) + 0.5,
411 (
double)std::ceil( urRow ) + 0.5, envPtr->m_urx, envPtr->m_ury );
415 inputRst->getGrid()->getResolutionY(), envPtr.release(), inputRst->getSRID());
419 std::map<std::string, std::string> rinfo =
430 if( outputRst.get() == nullptr )
432 QMessageBox::critical(
this, tr(
"Clipping"), tr(
"Output raster creation error."));
434 const std::size_t geomVecSize = geomVec.size();
435 for( std::size_t geomVecIdx = 0 ; geomVecIdx < geomVecSize ; ++geomVecIdx )
437 delete geomVec[ geomVecIdx ];
449 std::vector< std::complex< double > > doubleVec;
450 unsigned int outRow = 0;
451 unsigned int outCol = 0;
455 for(std::size_t i = 0; i < geomVec.size(); ++i)
457 std::vector< te::gm::Geometry* > singleGeometriesPtrs;
460 for (std::size_t singleGeometriesPtrsIdx = 0; singleGeometriesPtrsIdx <
461 singleGeometriesPtrs.size(); ++singleGeometriesPtrsIdx)
463 te::gm::Geometry* currGeomPtr = singleGeometriesPtrs[singleGeometriesPtrsIdx];
472 std::vector<te::rst::BandProperty*>
bands;
474 for (std::size_t t = 0; t < inputRst->getNumberOfBands(); ++t)
477 b->
m_type = inputRst->getBand(t)->getProperty()->getType();
478 b->
m_noDataValue = inputRst->getBand(t)->getProperty()->m_noDataValue;
482 std::unique_ptr< te::gm::Envelope > envPtr;
488 inputRst->getGrid()->geoToGrid( unionEnvelopePtr->
m_llx, unionEnvelopePtr->
m_lly, llCol, llRow );
492 inputRst->getGrid()->geoToGrid( unionEnvelopePtr->
m_urx, unionEnvelopePtr->
m_ury, urCol, urRow );
495 inputRst->getGrid()->gridToGeo( (
double)std::floor( llCol ) - 0.5,
496 (
double)std::floor( llRow ) - 0.5, envPtr->m_llx, envPtr->m_lly );
497 inputRst->getGrid()->gridToGeo( (
double)std::ceil( urCol ) + 0.5,
498 (
double)std::ceil( urRow ) + 0.5, envPtr->m_urx, envPtr->m_ury );
502 inputRst->getGrid()->getResolutionY(), envPtr.release(), inputRst->getSRID());
506 std::map<std::string, std::string> rinfo =
517 if( outputRst.get() == nullptr )
519 QMessageBox::critical(
this, tr(
"Clipping"), tr(
"Output raster creation error."));
521 const std::size_t geomVecSize = geomVec.size();
522 for( std::size_t geomVecIdx = 0 ; geomVecIdx < geomVecSize ; ++geomVecIdx )
524 delete geomVec[ geomVecIdx ];
549 outputGrid.
gridToGeo((
double)outCol, (
double)outRow, outputCoord.
x,
551 inputGrid.geoToGrid(outputCoord.
x, outputCoord.
y, inputCoord.
x,
554 interp.getValues(inputCoord.
x, inputCoord.
y, doubleVec);
556 outputRst->setValues(outCol, outRow, doubleVec);
575 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Clipping execution error.") +
586 int addOutPutLayer = QMessageBox::question(
this, tr(
"Clipping"),
587 tr(
"Would you like to add ") + QString::number(
m_outputLayer.size()) + (
" layer(s) on active project?"),
588 QMessageBox::Yes | QMessageBox::No);
589 if(addOutPutLayer == QMessageBox::Yes)
599 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Clipping ended sucessfully."));
619 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Clipping ended sucessfully."));
623 QMessageBox::critical(
this, tr(
"Clipping"), tr(
"Clipping execution error.") +
626 const std::size_t geomVecSize = geomVec.size();
627 for( std::size_t geomVecIdx = 0 ; geomVecIdx < geomVecSize ; ++geomVecIdx )
629 delete geomVec[ geomVecIdx ];
637 const std::size_t geomVecSize = geomVec.size();
638 for( std::size_t geomVecIdx = 0 ; geomVecIdx < geomVecSize ; ++geomVecIdx )
640 delete geomVec[ geomVecIdx ];
655 std::map<std::string, te::gm::Geometry*> geomMap;
662 std::map<std::string, te::gm::Geometry*>::iterator itg;
664 itg = geomMap.begin();
666 while(itg != geomMap.end())
668 if (itg->second->getSRID() != inputRst->getSRID())
672 itg->second->transform(inputRst->getSRID());
676 QMessageBox::critical(
this, tr(
"Clipping"), tr(
"Layer reprojection failed."));
685 std::unique_ptr<te::rst::Raster> outputRst;
690 std::vector< std::complex< double > > doubleVec;
691 unsigned int outRow = 0;
692 unsigned int outCol = 0;
696 itg = geomMap.begin();
700 while(itg != geomMap.end())
702 std::vector< te::gm::Geometry* > singleGeometriesPtrs;
705 std::vector<te::rst::BandProperty*>
bands;
707 for (std::size_t t = 0; t < inputRst->getNumberOfBands(); ++t)
710 b->
m_type = inputRst->getBand(t)->getProperty()->getType();
711 b->
m_noDataValue = inputRst->getBand(t)->getProperty()->m_noDataValue;
717 std::unique_ptr< te::gm::Envelope > envPtr;
723 inputRst->getGrid()->geoToGrid( unionEnvelopePtr->
m_llx, unionEnvelopePtr->
m_lly, llCol, llRow );
727 inputRst->getGrid()->geoToGrid( unionEnvelopePtr->
m_urx, unionEnvelopePtr->
m_ury, urCol, urRow );
730 inputRst->getGrid()->gridToGeo( (
double)std::floor( llCol ) - 0.5,
731 (
double)std::floor( llRow ) - 0.5, envPtr->m_llx, envPtr->m_lly );
732 inputRst->getGrid()->gridToGeo( (
double)std::ceil( urCol ) + 0.5,
733 (
double)std::ceil( urRow ) + 0.5, envPtr->m_urx, envPtr->m_ury );
737 inputRst->getGrid()->getResolutionY(), envPtr.release(), inputRst->getSRID());
741 std::map<std::string, std::string> rinfo =
752 if( outputRst.get() == nullptr )
754 QMessageBox::critical(
this, tr(
"Clipping"), tr(
"Output raster creation error."));
761 for (std::size_t singleGeometriesPtrsIdx = 0; singleGeometriesPtrsIdx <
762 singleGeometriesPtrs.size(); ++singleGeometriesPtrsIdx)
764 te::gm::Geometry* currGeomPtr = singleGeometriesPtrs[singleGeometriesPtrsIdx];
787 outputGrid.
gridToGeo((
double)outCol, (
double)outRow, outputCoord.
x,
789 inputGrid.geoToGrid(outputCoord.
x, outputCoord.
y, inputCoord.
x,
792 interp.getValues(inputCoord.
x, inputCoord.
y, doubleVec);
794 outputRst->setValues(outCol, outRow, doubleVec);
813 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Clipping execution error.") +
822 int addOutPutLayer = QMessageBox::question(
this, tr(
"Clipping"),
823 tr(
"Would you like to add ") + QString::number(
m_outputLayer.size()) + (
" layer(s) on active project?"),
824 QMessageBox::Yes | QMessageBox::No);
825 if(addOutPutLayer == QMessageBox::Yes)
835 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Clipping ended sucessfully."));
Near neighborhood interpolation method.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
A raster band description.
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
virtual Raster * trim(const te::gm::Envelope *env, const std::map< std::string, std::string > &rinfo) const
Subsetting operation for trimming (cropping) the raster.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
double m_urx
Upper right corner x-coordinate.
virtual Raster * resample(int method, unsigned int drow, unsigned int dcolumn, unsigned int height, unsigned int width, unsigned int newheight, unsigned int newwidth, const std::map< std::string, std::string > &rinfo) const
Resample a subset of the raster, given a box.
TEGEOMEXPORT std::unique_ptr< te::gm::Geometry > GetGeometryUnion(const std::vector< te::gm::Geometry * > &geomVec)
It returns the union of a geometry vector.
TERASTEREXPORT void FillRaster(te::rst::Raster *rin, const std::complex< double > &value)
Fill a Raster with provided value (all bands).
unsigned int getRow() const
Returns the current row in iterator.
An utility struct for representing 2D coordinates.
int m_type
The data type of the elements in the band ( See te::dt namespace basic data types for reference )...
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
A Qt dialog that allows users to run a clipping operation defined by RP module.
TEGEOMEXPORT void Multi2Single(const te::gm::Geometry *g, std::vector< te::gm::Geometry * > &geoms)
It will get a GeometryCollection and distribute in a vector.
static const std::string getLastLogStr()
Returns the last log string generated by this module.
This file defines a class for a Raster Info Wizard page.
This file defines a class for a Clipping Wizard page.
double m_llx
Lower left corner x-coordinate.
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
This class is GUI used to define the raster info parameters for raster factory.
Utility functions for the data access module.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
double m_lly
Lower left corner y-coordinate.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p, const IterationType iterationType)
Returns an iterator referring to the first value of the band.
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
double m_ury
Upper right corner y-coordinate.
static Raster * make()
It creates and returns an empty raster with default raster driver.
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
unsigned int getColumn() const
Returns the current column in iterator.
A rectified grid is the spatial support for raster data.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
This class is GUI used to define the clipping parameters for the RP constast operation.