3 #include "SpatialPlotTool.h"
7 #include <geos/geom/Polygon.h>
8 #include <geos/geom/CoordinateArraySequence.h>
9 #include <geos/geom/Point.h>
11 #include <QHBoxLayout>
13 #include <QStackedWidget>
30 #include "RubberBandComboBox.h"
31 #include "RubberBandTool.h"
87 QString text =
"<b>Function:</b> Create a spatial plot of the selected pixels' DN values.";
113 Interpolator::NearestNeighborType);
115 Interpolator::BiLinearType);
117 Interpolator::CubicConvolutionType);
126 QHBoxLayout *layout =
new QHBoxLayout(wrapper);
127 layout->setMargin(0);
129 layout->addWidget(
new QLabel(
"Interpolation:"));
131 layout->addWidget(abstractToolWidgets);
132 layout->addWidget(m_xUnitsCombo);
133 layout->addStretch(1);
134 wrapper->setLayout(layout);
149 m_xUnitsCombo->currentIndex()).
toInt();
151 while (m_xUnitsCombo->count())
152 m_xUnitsCombo->removeItem(0);
156 bool haveGroundMaps =
true;
161 if (haveGroundMaps) {
166 if (m_xUnitsCombo->findData(preferredUnits) != -1) {
167 m_xUnitsCombo->setCurrentIndex(
168 m_xUnitsCombo->findData(preferredUnits));
171 m_xUnitsCombo->setVisible(m_xUnitsCombo->count() > 1);
184 m_xUnitsCombo->currentIndex()).
toInt(),
211 if (rubberBandTool()->isValid()) {
215 QMessageBox::information(NULL,
"Error",
216 "The selected Area contains no valid pixels",
229 if (activeViewport && rubberBandTool()->isValid()) {
235 m_xUnitsCombo->itemData(m_xUnitsCombo->currentIndex()).
toInt()) {
244 if (data.size() > 0) {
250 (*m_spatialCurves)[viewport]->setData(
new QwtPointSeriesData(data));
251 (*m_spatialCurves)[viewport]->setSource(
252 viewport, rubberBandPoints, band);
271 m_xUnitsCombo->currentIndex()).
toInt();
273 QPen spatialPen(Qt::white);
274 spatialPen.setWidth(1);
275 spatialPen.setStyle(Qt::SolidLine);
283 targetWindow->
add(plotCurve);
322 m_xUnitsCombo->currentIndex()).
toInt();
324 if (cvp && vertices.size()) {
335 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode) {
336 double startSample =
Null;
337 double endSample =
Null;
338 double startLine =
Null;
339 double endLine =
Null;
342 startSample, startLine);
347 int lineLength = qRound(sqrt(pow(startSample - endSample, 2) +
348 pow(startLine - endLine, 2)));
353 if (groundMap->
SetImage(startSample, startLine)) {
354 startPoint = resultToSurfacePoint(groundMap);
357 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
358 tr(
"Failed to project points along line"),
359 tr(
"Failed to project (calculate a latitude, longitude, and radius) for the "
360 "starting point of the line (sample [%1], line [%2]).")
361 .arg(startSample).arg(startLine));
366 if (lineLength > 0) {
367 for(
int index = 0; index <= lineLength; index++) {
369 double sample = (index / (double)lineLength) * (endSample - startSample) +
372 sample -= (interp.
Samples() / 2.0 - 0.5);
374 double line = (index / (double)lineLength) * (endLine - startLine) +
376 line -= (interp.
Lines() / 2.0 - 0.5);
378 dataReader.SetPosition(sample, line, band);
381 double result = interp.
Interpolate(sample + 0.5, line + 0.5, dataReader.DoubleBuffer());
384 double plotXValue = index + 1;
389 if (groundMap->
SetImage(sample, line)) {
393 plotXValue = xDistance.
meters();
398 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
399 tr(
"Failed to project points along line"),
400 tr(
"Failed to project (calculate a latitude, longitude, and radius) for a "
401 "point along the line (sample [%1], line [%2]).")
402 .arg(startSample).arg(startLine));
407 data.append(QPointF(plotXValue, result));
412 QMessageBox::information(NULL,
"Error",
413 "The selected Area contains no valid pixels",
417 else if (rubberBandTool()->currentMode() == RubberBandTool::RotatedRectangleMode) {
447 double clickSample =
Null;
448 double clickLine =
Null;
449 double acrossSample =
Null;
450 double acrossLine =
Null;
451 double endSample =
Null;
452 double endLine =
Null;
455 clickSample, clickLine);
457 acrossSample, acrossLine);
461 double acrossVectorX = acrossSample - clickSample;
462 double acrossVectorY = acrossLine - clickLine;
464 int acrossLength = qRound(sqrt(acrossVectorX * acrossVectorX +
465 acrossVectorY * acrossVectorY));
466 double sampleStepAcross = (1.0 / (double)acrossLength) * acrossVectorX;
467 double lineStepAcross = (1.0 / (double)acrossLength) * acrossVectorY;
469 double lengthVectorSample = endSample - clickSample;
470 double lengthVectorLine = endLine - clickLine;
471 int rectangleLength = qRound(sqrt(lengthVectorSample * lengthVectorSample +
472 lengthVectorLine * lengthVectorLine));
477 double midStartSample = (clickSample + acrossSample) / 2.0;
478 double midStartLine = (clickLine + acrossLine) / 2.0;
479 if (groundMap->
SetImage(midStartSample, midStartLine)) {
480 startPoint = resultToSurfacePoint(groundMap);
483 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
484 tr(
"Failed to project points along line"),
485 tr(
"Failed to project (calculate a latitude, longitude, and radius) for the "
486 "starting point of the line (sample [%1], line [%2]).")
487 .arg(midStartSample).arg(midStartLine));
493 for(
int index = 0; index <= rectangleLength; index++) {
497 double sample = (index / (double)rectangleLength) * lengthVectorSample +
500 sample -= (interp.
Samples() / 2.0 - 0.5);
502 double line = (index / (double)rectangleLength) * lengthVectorLine +
504 line -= (interp.
Lines() / 2.0 - 0.5);
506 double sampleMid = sample + (acrossLength / 2.0) * sampleStepAcross;
507 double lineMid = line + (acrossLength / 2.0) * lineStepAcross;
509 for(
int acrossPixel = 0;
510 acrossPixel <= acrossLength;
512 dataReader.SetPosition(sample, line, band);
514 double pixelValue = interp.
Interpolate(sample + 0.5, line + 0.5,
515 dataReader.DoubleBuffer());
518 acrossStats.
AddData(pixelValue);
521 sample += sampleStepAcross;
522 line += lineStepAcross;
526 double plotXValue = index + 1;
529 if (groundMap->
SetImage(sampleMid, lineMid)) {
533 plotXValue = xDistance.
meters();
538 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
539 tr(
"Failed to project points along line"),
540 tr(
"Failed to project (calculate a latitude, longitude, and radius) for a "
541 "point along the line (sample [%1], line [%2]).")
542 .arg(sampleMid).arg(lineMid));
547 data.append(QPointF(plotXValue, acrossStats.
Average()));