All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CreateCellularSpaceDialog.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/qt/widgets/connector/cellspace/CreateCellularSpaceDialog.cpp
22 
23  \brief ....
24 */
25 
26 // TerraLib
27 #include "../../../cellspace/CellSpaceOperations.h"
28 #include "../../../common/Exception.h"
29 #include "../../../common/progress/ProgressManager.h"
30 #include "../../../common/StringUtils.h"
31 #include "../../../common/Translator.h"
32 #include "../../../common/UnitsOfMeasureManager.h"
33 #include "../../../dataaccess/datasource/DataSource.h"
34 #include "../../../dataaccess/datasource/DataSourceFactory.h"
35 #include "../../../dataaccess/datasource/DataSourceInfoManager.h"
36 #include "../../../dataaccess/datasource/DataSourceTransactor.h"
37 #include "../../../dataaccess/datasource/DataSourceManager.h"
38 #include "../../../dataaccess/utils/Utils.h"
39 #include "../../../qt/widgets/layer/utils/DataSet2Layer.h"
40 #include "../../../qt/widgets/help/HelpPushButton.h"
41 #include "../../../qt/widgets/progress/ProgressViewerDialog.h"
42 #include "../../../qt/widgets/srs/SRSManagerDialog.h"
43 #include "../../../srs/SpatialReferenceSystemManager.h"
44 #include "../../widgets/datasource/selector/DataSourceSelectorDialog.h"
45 #include "ui_CreateCellularSpaceDialogForm.h"
47 
48 // Qt
49 #include <QFileDialog>
50 #include <QMessageBox>
51 #include <QToolButton>
52 
53 // Boost
54 #include <boost/filesystem.hpp>
55 #include <boost/uuid/random_generator.hpp>
56 #include <boost/uuid/uuid_io.hpp>
57 
60 
62  : QDialog(parent, f),
63  m_currentSRID(4618),
64  m_isFile(false),
65  m_outputDataSetName(""),
66  m_ui(new Ui::CreateCellularSpaceDialogForm)
67 {
68 // add controls
69  m_ui->setupUi(this);
70 
71 // Set icons
72  m_ui->m_maskToolButton->setIcon(QIcon::fromTheme("cellspace-mask-hint"));
73  m_ui->m_noMaskToolButton->setIcon(QIcon::fromTheme("cellspace-no-mask-hint"));
74  m_ui->m_polygonsToolButton->setIcon(QIcon::fromTheme("cellspace-polygons-hint"));
75  m_ui->m_pointsToolButton->setIcon(QIcon::fromTheme("cellspace-points-hint"));
76  m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme("datasource"));
77  m_ui->m_srsToolButton->setIcon(QIcon::fromTheme("srs"));
78 
79 // Set validators
80  m_ui->m_llxLineEdit->setValidator(new QDoubleValidator(this));
81  m_ui->m_llyLineEdit->setValidator(new QDoubleValidator(this));
82  m_ui->m_urxLineEdit->setValidator(new QDoubleValidator(this));
83  m_ui->m_uryLineEdit->setValidator(new QDoubleValidator(this));
84  m_ui->m_resXLineEdit->setValidator(new QDoubleValidator(0, 99999999, 8, this));
85  m_ui->m_resYLineEdit->setValidator(new QDoubleValidator(0, 99999999, 8, this));
86  m_ui->m_rowsLineEdit->setValidator(new QIntValidator(this));
87  m_ui->m_colsLineEdit->setValidator(new QIntValidator(this));
88 
90 
91  connect(m_ui->m_layersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onLayersComboBoxChanged(int)));
92  connect(m_ui->m_unitComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onUnitComboBoxChanged(int)));
93 
94  connect(m_ui->m_resXLineEdit, SIGNAL(editingFinished()), this, SLOT(onResXLineEditEditingFinished()));
95  connect(m_ui->m_resYLineEdit, SIGNAL(editingFinished()), this, SLOT(onResYLineEditEditingFinished()));
96  connect(m_ui->m_colsLineEdit, SIGNAL(editingFinished()), this, SLOT(onColsLineEditEditingFinished()));
97  connect(m_ui->m_rowsLineEdit, SIGNAL(editingFinished()), this, SLOT(onRowsLineEditEditingFinished()));
98  connect(m_ui->m_llxLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(onEnvelopeChanged(const QString &)));
99  connect(m_ui->m_llyLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(onEnvelopeChanged(const QString &)));
100  connect(m_ui->m_urxLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(onEnvelopeChanged(const QString &)));
101  connect(m_ui->m_uryLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(onEnvelopeChanged(const QString &)));
102 
103  connect(m_ui->m_targetFileToolButton, SIGNAL(clicked()), this, SLOT(onTargetFileToolButtonClicked()));
104  connect(m_ui->m_targetDatasourceToolButton, SIGNAL(clicked()), this, SLOT(onTargetDatasourceToolButtonClicked()));
105  connect(m_ui->m_createPushButton, SIGNAL(clicked()), this, SLOT(onCreatePushButtonClicked()));
106  connect(m_ui->m_referenceGroupBox, SIGNAL(toggled(bool)), this, SLOT(onReferenceGroupBoxToggled(bool)));
107  connect(m_ui->m_srsToolButton, SIGNAL(clicked()), this, SLOT(onSrsToolButtonClicked()));
108 
109  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
110  m_ui->m_helpPushButton->setPageReference("plugins/cellspace/cellspace.html");
111 }
112 
114 {
115 }
116 
117 void te::qt::plugins::cellspace::CreateCellularSpaceDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
118 {
119  if(layers.empty())
120  {
121  m_ui->m_srsToolButton->setEnabled(true);
122  m_ui->m_referenceGroupBox->setChecked(false);
123  m_ui->m_referenceGroupBox->setEnabled(false);
124  showSRS();
125  return;
126  }
127 
128  std::vector<std::string> nonSridLayers;
129  bool hasNonSridLayer = false;
130 
131  std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
132 
133  while(it != layers.end())
134  {
135  if(it->get()->getSRID() > 0)
136  {
137  std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
138  if(dsType->hasGeom())
139  m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant::fromValue(*it));
140  }
141  else
142  {
143  nonSridLayers.push_back(it->get()->getTitle());
144  hasNonSridLayer = true;
145  }
146  ++it;
147  }
148 
149  if(hasNonSridLayer)
150  {
151  QString w(tr("Some Layers were not added because they have no SRID:"));
152  w.append("\n");
153  for(std::size_t i = 0; i < nonSridLayers.size(); ++i)
154  w.append(nonSridLayers[i].c_str()).append("\n");
155  QMessageBox::warning(this, tr("Cellular Spaces"), w);
156  }
157 
158  if(nonSridLayers.size() == layers.size())
159  {
160  m_ui->m_srsToolButton->setEnabled(true);
161  m_ui->m_referenceGroupBox->setChecked(false);
162  m_ui->m_referenceGroupBox->setEnabled(false);
163  showSRS();
164  return;
165  }
166 
167  te::map::AbstractLayerPtr layer = getReferenceLayer();
168  m_currentSRID = layer->getSRID();
169  showSRS();
170 }
171 
173 {
174  te::map::AbstractLayerPtr layer = getReferenceLayer();
175 
176  if(!layer)
177  return;
178 
179  te::gm::Envelope env = layer->getExtent();
180  showEnvelope(env);
181 
182  m_currentSRID = layer->getSRID();
183 
184  showSRS();
185 
187 
188  m_ui->m_sridLabel->setText(te::srs::SpatialReferenceSystemManager::getInstance().getName(m_currentSRID).c_str());
189 
190  if(!unit.get())
191  {
192  // METRE
193  m_ui->m_unitComboBox->setCurrentIndex(1);
194  }
195  else
196  {
197  setCurrentUnit(unit);
198  }
199 }
200 
202 {
203  double resX = getResX();
204 
205  te::gm::Envelope env = getOutputEnvelope();
206 
207  if(!env.isValid())
208  {
209  QMessageBox::warning(this, tr("Cellular Spaces"), tr("Invalid envelope!"));
210  return;
211  }
212 
213 int maxCols = (int)ceil((env.m_urx - env.m_llx)/resX);
214 
215  m_ui->m_colsLineEdit->setText(QString::number(maxCols));
216 }
217 
219 {
220  double resY = getResY();
221 
222  te::gm::Envelope env = getOutputEnvelope();
223 
224  if(!env.isValid())
225  {
226  QMessageBox::warning(this, tr("Cellular Spaces"), tr("Invalid envelope!"));
227  return;
228  }
229 
230  int maxRows = (int)ceil((env.m_ury - env.m_lly)/resY);
231 
232  m_ui->m_rowsLineEdit->setText(QString::number(maxRows));
233 }
234 
236 {
237  int cols = m_ui->m_colsLineEdit->text().toInt();
238 
239  te::gm::Envelope env = getOutputEnvelope();
240 
241  if(!env.isValid())
242  {
243  QMessageBox::warning(this, tr("Cellular Spaces"), tr("Invalid envelope!"));
244  return;
245  }
246 
247  double resX = (env.m_urx - env.m_llx)/cols;
248 
249  te::map::AbstractLayerPtr layer = getReferenceLayer();
250 
252  te::common::UnitOfMeasurePtr currentUnit = getCurrentUnit();
253 
254  if(layer)
255  {
256  layerUnit = te::srs::SpatialReferenceSystemManager::getInstance().getUnit(layer->getSRID());
257  }
258  else
259  {
260  layerUnit = te::srs::SpatialReferenceSystemManager::getInstance().getUnit(m_currentSRID);
261  }
262 
263  if(layerUnit != currentUnit)
264  {
265  try
266  {
267  double factorX = te::common::UnitsOfMeasureManager::getInstance().getConversion(layerUnit->getName(), currentUnit->getName());
268  resX = resX/factorX;
269  }
270  catch(te::common::Exception& /*e*/)
271  {
272  clearResolution();
273  }
274  }
275 
276  m_ui->m_resXLineEdit->setText(QString::number(resX));
277 }
278 
280 {
281  int rows = m_ui->m_rowsLineEdit->text().toInt();
282 
283  te::gm::Envelope env = getOutputEnvelope();
284 
285  if(!env.isValid())
286  {
287  QMessageBox::warning(this, tr("Cellular Spaces"), tr("Invalid envelope!"));
288  return;
289  }
290 
291  double resY = (env.m_ury - env.m_lly)/rows;
292 
293  te::map::AbstractLayerPtr layer = getReferenceLayer();
294 
296  te::common::UnitOfMeasurePtr currentUnit = getCurrentUnit();
297 
298  if(layer)
299  {
300  layerUnit = te::srs::SpatialReferenceSystemManager::getInstance().getUnit(layer->getSRID());
301  }
302  else
303  {
304  layerUnit = te::srs::SpatialReferenceSystemManager::getInstance().getUnit(m_currentSRID);
305  }
306 
307  if(layerUnit != currentUnit)
308  {
309  try
310  {
311  double factorY = te::common::UnitsOfMeasureManager::getInstance().getConversion(layerUnit->getName(), currentUnit->getName());
312  resY = resY/factorY;
313  }
314  catch(te::common::Exception& /*e*/)
315  {
316  clearResolution();
317  }
318  }
319 
320  m_ui->m_resYLineEdit->setText(QString::number(resY));
321 }
322 
324 {
325  clearResolution();
326 }
327 
329 {
330  std::string errors;
331  if(!checkList(errors))
332  {
333  QMessageBox::warning(this, tr("Cellular Spaces"), errors.c_str());
334  return;
335  }
336 
337  m_outputDataSetName = m_ui->m_newLayerNameLineEdit->text().toStdString();
338 
339  te::map::AbstractLayerPtr referenceLayer;
340 
341  if(!isNoReference())
342  referenceLayer = getReferenceLayer();
343 
344  double resX = getResX();
345  double resY = getResY();
346  bool isPolygonsAsMask = m_ui->m_maskToolButton->isChecked();
347 
348  std::auto_ptr<te::cellspace::CellularSpacesOperations> cellSpaceOp(new te::cellspace::CellularSpacesOperations());
349 
351 
352  if(m_ui->m_polygonsToolButton->isChecked())
353  {
355  }
356  else if(m_ui->m_pointsToolButton->isChecked())
357  {
359  }
360 
361  //progress
364 
365  try
366  {
367  if(isNoReference())
368  cellSpaceOp->createCellSpace(m_outDataSourceInfo, m_outputDataSetName, resX, resY, getEnvelope(), m_currentSRID, type);
369  else
370  cellSpaceOp->createCellSpace(m_outDataSourceInfo, m_outputDataSetName, referenceLayer, resX, resY, isPolygonsAsMask, type);
371  }
372  catch(te::common::Exception& e)
373  {
375  this->setCursor(Qt::ArrowCursor);
376  QMessageBox::warning(this, tr("Cellular Spaces"), e.what());
377  reject();
378  return;
379  }
380 
382  this->setCursor(Qt::ArrowCursor);
383 
384  accept();
385 }
386 
388 {
389  m_ui->m_newLayerNameLineEdit->clear();
390  m_ui->m_repositoryLineEdit->clear();
391 
392  QString extension;
393 
394  std::string accessDriver;
395 
396  extension = tr("Shapefile (*.shp *.SHP);;");
397  accessDriver = "OGR";
398 
399  QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."),
400  QString(), extension, 0, QFileDialog::DontConfirmOverwrite);
401 
402  if (fileName.isEmpty())
403  return;
404 
405  boost::filesystem::path outfile(fileName.toStdString());
406  std::string aux = outfile.leaf().string();
407  m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
408  aux = outfile.string();
409  m_ui->m_repositoryLineEdit->setText(aux.c_str());
410 
411  m_isFile = true;
412 
413  m_ui->m_newLayerNameLineEdit->setEnabled(false);
414 
415  std::map<std::string, std::string> connInfo;
416  connInfo["URI"] = m_ui->m_repositoryLineEdit->text().toStdString();
417 
418  m_outDataSourceInfo.reset(new te::da::DataSourceInfo);
419 
420  m_outDataSourceInfo->setAccessDriver(accessDriver);
421  m_outDataSourceInfo->setConnInfo(connInfo);
422 }
423 
425 {
426  m_ui->m_newLayerNameLineEdit->clear();
427  m_ui->m_repositoryLineEdit->clear();
428 
430  dlg.exec();
431 
432  std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.getSelecteds();
433 
434  if(dsPtrList.size() <= 0)
435  return;
436 
437  std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
438 
439  m_outDataSourceInfo = *it;
440 
441  m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
442 
443  m_isFile = false;
444 
445  m_ui->m_newLayerNameLineEdit->setEnabled(true);
446 }
447 
449 {
450  te::map::AbstractLayerPtr layer = getReferenceLayer();
451 
453  te::common::UnitOfMeasurePtr currentUnit = getCurrentUnit();
454 
455  if(layer)
456  {
457  layerUnit = te::srs::SpatialReferenceSystemManager::getInstance().getUnit(layer->getSRID());
458  }
459  else
460  {
461  layerUnit = te::srs::SpatialReferenceSystemManager::getInstance().getUnit(m_currentSRID);
462  }
463 
464  if(layerUnit != currentUnit)
465  {
466  if (!te::common::UnitsOfMeasureManager::getInstance().areConvertible(layerUnit->getName(), currentUnit->getName()))
467  {
468  QMessageBox::warning(this, tr("Cellular Spaces"), tr("Unable to convert between the measuring unit of the layer projection and the selected!"));
469  clearResolution();
470  }
471  }
472 
473  clearResolution();
474 }
475 
477 {
480  while (it != itend)
481  {
482  te::common::UnitOfMeasurePtr uptr = it->second;
483  m_ui->m_unitComboBox->addItem(uptr->getName().c_str(), QVariant::fromValue(uptr));
484  ++it;
485  }
486 
487  if(m_currentSRID > 0)
488  {
490  setCurrentUnit(unit);
491  }
492  else
493  {
494  m_ui->m_unitComboBox->setCurrentIndex(1);
495  }
496 }
497 
499 {
500  te::gm::Envelope env;
501 
502  env.m_llx = m_ui->m_llxLineEdit->text().toDouble();
503  env.m_lly = m_ui->m_llyLineEdit->text().toDouble();
504  env.m_urx = m_ui->m_urxLineEdit->text().toDouble();
505  env.m_ury = m_ui->m_uryLineEdit->text().toDouble();
506 
507  return env;
508 }
509 
511 {
512  char txt[40];
513  sprintf(txt,"%.8g",env.m_llx);
514  m_ui->m_llxLineEdit->setText(QString(txt));
515  sprintf(txt,"%.8g",env.m_lly);
516  m_ui->m_llyLineEdit->setText(QString(txt));
517  sprintf(txt,"%.8g",env.m_urx);
518  m_ui->m_urxLineEdit->setText(QString(txt));
519  sprintf(txt,"%.8g",env.m_ury);
520  m_ui->m_uryLineEdit->setText(QString(txt));
521 }
522 
524 {
525  te::gm::Envelope env;
526 
527  env.m_llx = m_ui->m_llxLineEdit->text().toDouble();
528  env.m_lly = m_ui->m_llyLineEdit->text().toDouble();
529  env.m_urx = m_ui->m_urxLineEdit->text().toDouble();
530  env.m_ury = m_ui->m_uryLineEdit->text().toDouble();
531 
532  return env;
533 }
534 
536 {
537  QVariant varLayer = m_ui->m_layersComboBox->itemData(m_ui->m_layersComboBox->currentIndex(), Qt::UserRole);
538  return varLayer.value<te::map::AbstractLayerPtr>();
539 }
540 
542 {
543  QVariant varUnit = m_ui->m_unitComboBox->itemData(m_ui->m_unitComboBox->currentIndex(), Qt::UserRole);
544  return varUnit.value<te::common::UnitOfMeasurePtr>();
545 }
546 
548 {
549  for(int i = 0; i < m_ui->m_unitComboBox->count(); ++i)
550  {
551  std::string name = m_ui->m_unitComboBox->itemText(i).toStdString();
552 
553  if(unit->getName() == name)
554  {
555  m_ui->m_unitComboBox->setCurrentIndex(i);
556  break;
557  }
558  }
559 }
560 
562 {
563  bool noErrors = true;
564 
565  std::string name = m_ui->m_newLayerNameLineEdit->text().toStdString();
566  te::map::AbstractLayerPtr referenceLayer = getReferenceLayer();
567  double resX = m_ui->m_resXLineEdit->text().toDouble();
568  double resY = m_ui->m_resYLineEdit->text().toDouble();
569 
570  errors = tr("Some information is missing:").toStdString();
571 
572  if(name.empty())
573  {
574  errors += "\n - " + tr("Output name").toStdString();
575  noErrors = false;
576  }
577 
578  if(m_currentSRID <= 0)
579  {
580  errors += "\n - " + tr("Projection").toStdString();
581  noErrors = false;
582  }
583 
584  te::gm::Envelope env = getOutputEnvelope();
585 
586  if(!env.isValid())
587  {
588  errors += "\n - " + tr("Invalid envelope").toStdString();
589  noErrors = false;
590  }
591 
592  double lWidth = env.getWidth();
593  double lHeight = env.getHeight();
594 
595  if (resX < 0. || resX >= lWidth)
596  {
597  char txt[40];
598  sprintf(txt,"%.8g",lWidth);
599  errors += "\n - " + tr("Resolution in X must be > 0 and < ").toStdString() + txt;
600  noErrors = false;
601  }
602 
603  if (resY < 0. || resY >= lHeight)
604  {
605  char txt[40];
606  sprintf(txt,"%.8g",lHeight);
607  errors += "\n - " + tr("Resolution in X must be > 0 and < ").toStdString() + txt;
608  noErrors = false;
609  }
610 
611  return noErrors;
612 }
613 
615 {
616  if(m_isFile)
617  {
618  // let's include the new datasource in the managers
619  boost::uuids::basic_random_generator<boost::mt19937> gen;
620  boost::uuids::uuid u = gen();
621  std::string id_ds = boost::uuids::to_string(u);
622 
623  boost::filesystem::path uri(m_outDataSourceInfo->getConnInfo()["URI"]);
624 
626  ds->setConnInfo(m_outDataSourceInfo->getConnInfo());
627  ds->setTitle(uri.stem().string());
628  ds->setAccessDriver("OGR");
629  ds->setType("OGR");
630  ds->setDescription(uri.string());
631  ds->setId(id_ds);
632 
633  te::da::DataSourcePtr newds = te::da::DataSourceManager::getInstance().get(id_ds, "OGR", ds->getConnInfo());
634  newds->open();
636  m_outDataSourceInfo = ds;
637 
638  m_outputDataSetName = uri.stem().string();
639  }
640 
641  te::da::DataSourcePtr outDataSource = te::da::GetDataSource(m_outDataSourceInfo->getId());
642 
643  // Inserido devido a erro indeterminado na criação do layer
644  outDataSource->open();
645  //-----
646 
647  te::qt::widgets::DataSet2Layer converter(m_outDataSourceInfo->getId());
648 
649  te::da::DataSetTypePtr dt(outDataSource->getDataSetType(m_outputDataSetName).release());
650 
651  te::map::AbstractLayerPtr layer = converter(dt);
652 
653  if(isNoReference() || layer->getSRID() <= 0)
654  layer->setSRID(m_currentSRID);
655 
656  return layer;
657 }
658 
660 {
661  te::qt::widgets::SRSManagerDialog srsDialog(this);
662  srsDialog.setWindowTitle(tr("Choose the SRS"));
663 
664  if(srsDialog.exec() == QDialog::Rejected)
665  return;
666 
667  m_currentSRID = srsDialog.getSelectedSRS().first;
668 
669  showSRS();
670 
672 
673  setCurrentUnit(unit);
674 
675  clearEnvelope();
676  clearResolution();
677 }
678 
680 {
681  m_ui->m_llxLineEdit->clear();
682  m_ui->m_llyLineEdit->clear();
683  m_ui->m_urxLineEdit->clear();
684  m_ui->m_uryLineEdit->clear();
685 }
686 
688 {
689  m_ui->m_resXLineEdit->clear();
690  m_ui->m_resYLineEdit->clear();
691  m_ui->m_colsLineEdit->clear();
692  m_ui->m_rowsLineEdit->clear();
693 }
694 
696 {
697  std::string name = te::srs::SpatialReferenceSystemManager::getInstance().getName(m_currentSRID);
698 
699  m_ui->m_sridLabel->setText(name.c_str());
700 }
701 
703 {
704  double resX = m_ui->m_resXLineEdit->text().toDouble();
705 
706  te::map::AbstractLayerPtr layer = getReferenceLayer();
707 
709  te::common::UnitOfMeasurePtr currentUnit = getCurrentUnit();
710 
711  if(layer)
712  {
713  layerUnit = te::srs::SpatialReferenceSystemManager::getInstance().getUnit(layer->getSRID());
714  }
715  else
716  {
717  layerUnit = te::srs::SpatialReferenceSystemManager::getInstance().getUnit(m_currentSRID);
718  }
719 
720  if(layerUnit != currentUnit)
721  {
722  try
723  {
724  double factorX = te::common::UnitsOfMeasureManager::getInstance().getConversion(layerUnit->getName(), currentUnit->getName());
725  resX = resX/factorX;
726  }
727  catch(te::common::Exception& /*e*/)
728  {
729  clearResolution();
730  }
731  }
732 
733  return resX;
734 }
735 
737 {
738  double resY = m_ui->m_resYLineEdit->text().toDouble();
739 
740  te::map::AbstractLayerPtr layer = getReferenceLayer();
741 
743  te::common::UnitOfMeasurePtr currentUnit = getCurrentUnit();
744 
745  if(layer)
746  {
747  layerUnit = te::srs::SpatialReferenceSystemManager::getInstance().getUnit(layer->getSRID());
748  }
749  else
750  {
751  layerUnit = te::srs::SpatialReferenceSystemManager::getInstance().getUnit(m_currentSRID);
752  }
753 
754  if(layerUnit != currentUnit)
755  {
756  try
757  {
758  double factorY = te::common::UnitsOfMeasureManager::getInstance().getConversion(layerUnit->getName(), currentUnit->getName());
759  resY = resY/factorY;
760  }
761  catch(te::common::Exception& /*e*/)
762  {
763  clearResolution();
764  }
765  }
766 
767  return resY;
768 }
769 
771 {
772  m_ui->m_srsToolButton->setEnabled(!isToggled);
773 
774  if(!isToggled)
775  {
776  clearEnvelope();
777  clearResolution();
778  }
779  else
780  {
781  onLayersComboBoxChanged(0);
782  }
783 }
784 
786 {
787  if(m_ui->m_referenceGroupBox->isChecked())
788  return false;
789  else
790  return true;
791 }
const_iterator begin() const
It returns an iterator to the beginning of the conteiner.
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
Definition: Utils.cpp:262
This class provide cellular spaces operations.
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
virtual const char * what() const
It outputs the exception message.
Definition: Exception.cpp:58
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
const_iterator end() const
It returns an iterator to the end of the conteiner.
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
void removeViewer(int viewerId)
Dettach a progress viewer.
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
std::map< unsigned int, UnitOfMeasurePtr >::const_iterator const_iterator
double getConversion(const std::string &unitFromName, const std::string &unitToName) const
Calculates a multiplicative factor to convert from a given unit to its base unit and vice-versa...
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
boost::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
A dialog for selecting a data source.
A class that represents a data source component.
A dialog used to build a SRSManagerDialog element.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
const std::pair< int, std::string > & getSelectedSRS() const
Returns the selected SRS in the window.
bool isValid() const
It tells if the rectangle is valid or not.
Definition: Envelope.h:438
std::auto_ptr< Ui::CreateCellularSpaceDialogForm > m_ui
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
CreateCellularSpaceDialog(QWidget *parent=0, Qt::WindowFlags f=0)