1
/***************************************************************************
2
qgsrasterlayerproperties.cpp - description
5
copyright : (C) 2004 Tim Sutton
6
email : tim@linfiniti.com
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
19
#include "qgsrasterlayerproperties.h"
20
#include "qgslayerprojectionselector.h"
21
#include "qgsproject.h"
23
#include <qapplication.h>
27
#include <qcombobox.h>
28
#include <qcheckbox.h>
29
#include <qgroupbox.h>
31
#include <qradiobutton.h>
32
#include <qlineedit.h>
34
#include <qtextedit.h>
37
#include <qtabwidget.h>
39
#include <qlistview.h>
41
#include <qtextbrowser.h>
43
#include <qpointarray.h>
46
const char * const ident =
47
"$Id: qgsrasterlayerproperties.cpp,v 1.57.2.9 2005/10/16 23:35:33 timlinux Exp $";
50
QgsRasterLayerProperties::QgsRasterLayerProperties(QgsMapLayer *lyr, QWidget *parent, const char *name, bool modal)
51
: QgsRasterLayerPropertiesBase(parent, name, modal),
52
rasterLayer( dynamic_cast<QgsRasterLayer*>(lyr) )
55
// set up the scale based layer visibility stuff....
56
chkUseScaleDependentRendering->setChecked(lyr->scaleBasedVisibility());
57
spinMinimumScale->setValue((int)lyr->minScale());
58
spinMaximumScale->setValue((int)lyr->maxScale());
60
// build GUI components
62
cboColorMap->insertItem(tr("Grayscale"));
63
cboColorMap->insertItem(tr("Pseudocolor"));
64
cboColorMap->insertItem(tr("Freak Out"));
66
//set the std deviations to be plotted combo box
67
cboStdDev->insertItem("0");
68
cboStdDev->insertItem("0.5");
69
cboStdDev->insertItem("0.75");
70
cboStdDev->insertItem("1");
71
cboStdDev->insertItem("1.25");
72
cboStdDev->insertItem("1.5");
73
cboStdDev->insertItem("1.75");
74
cboStdDev->insertItem("2");
75
cboStdDev->insertItem("2.25");
76
cboStdDev->insertItem("2.5");
77
cboStdDev->insertItem("2.75");
78
cboStdDev->insertItem("3");
81
// Set up the combo boxes that contain band lists using the qstring list generated above
84
if (rasterLayer->getRasterLayerType()
85
== QgsRasterLayer::PALETTE) //paletted layers have hard coded color entries
87
cboRed->insertItem("Red");
88
cboGreen->insertItem("Red");
89
cboBlue->insertItem("Red");
91
cboRed->insertItem("Green");
92
cboGreen->insertItem("Green");
93
cboBlue->insertItem("Green");
95
cboRed->insertItem("Blue");
96
cboGreen->insertItem("Blue");
97
cboBlue->insertItem("Blue");
99
cboRed->insertItem(tr("Not Set"));
100
cboGreen->insertItem(tr("Not Set"));
101
cboBlue->insertItem(tr("Not Set"));
103
cboGray->insertItem("Red");
104
cboGray->insertItem("Green");
105
cboGray->insertItem("Blue");
106
cboGray->insertItem(tr("Not Set"));
108
lstHistogramLabels->insertItem(tr("Palette"));
110
else // all other layer types use band name entries only
113
std::cout << "Populating combos for non paletted layer" << std::endl;
117
// Get a list of band names
119
QStringList myBandNameQStringList;
121
int myBandCountInt = rasterLayer->getBandCount();
123
std::cout << "Looping though " << myBandCountInt << " image layers to get their names " << std::endl;
125
for (int myIteratorInt = 1;
126
myIteratorInt <= myBandCountInt;
129
//find out the name of this band
130
QString myRasterBandNameQString = rasterLayer->getRasterBandName(myIteratorInt) ;
133
//add the band to the histogram tab
135
QPixmap myPixmap(10,10);
137
if (myBandCountInt==1) //draw single band images with black
139
myPixmap.fill( Qt::black );
141
else if (myIteratorInt==1)
143
myPixmap.fill( Qt::red );
145
else if (myIteratorInt==2)
147
myPixmap.fill( Qt::green );
149
else if (myIteratorInt==3)
151
myPixmap.fill( Qt::blue );
153
else if (myIteratorInt==4)
155
myPixmap.fill( Qt::magenta );
157
else if (myIteratorInt==5)
159
myPixmap.fill( Qt::darkRed );
161
else if (myIteratorInt==6)
163
myPixmap.fill( Qt::darkGreen );
165
else if (myIteratorInt==7)
167
myPixmap.fill( Qt::darkBlue );
171
myPixmap.fill( Qt::gray );
173
lstHistogramLabels->insertItem(myPixmap,myRasterBandNameQString);
174
//keep a list of band names for later use
175
//! @note band names should not be translated!
176
myBandNameQStringList.append(myRasterBandNameQString);
179
//select all histogram layers list items by default
180
for (int myIteratorInt = 1;
181
myIteratorInt <= myBandCountInt;
184
QListBoxItem *myItem = lstHistogramLabels->item( myIteratorInt-1 );
185
lstHistogramLabels->setSelected( myItem,true);
188
for (QStringList::Iterator myIterator = myBandNameQStringList.begin();
189
myIterator != myBandNameQStringList.end();
192
QString myQString = *myIterator;
195
std::cout << "Inserting : " << myQString.local8Bit() << std::endl;
198
cboGray->insertItem(myQString);
199
cboRed->insertItem(myQString);
200
cboGreen->insertItem(myQString);
201
cboBlue->insertItem(myQString);
203
cboRed->insertItem(tr("Not Set"));
204
cboGreen->insertItem(tr("Not Set"));
205
cboBlue->insertItem(tr("Not Set"));
206
cboGray->insertItem(tr("Not Set"));
210
#if defined(WIN32) || defined(Q_OS_MACX)
211
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
213
QPixmap myPyramidPixmap(QString(PKGDATAPATH) + QString("/images/icons/pyramid.png"));
214
QPixmap myNoPyramidPixmap(QString(PKGDATAPATH) + QString("/images/icons/no_pyramid.png"));
216
RasterPyramidList myPyramidList = rasterLayer->buildRasterPyramidList();
217
RasterPyramidList::iterator myRasterPyramidIterator;
219
for ( myRasterPyramidIterator=myPyramidList.begin();
220
myRasterPyramidIterator != myPyramidList.end();
221
++myRasterPyramidIterator )
223
if ((*myRasterPyramidIterator).existsFlag==true)
225
lbxPyramidResolutions->insertItem(myPyramidPixmap,
226
QString::number((*myRasterPyramidIterator).xDimInt) + QString(" x ") +
227
QString::number((*myRasterPyramidIterator).yDimInt));
231
lbxPyramidResolutions->insertItem(myNoPyramidPixmap,
232
QString::number((*myRasterPyramidIterator).xDimInt) + QString(" x ") +
233
QString::number((*myRasterPyramidIterator).yDimInt));
237
if ( rasterLayer->coordinateTransform() )
239
leSpatialRefSys->setText(rasterLayer->coordinateTransform()->sourceSRS().proj4String());
242
//pbnHistRefresh_clicked();
244
// update based on lyr's current state
246
} // QgsRasterLayerProperties ctor
249
QgsRasterLayerProperties::~QgsRasterLayerProperties()
255
void QgsRasterLayerProperties::apply()
257
// set up the scale based layer visibility stuff....
258
rasterLayer->setScaleBasedVisibility(chkUseScaleDependentRendering->isChecked());
259
rasterLayer->setMinScale(spinMinimumScale->value());
260
rasterLayer->setMaxScale(spinMaximumScale->value());
262
rasterLayer->setTransparency(static_cast < unsigned int >(255 - sliderTransparency->value()));
263
//set the std deviations to be plotted
264
rasterLayer->setStdDevsToPlot(cboStdDev->currentText().toDouble());
265
//set whether the layer histogram should be inverted
266
if (cboxInvertColorMap->isChecked()
269
rasterLayer->setInvertHistogramFlag(true);
273
rasterLayer->setInvertHistogramFlag(false);
275
//now set the color -> band mapping combos to the correct values
276
rasterLayer->setRedBandName(cboRed->currentText());
277
rasterLayer->setGreenBandName(cboGreen->currentText());
278
rasterLayer->setBlueBandName(cboBlue->currentText());
279
rasterLayer->setGrayBandName(cboGray->currentText());
280
//set the appropriate color ramping type
281
if (cboColorMap->currentText() == tr("Pseudocolor"))
283
rasterLayer->setColorRampingType(QgsRasterLayer::BLUE_GREEN_RED);
285
else if (cboColorMap->currentText() == tr("Freak Out"))
287
rasterLayer->setColorRampingType(QgsRasterLayer::FREAK_OUT);
289
//set the appropriate render style
290
if ((grpBoxGrayscale->isEnabled())
291
&& (rbtnSingleBand->isChecked()))
296
if (rasterLayer->rasterLayerType == QgsRasterLayer::GRAY_OR_UNDEFINED)
299
if (cboColorMap->currentText() != tr("Grayscale"))
302
std::cout << "Setting Raster Drawing Style to :: SINGLE_BAND_PSEUDO_COLOR" << std::endl;
305
rasterLayer->setDrawingStyle(QgsRasterLayer::SINGLE_BAND_PSEUDO_COLOR);
310
std::cout << "Setting Raster Drawing Style to :: SINGLE_BAND_GRAY" << std::endl;
313
rasterLayer->setDrawingStyle(QgsRasterLayer::SINGLE_BAND_GRAY);
319
else if (rasterLayer->rasterLayerType == QgsRasterLayer::PALETTE)
321
if (cboColorMap->currentText() != tr("Grayscale"))
324
std::cout << "Setting Raster Drawing Style to :: PALETTED_SINGLE_BAND_PSEUDO_COLOR" << std::endl;
327
rasterLayer->setDrawingStyle(QgsRasterLayer::PALETTED_SINGLE_BAND_PSEUDO_COLOR);
332
std::cout << "Setting Raster Drawing Style to :: PALETTED_SINGLE_BAND_GRAY" << std::endl;
336
std::cout << "Combo value : " << cboGray->currentText().local8Bit() << " GrayBand Mapping : " << rasterLayer->
337
getGrayBandName().local8Bit() << std::endl;
340
rasterLayer->setDrawingStyle(QgsRasterLayer::PALETTED_SINGLE_BAND_GRAY);
346
else if (rasterLayer->rasterLayerType == QgsRasterLayer::MULTIBAND)
348
if (cboColorMap->currentText() != tr("Grayscale"))
351
std::cout << "Setting Raster Drawing Style to ::MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR " << std::endl;
354
rasterLayer->setDrawingStyle(QgsRasterLayer::MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR);
359
std::cout << "Setting Raster Drawing Style to :: MULTI_BAND_SINGLE_BAND_GRAY" << std::endl;
360
std::cout << "Combo value : " << cboGray->currentText().local8Bit() << " GrayBand Mapping : " << rasterLayer->
361
getGrayBandName().local8Bit() << std::endl;
364
rasterLayer->setDrawingStyle(QgsRasterLayer::MULTI_BAND_SINGLE_BAND_GRAY);
368
} //end of grayscale box enabled and rbtnsingleband checked
369
else //assume that rbtnThreeBand is checked and render in rgb color
371
//set the grayscale color table type if the groupbox is enabled
373
if (rasterLayer->rasterLayerType == QgsRasterLayer::PALETTE)
376
std::cout << "Setting Raster Drawing Style to :: PALETTED_MULTI_BAND_COLOR" << std::endl;
379
rasterLayer->setDrawingStyle(QgsRasterLayer::PALETTED_MULTI_BAND_COLOR);
381
else if (rasterLayer->rasterLayerType == QgsRasterLayer::MULTIBAND)
385
std::cout << "Setting Raster Drawing Style to :: MULTI_BAND_COLOR" << std::endl;
388
rasterLayer->setDrawingStyle(QgsRasterLayer::MULTI_BAND_COLOR);
393
rasterLayer->setLayerName(leDisplayName->text());
395
//update the legend pixmap
396
pixmapLegend->setPixmap(rasterLayer->getLegendQPixmap());
397
pixmapLegend->setScaledContents(true);
398
pixmapLegend->repaint(false);
399
rasterLayer->updateItemPixmap();
401
//see if the user would like debug overlays
402
if (cboxShowDebugInfo->isChecked()
405
rasterLayer->setShowDebugOverlayFlag(true);
409
rasterLayer->setShowDebugOverlayFlag(false);
412
// update histogram clipping ranges from the advanced symbology tab
414
rasterLayer->setMinRedDouble(static_cast < double >(sliderMinRed->value()));
415
rasterLayer->setMaxRedDouble(static_cast < double >(255 - sliderMaxRed->value()));
416
rasterLayer->setMinGreenDouble(static_cast < double >(sliderMinGreen->value()));
417
rasterLayer->setMaxGreenDouble(static_cast < double >(255 - sliderMaxGreen->value()));
418
rasterLayer->setMinBlueDouble(static_cast < double >(sliderMinBlue->value()));
419
rasterLayer->setMaxBlueDouble(static_cast < double >(255 - sliderMaxBlue->value()));
420
rasterLayer->setMinGrayDouble(static_cast < double >(sliderMinGray->value()));
421
rasterLayer->setMaxGrayDouble(static_cast < double >(255 - sliderMaxGray->value()));
422
//get the thumbnail for the layer
423
QPixmap myQPixmap = QPixmap(pixmapThumbnail->width(),pixmapThumbnail->height());
424
rasterLayer->drawThumbnail(&myQPixmap);
425
pixmapThumbnail->setPixmap(myQPixmap);
426
//make sure the layer is redrawn
427
rasterLayer->triggerRepaint();
430
void QgsRasterLayerProperties::accept()
435
void QgsRasterLayerProperties::sliderTransparency_valueChanged(int theValue)
437
//set the transparency percentage label to a suitable value
438
int myInt = static_cast < int >((theValue / 255.0) * 100); //255.0 to prevent integer division
439
lblTransparencyPercent->setText(QString::number(myInt) + "%");
440
}//sliderTransparency_valueChanged
442
void QgsRasterLayerProperties::sliderMaxRed_valueChanged(int)
444
//the 255- is used because a vertical qslider has its max value at the bottom and
445
//we want it to appear to the user that the max value is at the top, so we invert its value
446
if ((255 - sliderMaxRed->value()) < sliderMinRed->value())
448
sliderMinRed->setValue(255 - sliderMaxRed->value());
450
makeScalePreview("red");
454
void QgsRasterLayerProperties::sliderMinRed_valueChanged(int)
456
//the 255- is used because a vertical qslider has its max value at the bottom and
457
//we want it to appear to the user that the max value is at the top, so we invert its value
458
if ((255 - sliderMaxRed->value()) < sliderMinRed->value())
460
sliderMaxRed->setValue(255 - sliderMinRed->value());
462
makeScalePreview("red");
466
void QgsRasterLayerProperties::sliderMaxBlue_valueChanged(int)
468
//the 255- is used because a vertical qslider has its max value at the bottom and
469
//we want it to appear to the user that the max value is at the top, so we invert its value
470
if ((255 - sliderMaxBlue->value()) < sliderMinBlue->value())
472
sliderMinBlue->setValue(255 - sliderMaxBlue->value());
474
makeScalePreview("blue");
478
void QgsRasterLayerProperties::sliderMinBlue_valueChanged(int)
480
//the 255- is used because a vertical qslider has its max value at the bottom and
481
//we want it to appear to the user that the max value is at the top, so we invert its value
482
if ((255 - sliderMaxBlue->value()) < sliderMinBlue->value())
484
sliderMaxBlue->setValue(255 - sliderMinBlue->value());
487
makeScalePreview("blue");
491
void QgsRasterLayerProperties::sliderMaxGreen_valueChanged(int)
493
//the 255- is used because a vertical qslider has its max value at the bottom and
494
//we want it to appear to the user that the max value is at the top, so we invert its value
495
if ((255 - sliderMaxGreen->value()) < sliderMinGreen->value())
497
sliderMinGreen->setValue(255 - sliderMaxGreen->value());
500
makeScalePreview("green");
504
void QgsRasterLayerProperties::sliderMinGreen_valueChanged(int)
506
//the 255- is used because a vertical qslider has its max value at the bottom and
507
//we want it to appear to the user that the max value is at the top, so we invert its value
509
if ((255 - sliderMaxGreen->value()) < sliderMinGreen->value())
511
sliderMaxGreen->setValue(255 - sliderMinGreen->value());
513
makeScalePreview("green");
517
void QgsRasterLayerProperties::sliderMaxGray_valueChanged(int)
519
//the 255- is used because a vertical qslider has its max value at the bottom and
520
//we want it to appear to the user that the max value is at the top, so we invert its value
522
if ((255 - sliderMaxGray->value()) < sliderMinGray->value())
524
sliderMinGray->setValue(255 - sliderMaxGray->value());
526
makeScalePreview("gray");
530
void QgsRasterLayerProperties::sliderMinGray_valueChanged(int)
532
//the 255- is used because a vertical qslider has its max value at the bottom and
533
//we want it to appear to the user that the max value is at the top, so we invert its value
534
if ((255 - sliderMaxGray->value()) < sliderMinGray->value())
536
sliderMaxGray->setValue(255 - sliderMinGray->value());
538
makeScalePreview("gray");
543
void QgsRasterLayerProperties::makeScalePreview(QString theColor)
545
double myMinDouble = 0;
546
double myMaxDouble = 255;
547
double myRedDouble = 0;
548
double myBlueDouble = 0;
549
double myGreenDouble = 0;
550
unsigned int myTransparencyInt = sliderTransparency->value();
551
//the 255- is used because a vertical qslider has its max value at the bottom and
552
//we want it to appear to the user that the max value is at the top, so we invert its value
553
if (theColor == "red")
555
myMinDouble = sliderMinRed->value();
556
myMaxDouble = 255 - sliderMaxRed->value();
557
myRedDouble = myMaxDouble;
559
else if (theColor == "green")
561
myMinDouble = sliderMinGreen->value();
562
myMaxDouble = 255 - sliderMaxGreen->value();
564
else if (theColor == "blue")
566
myMinDouble = sliderMinBlue->value();
567
myMaxDouble = 255 - sliderMaxBlue->value();
569
else if (theColor == "gray")
571
myMinDouble = sliderMinGray->value();
572
myMaxDouble = 255 - sliderMaxGray->value();
574
QImage myQImage = QImage(100, 100, 32); //32bpp
575
double myRangeDouble = myMaxDouble - myMinDouble;
576
double myDecrementDouble = myRangeDouble / 100;
577
//std::cout << "Decrementing " << theColor << " by : " << myDecrementDouble << std::endl;
578
if (myDecrementDouble == 0)
580
for (int myRowInt = 99; myRowInt >= 0; myRowInt = myRowInt - 1)
582
//reset the max value that the scale starts at
583
if (theColor == "red")
585
myRedDouble = myMaxDouble;
587
else if (theColor == "green")
589
myGreenDouble = myMaxDouble;
591
else if (theColor == "blue")
593
myBlueDouble = myMaxDouble;
595
else if (theColor == "gray")
597
myRedDouble = myMaxDouble;
598
myGreenDouble = myMaxDouble;
599
myBlueDouble = myMaxDouble;
601
for (int myColInt = 99; myColInt >= 0; myColInt--)
603
if (theColor == "red")
605
myRedDouble -= myDecrementDouble;
607
else if (theColor == "green")
609
myGreenDouble -= myDecrementDouble;
611
else if (theColor == "blue")
613
myBlueDouble -= myDecrementDouble;
615
else if (theColor == "gray")
617
myRedDouble -= myDecrementDouble;
618
myGreenDouble -= myDecrementDouble;
619
myBlueDouble -= myDecrementDouble;
621
//std::cout << "R " << myRedDouble << " G " << myGreenDouble << " B " << myBlueDouble << std::endl;
622
myQImage.setPixel(myColInt, myRowInt,
623
qRgb((unsigned int) myRedDouble, (unsigned int) myGreenDouble, (unsigned int) myBlueDouble));
626
// Create a pixmap the same size as the image - to be placed in the pixmalLabel
627
QPixmap *myQPixmap = new QPixmap(100, 100);
630
// Draw a text alabel onto the pixmap showing the min max value
632
QPainter myQPainter(myQPixmap);
633
myQPainter.rotate(-45);
634
myQPainter.drawImage(-70, 0, myQImage.scale(140, 140));
635
myQPainter.rotate(45);
636
QFont myQFont("arial", 18, QFont::Bold);
637
myQPainter.setFont(myQFont);
638
myQPainter.setPen(Qt::white);
639
myQPainter.drawText(15, 50, QString::number(static_cast < unsigned int >(myMinDouble)) + " - " + QString::number(static_cast
644
//now draw the image into the relevant pixmap label
645
if (theColor == "red")
647
pixmapScaleRed->setScaledContents(true);
648
pixmapScaleRed->setPixmap(*myQPixmap);
649
pixmapScaleRed->repaint(false);
651
else if (theColor == "green")
653
pixmapScaleGreen->setScaledContents(true);
654
pixmapScaleGreen->setPixmap(*myQPixmap);
655
pixmapScaleGreen->repaint(false);
657
else if (theColor == "blue")
659
pixmapScaleBlue->setScaledContents(true);
660
pixmapScaleBlue->setPixmap(*myQPixmap);
661
pixmapScaleBlue->repaint(false);
663
else if (theColor == "gray")
665
pixmapScaleGray->setScaledContents(true);
666
pixmapScaleGray->setPixmap(*myQPixmap);
667
pixmapScaleGray->repaint(false);
672
void QgsRasterLayerProperties::rbtnSingleBand_toggled(bool)
676
void QgsRasterLayerProperties::rbtnThreeBand_toggled(bool)
679
void QgsRasterLayerProperties::buttonBuildPyramids_clicked()
683
// Go through the list marking any files that are selected in the listview
684
// as true so that we can generate pyramids for them.
686
RasterPyramidList myPyramidList = rasterLayer->buildRasterPyramidList();
687
for ( unsigned int myCounterInt = 0; myCounterInt < lbxPyramidResolutions->count(); myCounterInt++ )
689
QListBoxItem *myItem = lbxPyramidResolutions->item( myCounterInt );
690
if ( myItem->isSelected() )
692
//mark to be pyramided
693
myPyramidList[myCounterInt].existsFlag=true;
697
// Ask raster layer to build the pyramids
699
rasterLayer->buildPyramids(myPyramidList,cboResamplingMethod->currentText());
701
// repopulate the pyramids list
703
lbxPyramidResolutions->clear();
704
#if defined(WIN32) || defined(Q_OS_MACX)
705
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
707
QPixmap myPyramidPixmap(QString(PKGDATAPATH) + QString("/images/icons/pyramid.png"));
708
QPixmap myNoPyramidPixmap(QString(PKGDATAPATH) + QString("/images/icons/no_pyramid.png"));
709
RasterPyramidList::iterator myRasterPyramidIterator;
710
for ( myRasterPyramidIterator=myPyramidList.begin();
711
myRasterPyramidIterator != myPyramidList.end();
712
++myRasterPyramidIterator )
714
if ((*myRasterPyramidIterator).existsFlag==true)
716
lbxPyramidResolutions->insertItem(myPyramidPixmap,
717
QString::number((*myRasterPyramidIterator).xDimInt) + QString(" x ") +
718
QString::number((*myRasterPyramidIterator).yDimInt));
722
lbxPyramidResolutions->insertItem(myNoPyramidPixmap,
723
QString::number((*myRasterPyramidIterator).xDimInt) + QString(" x ") +
724
QString::number((*myRasterPyramidIterator).yDimInt));
727
//update the legend pixmap
728
pixmapLegend->setPixmap(rasterLayer->getLegendQPixmap());
729
pixmapLegend->setScaledContents(true);
730
pixmapLegend->repaint(false);
731
rasterLayer->updateItemPixmap();
732
//populate the metadata tab's text browser widget with gdal metadata info
733
txtbMetadata->setText(rasterLayer->getMetadata());
738
@note moved from ctor
740
Previously this dialog was created anew with each right-click pop-up menu
741
invokation. Changed so that the dialog always exists after first
742
invocation, and is just re-synchronized with its layer's state when
746
void QgsRasterLayerProperties::sync()
748
// XXX Remove the advanced symbology widget and debug overlay for 0.1 release
750
tabSymbology->removePage(TabPage);
751
cboxShowDebugInfo->hide();
753
//get the thumbnail for the layer
754
QPixmap myQPixmap = QPixmap(pixmapThumbnail->width(),pixmapThumbnail->height());
755
rasterLayer->drawThumbnail(&myQPixmap);
756
pixmapThumbnail->setPixmap(myQPixmap);
758
//populate the metadata tab's text browser widget with gdal metadata info
759
txtbMetadata->setText(rasterLayer->getMetadata());
760
//tabSymbology->removePage(tabMetadata);
761
//display the raster dimensions and no data value
762
lblColumns->setText(tr("Columns:") + QString::number(rasterLayer->getRasterXDim()));
763
lblRows->setText(tr("Rows:") + QString::number(rasterLayer->getRasterYDim()));
764
lblNoData->setText(tr("No Data:") + QString::number(rasterLayer->getNoDataValue()));
766
//these properties (layername and label) are provided by the qgsmaplayer superclass
767
leLayerSource->setText(rasterLayer->source());
768
leDisplayName->setText(rasterLayer->name());
770
//update the debug checkbox
771
cboxShowDebugInfo->setChecked(rasterLayer->getShowDebugOverlayFlag());
773
//update the legend pixmap on this dialog
774
pixmapLegend->setPixmap(rasterLayer->getLegendQPixmap());
775
pixmapLegend->setScaledContents(true);
776
pixmapLegend->repaint(false);
778
//set the palette pixmap
779
pixmapPalette->setPixmap(rasterLayer->getPaletteAsPixmap());
780
pixmapPalette->setScaledContents(true);
781
pixmapPalette->repaint(false);
783
//set the transparency slider
784
sliderTransparency->setValue(255 - rasterLayer->getTransparency());
785
//update the transparency percentage label
786
sliderTransparency_valueChanged(255 - rasterLayer->getTransparency());
787
//decide whether user can change rgb settings
789
switch (rasterLayer->getDrawingStyle())
791
case QgsRasterLayer::SINGLE_BAND_GRAY:
792
rbtnThreeBand->setEnabled(false);
793
rbtnSingleBand->setEnabled(true);
794
rbtnSingleBand->toggle();
796
case QgsRasterLayer::SINGLE_BAND_PSEUDO_COLOR:
797
rbtnThreeBand->setEnabled(false);
798
rbtnSingleBand->setEnabled(true);
799
rbtnSingleBand->toggle();
801
case QgsRasterLayer::PALETTED_SINGLE_BAND_GRAY:
802
rbtnThreeBand->setEnabled(true);
803
rbtnSingleBand->setEnabled(true);
804
rbtnSingleBand->toggle();
806
case QgsRasterLayer::PALETTED_SINGLE_BAND_PSEUDO_COLOR:
807
rbtnThreeBand->setEnabled(true);
808
rbtnSingleBand->setEnabled(true);
809
rbtnSingleBand->toggle();
811
case QgsRasterLayer::PALETTED_MULTI_BAND_COLOR:
812
rbtnThreeBand->setEnabled(true);
813
rbtnSingleBand->setEnabled(true);
814
rbtnThreeBand->toggle();
816
case QgsRasterLayer::MULTI_BAND_SINGLE_BAND_GRAY:
817
rbtnThreeBand->setEnabled(true);
818
rbtnSingleBand->setEnabled(true);
819
rbtnSingleBand->toggle();
821
case QgsRasterLayer::MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR:
822
rbtnThreeBand->setEnabled(true);
823
rbtnSingleBand->setEnabled(true);
824
rbtnSingleBand->toggle();
826
case QgsRasterLayer::MULTI_BAND_COLOR:
827
rbtnThreeBand->setEnabled(true);
828
rbtnSingleBand->setEnabled(true);
829
rbtnThreeBand->toggle();
836
if (rasterLayer->getRasterLayerType() == QgsRasterLayer::MULTIBAND)
838
//multiband images can also be rendered as single band (using only one of the bands)
841
("<h3>Multiband Image Notes</h3><p>This is a multiband image. You can choose to render it as grayscale or color (RGB). For color images, you can associate bands to colors arbitarily. For example, if you have a seven band landsat image, you may choose to render it as:</p><ul><li>Visible Blue (0.45 to 0.52 microns) - not mapped</li><li>Visible Green (0.52 to 0.60 microns) - not mapped</li></li>Visible Red (0.63 to 0.69 microns) - mapped to red in image</li><li>Near Infrared (0.76 to 0.90 microns) - mapped to green in image</li><li>Mid Infrared (1.55 to 1.75 microns) - not mapped</li><li>Thermal Infrared (10.4 to 12.5 microns) - not mapped</li><li>Mid Infrared (2.08 to 2.35 microns) - mapped to blue in image</li></ul>"));
843
else if (rasterLayer->getRasterLayerType() == QgsRasterLayer::PALETTE)
845
//paletted images (e.g. tif) can only be rendered as three band rgb images
848
("<h3>Paletted Image Notes</h3> <p>This image uses a fixed color palette. You can remap these colors in different combinations e.g.</p><ul><li>Red - blue in image</li><li>Green - blue in image</li><li>Blue - green in image</li></ul>"));
850
else //only grayscale settings allowed
852
//grayscale images can only be rendered as singleband
855
("<h3>Grayscale Image Notes</h3> <p>You can remap these grayscale colors to a pseudocolor image using an automatically generated color ramp.</p>"));
860
// Populate the various controls on the form
862
if (rasterLayer->getDrawingStyle() == QgsRasterLayer::SINGLE_BAND_PSEUDO_COLOR ||
863
rasterLayer->getDrawingStyle() == QgsRasterLayer::PALETTED_SINGLE_BAND_PSEUDO_COLOR ||
864
rasterLayer->getDrawingStyle() == QgsRasterLayer::MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR)
866
if(rasterLayer->getColorRampingType()==QgsRasterLayer::BLUE_GREEN_RED)
868
cboColorMap->setCurrentText(tr("Pseudocolor"));
872
cboColorMap->setCurrentText(tr("Freak Out"));
878
cboColorMap->setCurrentText(tr("Grayscale"));
880
//set whether the layer histogram should be inverted
881
if (rasterLayer->getInvertHistogramFlag())
883
cboxInvertColorMap->setChecked(true);
887
cboxInvertColorMap->setChecked(false);
890
double myStdDevsDouble = rasterLayer->getStdDevsToPlot();
891
cboStdDev->setCurrentText(QString::number(myStdDevsDouble));
894
// Set up the sliders on the advanced symbology tab
896
sliderMinRed->setValue(static_cast < int >(rasterLayer->getMinRedDouble()));
897
sliderMaxRed->setValue(static_cast < int >(255 - rasterLayer->getMaxRedDouble()));
898
sliderMinGreen->setValue(static_cast < int >(rasterLayer->getMinGreenDouble()));
899
sliderMaxGreen->setValue(static_cast < int >(255 - rasterLayer->getMaxGreenDouble()));
900
sliderMinBlue->setValue(static_cast < int >(rasterLayer->getMinBlueDouble()));
901
sliderMaxBlue->setValue(static_cast < int >(255 - rasterLayer->getMaxBlueDouble()));
902
sliderMinGray->setValue(static_cast < int >(rasterLayer->getMinGrayDouble()));
903
sliderMaxGray->setValue(static_cast < int >(255 - rasterLayer->getMaxGrayDouble()));
905
//now set the combos to the correct values
906
cboRed->setCurrentText(rasterLayer->getRedBandName());
907
cboGreen->setCurrentText(rasterLayer->getGreenBandName());
908
cboBlue->setCurrentText(rasterLayer->getBlueBandName());
909
cboGray->setCurrentText(rasterLayer->getGrayBandName());
912
// Set up the colour scaling previews
914
makeScalePreview("red");
915
makeScalePreview("green");
916
makeScalePreview("blue");
917
makeScalePreview("gray");
920
} // QgsRasterLayerProperties::sync()
922
void QgsRasterLayerProperties::pbnHistRefresh_clicked()
925
std::cout << "QgsRasterLayerProperties::pbnHistRefresh_clicked" << std::endl;
927
int myBandCountInt = rasterLayer->getBandCount();
929
// Find out how many bands are selected and short circuit out clearing the image
931
int mySelectionCount=0;
932
for (int myIteratorInt = 1;
933
myIteratorInt <= myBandCountInt;
936
RasterBandStats myRasterBandStats = rasterLayer->getRasterBandStats(myIteratorInt);
937
QListBoxItem *myItem = lstHistogramLabels->item( myIteratorInt-1 );
938
if ( myItem->isSelected() )
943
if (mySelectionCount==0)
945
int myImageWidth = pixHistogram->width();
946
int myImageHeight = pixHistogram->height();
947
QPixmap myPixmap(myImageWidth,myImageHeight);
948
myPixmap.fill(Qt::white);
949
pixHistogram->setPixmap(myPixmap);
953
// We use the gdal histogram creation routine is called for each selected
954
// layer. Currently the hist is hardcoded
955
// to create 256 bins. Each bin stores the total number of cells that
956
// fit into the range defined by that bin.
958
// The graph routine below determines the greatest number of pixesl in any given
959
// bin in all selected layers, and the min. It then draws a scaled line between min
960
// and max - scaled to image height. 1 line drawn per selected band
962
const int BINCOUNT = spinHistBinCount->value();
963
enum GRAPH_TYPE { BAR_CHART, LINE_CHART } myGraphType;
964
if (radHistTypeBar->isOn()) myGraphType=BAR_CHART; else myGraphType=LINE_CHART;
965
bool myIgnoreOutOfRangeFlag = chkHistIgnoreOutOfRange->isChecked();
966
bool myThoroughBandScanFlag = chkHistAllowApproximation->isChecked();
968
long myCellCount = rasterLayer->getRasterXDim() * rasterLayer->getRasterYDim();
972
std::cout << "Computing histogram minima and maxima" << std::endl;
974
//somtimes there are more bins than needed
975
//we find out the last on that actully has data in it
976
//so we can discard the rest adn the x-axis scales correctly
977
int myLastBinWithData=0;
979
// First scan through to get max and min cell counts from among selected layers' histograms
985
for (int myIteratorInt = 1;
986
myIteratorInt <= myBandCountInt;
989
RasterBandStats myRasterBandStats = rasterLayer->getRasterBandStats(myIteratorInt);
990
//calculate the x axis min max
991
if (myRasterBandStats.minValDouble < myXAxisMin || myIteratorInt==1)
993
myXAxisMin=static_cast < unsigned int >(myRasterBandStats.minValDouble);
995
if (myRasterBandStats.maxValDouble < myXAxisMax || myIteratorInt==1)
997
myXAxisMax=static_cast < unsigned int >(myRasterBandStats.maxValDouble);
999
QListBoxItem *myItem = lstHistogramLabels->item( myIteratorInt-1 );
1000
if ( myItem->isSelected() )
1003
std::cout << "Ensuring hist is populated for this layer" << std::endl;
1005
rasterLayer->populateHistogram(myIteratorInt,BINCOUNT,myIgnoreOutOfRangeFlag,myThoroughBandScanFlag);
1008
std::cout << "...done..." << myRasterBandStats.histogramVector->size() << " bins filled" << std::endl;
1010
for (int myBin = 0; myBin <BINCOUNT; myBin++)
1012
int myBinValue = myRasterBandStats.histogramVector->at(myBin);
1013
if (myBinValue > 0 && myBin > myLastBinWithData)
1015
myLastBinWithData = myBin;
1018
std::cout << "Testing if " << myBinValue << " is less than " << myYAxisMin << "or greater then " <<myYAxisMax << std::endl;
1022
myYAxisMin = myBinValue;
1023
myYAxisMax = myBinValue;
1026
if (myBinValue > myYAxisMax)
1028
myYAxisMax = myBinValue;
1030
if ( myBinValue < myYAxisMin)
1032
myYAxisMin = myBinValue;
1038
std::cout << "max " << myYAxisMax << std::endl;
1039
std::cout << "min " << myYAxisMin << std::endl;
1043
//create the image onto which graph and axes will be drawn
1044
int myImageWidth = pixHistogram->width();
1045
int myImageHeight = pixHistogram->height();
1046
QPixmap myPixmap(myImageWidth,myImageHeight);
1047
myPixmap.fill(Qt::white);
1048
QPainter myPainter(&myPixmap, this);
1049
//determine labels sizes and draw them
1050
QFont myQFont("arial", 8, QFont::Normal);
1051
QFontMetrics myFontMetrics( myQFont );
1052
myPainter.setFont(myQFont);
1053
myPainter.setPen(Qt::black);
1054
QString myYMaxLabel= QString::number(static_cast < unsigned int >(myYAxisMax));
1055
QString myXMinLabel= QString::number(myXAxisMin);
1056
QString myXMaxLabel= QString::number(myXAxisMax);
1057
//calculate the gutters
1058
int myYGutterWidth=0;
1059
if (myFontMetrics.width(myXMinLabel) < myFontMetrics.width(myYMaxLabel))
1061
myYGutterWidth = myFontMetrics.width(myYMaxLabel )+2; //add 2 so we can have 1 pix whitespace either side of label
1065
myYGutterWidth = myFontMetrics.width(myXMinLabel )+2; //add 2 so we can have 1 pix whitespace either side of label
1067
int myXGutterHeight = myFontMetrics.height()+2;
1068
int myXGutterWidth = myFontMetrics.width(myXMaxLabel)+1;//1 pix whtispace from right edge of image
1071
// Now calculate the graph drawable area after the axis labels have been taken
1074
int myGraphImageWidth =myImageWidth-myYGutterWidth;
1075
int myGraphImageHeight = myImageHeight-myXGutterHeight;
1077
//find out how wide to draw bars when in bar chart mode
1078
int myBarWidth = static_cast<int>((((double)myGraphImageWidth)/((double)BINCOUNT)));
1082
//now draw actual graphs
1084
if (rasterLayer->getRasterLayerType()
1085
== QgsRasterLayer::PALETTE) //paletted layers have hard coded color entries
1087
QPointArray myPointArray(myLastBinWithData);
1088
QgsColorTable *myColorTable=rasterLayer->colorTable(1);
1090
std::cout << "Making paletted image histogram....computing band stats" << std::endl;
1091
std::cout << "myLastBinWithData = " << myLastBinWithData << std::endl;
1094
RasterBandStats myRasterBandStats = rasterLayer->getRasterBandStats(1);
1095
for (int myBin = 0; myBin < myLastBinWithData; myBin++)
1097
double myBinValue = myRasterBandStats.histogramVector->at(myBin);
1099
std::cout << "myBin = " << myBin << " myBinValue = " << myBinValue << std::endl;
1101
//NOTE: Int division is 0 if the numerator is smaller than the denominator.
1103
int myX = static_cast<int>((((double)myGraphImageWidth)/((double)myLastBinWithData))*myBin);
1104
//height varies according to freq. and scaled to greatet value in all layers
1108
myY=static_cast<int>(((double)myBinValue/(double)myYAxisMax)*myGraphImageHeight);
1111
//see wehter to draw something each loop or to save up drawing for after iteration
1112
if (myGraphType==BAR_CHART)
1114
//determin which color to draw the bar
1116
// Take middle of the interval for color
1117
// TODO: this is not precise
1118
double myInterval = (myXAxisMax - myXAxisMin) / myLastBinWithData;
1119
double myMiddle = myXAxisMin + myBin * myInterval + myInterval/2;
1122
std::cout << "myMiddle = " << myMiddle << std::endl;
1125
bool found = myColorTable->color ( myMiddle, &c1, &c2, &c3 );
1127
std::cout << "Color not found" << std::endl;
1128
c1 = c2 = c3 = 180; // grey
1132
std::cout << "c1 = " << c1 << " c2 = " << c2 << " c3 = " << c3 << std::endl;
1136
//QBrush myBrush(QColor(c1,c2,c3));
1137
myPainter.setBrush(QColor(c1,c2,c3));
1138
myPainter.setPen(QColor(c1,c2,c3));
1140
std::cout << "myX = " << myX << " myY = " << myY << std::endl;
1141
std::cout << "rect: " << myX+myYGutterWidth << ", " << myImageHeight-(myY+myXGutterHeight)
1142
<< ", " << myBarWidth << ", " << myY << std::endl;
1144
myPainter.drawRect(myX+myYGutterWidth,myImageHeight-(myY+myXGutterHeight),myBarWidth,myY);
1146
//store this point in our line too
1147
myY = myGraphImageHeight - myY;
1148
myPointArray.setPoint(myBin, myX+myYGutterWidth, myY-myXGutterHeight);
1150
//draw a line on the graph along the bar peaks;
1151
if (myGraphType==LINE_CHART)
1153
myPainter.setPen( Qt::black );
1154
myPainter.drawPolyline(myPointArray);
1160
for (int myIteratorInt = 1;
1161
myIteratorInt <= myBandCountInt;
1164
RasterBandStats myRasterBandStats = rasterLayer->getRasterBandStats(myIteratorInt);
1165
QListBoxItem *myItem = lstHistogramLabels->item( myIteratorInt-1 );
1166
if ( myItem->isSelected() )
1169
QPointArray myPointArray(myLastBinWithData);
1170
for (int myBin = 0; myBin <myLastBinWithData; myBin++)
1172
double myBinValue = myRasterBandStats.histogramVector->at(myBin);
1173
//NOTE: Int division is 0 if the numerator is smaller than the denominator.
1175
int myX = static_cast<int>((((double)myGraphImageWidth)/((double)myLastBinWithData))*myBin);
1176
//height varies according to freq. and scaled to greatet value in all layers
1177
int myY = static_cast<int>(((double)myBinValue/(double)myYAxisMax)*myGraphImageHeight);
1178
//adjust for image origin being top left
1180
std::cout << "-------------" << std::endl;
1181
std::cout << "int myY = (myBinValue/myCellCount)*myGraphImageHeight" << std::endl;
1182
std::cout << "int myY = (" << myBinValue << "/" << myCellCount << ")*" << myGraphImageHeight << std::endl;
1183
std::cout << "Band " << myIteratorInt << ", bin " << myBin << ", Hist Value : " << myBinValue << ", Scaled Value : " << myY << std::endl;
1184
std::cout << "myY = myGraphImageHeight - myY" << std::endl;
1185
std::cout << "myY = " << myGraphImageHeight << "-" << myY << std::endl;
1187
if (myGraphType==BAR_CHART)
1190
if (myBandCountInt==1) //draw single band images with black
1192
myPainter.setPen( Qt::black );
1194
else if (myIteratorInt==1)
1196
myPainter.setPen( Qt::red );
1198
else if (myIteratorInt==2)
1200
myPainter.setPen( Qt::green );
1202
else if (myIteratorInt==3)
1204
myPainter.setPen( Qt::blue );
1206
else if (myIteratorInt==4)
1208
myPainter.setPen( Qt::magenta );
1210
else if (myIteratorInt==5)
1212
myPainter.setPen( Qt::darkRed );
1214
else if (myIteratorInt==6)
1216
myPainter.setPen( Qt::darkGreen );
1218
else if (myIteratorInt==7)
1220
myPainter.setPen( Qt::darkBlue );
1224
myPainter.setPen( Qt::gray );
1227
// std::cout << "myPainter.fillRect(QRect(" << myX << "," << myY << "," << myBarWidth << "," <<myY << ") , myBrush );" << std::endl;
1229
myPainter.drawRect(myX+myYGutterWidth,myImageHeight-(myY+myXGutterHeight),myBarWidth,myY);
1233
myY = myGraphImageHeight - myY;
1234
myPointArray.setPoint(myBin, myX+myYGutterWidth, myY);
1237
if (myGraphType==LINE_CHART)
1239
if (myBandCountInt==1) //draw single band images with black
1241
myPainter.setPen( Qt::black );
1243
else if (myIteratorInt==1)
1245
myPainter.setPen( Qt::red );
1247
else if (myIteratorInt==2)
1249
myPainter.setPen( Qt::green );
1251
else if (myIteratorInt==3)
1253
myPainter.setPen( Qt::blue );
1255
else if (myIteratorInt==4)
1257
myPainter.setPen( Qt::magenta );
1259
else if (myIteratorInt==5)
1261
myPainter.setPen( Qt::darkRed );
1263
else if (myIteratorInt==6)
1265
myPainter.setPen( Qt::darkGreen );
1267
else if (myIteratorInt==7)
1269
myPainter.setPen( Qt::darkBlue );
1273
myPainter.setPen( Qt::gray );
1275
myPainter.drawPolyline(myPointArray);
1282
// Now draw interval markers on the x axis
1284
int myXDivisions = myGraphImageWidth/10;
1285
myPainter.setPen( Qt::gray );
1286
for (int i=0;i<myXDivisions;++i)
1288
QPointArray myPointArray(4);
1289
myPointArray.setPoint(0,(i*myXDivisions)+myYGutterWidth , myImageHeight-myXGutterHeight);
1290
myPointArray.setPoint(1,(i*myXDivisions)+myYGutterWidth , myImageHeight-(myXGutterHeight-5));
1291
myPointArray.setPoint(2,(i*myXDivisions)+myYGutterWidth , myImageHeight-myXGutterHeight);
1292
myPointArray.setPoint(3,((i+1)*myXDivisions)+myYGutterWidth , myImageHeight-myXGutterHeight);
1293
myPainter.drawPolyline(myPointArray);
1296
// Now draw interval markers on the y axis
1298
int myYDivisions = myGraphImageHeight/10;
1299
myPainter.setPen( Qt::gray );
1300
for (int i=myYDivisions;i>0;--i)
1303
QPointArray myPointArray(4);
1304
int myYOrigin = myImageHeight-myXGutterHeight;
1305
myPointArray.setPoint(0,myYGutterWidth,myYOrigin-(i*myYDivisions ));
1306
myPointArray.setPoint(1,myYGutterWidth-5,myYOrigin-(i*myYDivisions ));
1307
myPointArray.setPoint(2,myYGutterWidth,myYOrigin-(i*myYDivisions ));
1308
myPointArray.setPoint(3,myYGutterWidth,myYOrigin-((i-1)*myYDivisions ));
1309
myPainter.drawPolyline(myPointArray);
1312
//now draw the axis labels onto the graph
1313
myPainter.drawText(1, 12, myYMaxLabel);
1314
myPainter.drawText(1, myImageHeight-myXGutterHeight, QString::number(static_cast < unsigned int >(myYAxisMin)));
1315
myPainter.drawText(myYGutterWidth,myImageHeight-1 , myXMinLabel);
1316
myPainter.drawText( myImageWidth-myXGutterWidth,myImageHeight-1, myXMaxLabel );
1322
pixHistogram->setPixmap(myPixmap);
1325
void QgsRasterLayerProperties::pbnChangeSpatialRefSys_clicked()
1329
QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector(this);
1330
long myDefaultSRS = rasterLayer->coordinateTransform()->sourceSRS().srsid();
1331
if (myDefaultSRS==0)
1333
myDefaultSRS=QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectSRSID",GEOSRS_ID);
1335
mySelector->setSelectedSRSID(myDefaultSRS);
1336
if(mySelector->exec())
1338
rasterLayer->coordinateTransform()->sourceSRS().createFromSrsId(mySelector->getCurrentSRSID());
1339
rasterLayer->coordinateTransform()->initialise();
1343
QApplication::restoreOverrideCursor();
1346
leSpatialRefSys->setText(rasterLayer->coordinateTransform()->sourceSRS().proj4String());