28#include "moc_qgsrastervectorfieldrendererwidget.cpp"
42 mDirectionEncodingComboBox->addItem( tr(
"Esri (1 = E, 2 = SE, 4 = S, 8 = SW, 16 = W, 32 = NW, 64 = N, 128 = NE)" ), QVariant::fromValue(
Qgis::RasterDirectionEncoding::Esri ) );
44 mDirectionEncodingComboBox->addItem( tr(
"SAGA (0 = N, 1 = NE, 2 = E, 3 = SE, 4 = S, 5 = SW, 6 = W, 7 = NW)" ), QVariant::fromValue(
Qgis::RasterDirectionEncoding::Saga ) );
55 int yBand = std::min( 2, std::max( 1, bandCount ) );
56 int directionBand = 1;
63 directionBand =
renderer->directionBand();
64 encoding =
renderer->directionEncoding();
70 whileBlocking( mDirectionBandComboBox )->setBand( directionBand );
71 whileBlocking( mSourceModeComboBox )->setCurrentIndex( mSourceModeComboBox->findData( QVariant::fromValue( sourceMode ) ) );
72 whileBlocking( mDirectionEncodingComboBox )->setCurrentIndex( mDirectionEncodingComboBox->findData( QVariant::fromValue( encoding ) ) );
77 mVectorFieldSettingsWidget->setSettings( settings );
83 connect( mSourceModeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsRasterVectorFieldRendererWidget::onSourceModeChanged );
92void QgsRasterVectorFieldRendererWidget::onSourceModeChanged()
96 const QgsVectorFieldSettings settings = mVectorFieldSettingsWidget->settings();
98 mVectorFieldSettingsWidget->setSettings( settings );
103void QgsRasterVectorFieldRendererWidget::updateSourceMode()
106 mBandsStackedWidget->setCurrentWidget( encoded ? mDirectionBandPage : mComponentBandsPage );
107 mVectorFieldSettingsWidget->setHasMagnitude( !encoded );
109 updateMagnitudeRange();
112void QgsRasterVectorFieldRendererWidget::onBandChanged()
114 updateMagnitudeRange();
118void QgsRasterVectorFieldRendererWidget::updateMagnitudeRange()
120 mMinimumMagnitude = std::numeric_limits<double>::quiet_NaN();
121 mMaximumMagnitude = std::numeric_limits<double>::quiet_NaN();
127 mMinimumMagnitude = 0;
128 mMaximumMagnitude = 1;
129 mVectorFieldSettingsWidget->setMagnitudeRange( mMinimumMagnitude, mMaximumMagnitude );
134 const int xBand = mXBandComboBox->currentBand();
135 const int yBand = mYBandComboBox->currentBand();
136 if ( !provider || xBand <= 0 || yBand <= 0 )
147 if ( std::isnan( largestX ) || std::isnan( largestY ) )
150 mMinimumMagnitude = 0;
151 mMaximumMagnitude = std::hypot( largestX, largestY );
153 mVectorFieldSettingsWidget->setMagnitudeRange( mMinimumMagnitude, mMaximumMagnitude );
162 auto renderer = std::make_unique<QgsRasterVectorFieldRenderer>( provider );
163 renderer->setSourceMode( currentSourceMode() );
164 renderer->setXBand( mXBandComboBox->currentBand() );
165 renderer->setYBand( mYBandComboBox->currentBand() );
166 renderer->setDirectionBand( mDirectionBandComboBox->currentBand() );
168 renderer->setSettings( mVectorFieldSettingsWidget->settings() );
169 renderer->setMinimumMagnitude( mMinimumMagnitude );
170 renderer->setMaximumMagnitude( mMaximumMagnitude );
RasterVectorFieldSourceMode
Defines how a raster vector field renderer reads the vectors from the raster bands.
@ CartesianComponents
Two bands holding the x and y components of the vectors.
@ EncodedDirection
A single band holding integer coded compass directions, see Qgis::RasterDirectionEncoding.
QFlags< RasterBandStatistic > RasterBandStatistics
Statistics to be calculated for raster bands.
RasterDirectionEncoding
Schemes used to encode a compass direction as an integer raster value.
@ PcRaster
PCRaster: 1=SW, 2=S, 3=SE, 4=W, 6=E, 7=NW, 8=N, 9=NE.
@ Esri
Esri: 1=E, 2=SE, 4=S, 8=SW, 16=W, 32=NW, 64=N, 128=NE.
@ Saga
SAGA: 0=N, 1=NE, 2=E, 3=SE, 4=S, 5=SW, 6=W, 7=NW.
@ Grass
GRASS: 1=NE, 2=N, 3=NW, 4=W, 5=SW, 6=S, 7=SE, 8=E.
void bandChanged(int band)
Emitted when the currently selected band changes.
double minimumValue
The minimum cell value in the raster band.
double maximumValue
The maximum cell value in the raster band.
Base class for raster data providers.
Q_DECL_DEPRECATED QgsRasterBandStats bandStatistics(int bandNo, int stats, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, QgsRasterBlockFeedback *feedback=nullptr)
Returns the band statistics.
Represents a raster layer.
Raster renderer pipe that applies colors to a raster.
Raster renderer which draws a vector field stored in raster bands.
QgsVectorFieldSettings settings() const
Returns the settings used to render the vector field.
Qgis::RasterDirectionEncoding directionEncoding() const
Returns the scheme the directionBand() is coded with.
Qgis::RasterVectorFieldSourceMode sourceMode() const
Returns the way the vectors are stored in the raster bands.
A rectangle specified with double values.
Represents a renderer settings for vector datasets.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.