28 #include "../../common/Logger.h"
29 #include "../../common/progress/ProgressManager.h"
30 #include "../../dataaccess/dataset/DataSet.h"
31 #include "../../dataaccess/dataset/DataSetType.h"
32 #include "../../dataaccess/dataset/DataSetTypeConverter.h"
33 #include "../../dataaccess/datasource/DataSourceCapabilities.h"
34 #include "../../dataaccess/datasource/DataSourceInfo.h"
35 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
36 #include "../../dataaccess/datasource/DataSourceFactory.h"
37 #include "../../dataaccess/datasource/DataSourceManager.h"
38 #include "../../dataaccess/utils/Utils.h"
40 #include "../../maptools/AbstractLayer.h"
42 #include "../../qt/widgets/help/HelpPushButton.h"
43 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
44 #include "../../qt/widgets/layer/search/LayerSearchWidget.h"
45 #include "../../qt/widgets/layer/search/LayerSearchWizardPage.h"
46 #include "../../qt/widgets/layer/utils/DataSet2Layer.h"
48 #include "../Config.h"
49 #include "../Exception.h"
54 #include "../GeometricOp.h"
55 #include "../GeometricOpMemory.h"
56 #include "../GeometricOpQuery.h"
63 #include <QMessageBox>
66 #include <boost/filesystem.hpp>
67 #include <boost/uuid/random_generator.hpp>
68 #include <boost/uuid/uuid_io.hpp>
74 this->setWizardStyle(QWizard::ModernStyle);
75 this->setWindowTitle(tr(
"Geometric Operation"));
77 this->setOption(QWizard::HaveHelpButton,
true);
78 this->setOption(QWizard::HelpButtonOnRight,
false);
82 this->setButton(QWizard::HelpButton, helpButton);
96 if(currentPage() == m_layerSearchPage.get())
98 std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
100 if(list.empty() ==
false)
103 m_geomOpPage->setLayer(l);
106 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
107 std::vector<te::dt::Property*> vecProp = dsType->getProperties();
108 std::vector<std::string> vecPropName;
110 for(std::size_t i = 0; i < vecProp.size(); ++i)
113 vecPropName.push_back(vecProp[i]->getName());
116 m_geomOpOutputPage->setAttributes(vecPropName);
119 return m_layerSearchPage->isComplete();
121 else if(currentPage() == m_geomOpOutputPage.get())
123 if(!m_geomOpOutputPage->getToFile())
125 if(!m_geomOpOutputPage->getDsInfoPtr())
127 QMessageBox::information(
this,
128 "Basic Geographic Operation",
129 "Set the output data source before execute the operation.");
132 if(m_geomOpOutputPage->getOutDsName() ==
"")
134 QMessageBox::information(
this,
135 "Basic Geographic Operation",
136 "Set a Name for the output dataset before execute the operation.");
149 m_layerSearchPage->getSearchWidget()->setList(layerList);
150 m_layerSearchPage->getSearchWidget()->filterOnlyByGeom();
155 removePage(m_layerSearchId);
156 m_geomOpPage->setLayer(layer);
175 m_layerSearchId = addPage(m_layerSearchPage.get());
176 addPage(m_geomOpPage.get());
177 addPage(m_geomOpOutputPage.get());
180 m_layerSearchPage->getSearchWidget()->enableMultiSelection(
false);
199 if(m_geomOpOutputPage->hasConvexHull())
202 if(m_geomOpOutputPage->hasCentroid())
205 if(m_geomOpOutputPage->hasMBR())
208 if(m_geomOpOutputPage->hasArea())
211 if(m_geomOpOutputPage->hasLine())
214 if(m_geomOpOutputPage->hasPerimeter())
218 std::vector<std::string> geoProps = m_geomOpPage->getSelectedProps();
220 std::string outputdataset = m_geomOpOutputPage->getOutDsName();
221 std::vector<std::string> outputDSetNames;
224 m_attribute = m_geomOpOutputPage->getAttribute();
227 if(m_geomOpOutputPage->getToFile())
229 boost::filesystem::path uri(m_geomOpOutputPage->getPath());
231 bool ops_selected =
false;
233 if(m_geomOpOutputPage->hasConvexHull())
235 boost::filesystem::path uri_file(m_geomOpOutputPage->getPath() +
"/" + outputdataset +
"_convex_hull.shp");
236 if (boost::filesystem::exists(uri_file))
238 QMessageBox::information(
this,
"Geographic Operation",
"The convex hull output file already exists. Remove it or select a new name and try again.");
244 if(m_geomOpOutputPage->hasCentroid())
246 boost::filesystem::path uri_file(m_geomOpOutputPage->getPath() +
"/" + outputdataset +
"_centroid.shp");
247 if (boost::filesystem::exists(uri_file))
249 QMessageBox::information(
this,
"Geographic Operation",
"The centroid output file already exists. Remove it or select a new name and try again.");
255 if(m_geomOpOutputPage->hasMBR())
257 boost::filesystem::path uri_file(m_geomOpOutputPage->getPath() +
"/" + outputdataset +
"_mbr.shp");
258 if (boost::filesystem::exists(uri_file))
260 QMessageBox::information(
this,
"Geographic Operation",
"The mbr output file already exists. Remove it or select a new name and try again.");
268 boost::filesystem::path uri_file(m_geomOpOutputPage->getPath() +
"/" + outputdataset +
".shp");
269 if (boost::filesystem::exists(uri_file))
271 QMessageBox::information(
this,
"Geographic Operation",
"Output file already exists. Remove it or select a new name and try again.");
276 std::size_t idx = outputdataset.find(
".");
278 if (idx != std::string::npos)
279 outputdataset=outputdataset.substr(0,idx);
281 std::map<std::string, std::string> dsinfo;
282 dsinfo[
"URI"] = uri.string();
283 dsinfo[
"DRIVER"] =
"ESRI Shapefile";
286 dsOGR->setConnectionInfo(dsinfo);
288 if (dsOGR->dataSetExists(outputdataset))
290 QMessageBox::information(
this,
"Basic Geographic Operation",
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again.");
297 this->setCursor(Qt::WaitCursor);
318 m_geomOpOutputPage->getObjectStrategy(),
320 m_geomOpOutputPage->hasOutputLayer());
325 result = geomOp->
run();
329 this->setCursor(Qt::ArrowCursor);
330 QMessageBox::information(
this,
"Geometric Operation",
"Error: could not generate the operation, check the log file.");
339 boost::uuids::basic_random_generator<boost::mt19937> gen;
340 boost::uuids::uuid u = gen();
341 std::string
id = boost::uuids::to_string(u);
344 ds->setConnInfo(dsinfo);
345 ds->setTitle(uri.stem().string());
346 ds->setAccessDriver(
"OGR");
348 ds->setDescription(uri.string());
354 m_outputDatasource = ds;
358 m_outputDatasource = m_geomOpOutputPage->getDsInfoPtr();
360 trgDs->setConnectionInfo(m_outputDatasource->getConnInfo());
365 QMessageBox::information(
this,
"Geometric Operation",
"The selected output datasource can not be accessed.");
369 if (trgDs->dataSetExists(outputdataset))
371 QMessageBox::information(
this,
"Geometric Operation",
"Dataset already exists. Remove it or select a new name and try again.");
378 this->setCursor(Qt::WaitCursor);
398 m_geomOpOutputPage->getObjectStrategy(),
400 m_geomOpOutputPage->hasOutputLayer());
405 result = geomOp->
run();
409 this->setCursor(Qt::ArrowCursor);
410 QMessageBox::information(
this,
"Geometric Operation",
"Error: could not generate the operation.");
423 for(std::size_t i = 0; i < outputDSetNames.size(); ++i)
427 m_outLayer.push_back(converter(dt));
430 catch(
const std::exception& e)
432 this->setCursor(Qt::ArrowCursor);
433 QMessageBox::information(
this,
"Greographic Operation", e.what());
435 #ifdef TERRALIB_LOGGER_ENABLED
436 std::string str =
"Greographic Operation - ";
438 te::common::Logger::logDebug(
"vp", str.c_str());
446 this->setCursor(Qt::ArrowCursor);
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
const std::string & getDataSetName() const
std::vector< std::string > GetOutputDSetNames()
boost::shared_ptr< DataSetType > DataSetTypePtr
The geographic operation Line.
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
The geographic operation Minimum Bounding Rectangle.
void setLayer(te::map::AbstractLayerPtr layer)
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::auto_ptr< te::da::DataSetTypeConverter > converter)
virtual bool validateCurrentPage()
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
This class is GUI used to define the basic geometric operator parameters for the VP operation...
const QueryCapabilities & getQueryCapabilities() const
An converter for DataSetType.
The geographic operation Area.
void removeViewer(int viewerId)
Dettach a progress viewer.
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
const std::string & getDataSourceId() const
static std::auto_ptr< DataSource > make(const std::string &dsType)
A Qt dialog that allows users to run the basic geometric operations defined by VP module...
The geographic operation Perimeter.
bool supportsSpatialSQLDialect() const
void setOutput(std::auto_ptr< te::da::DataSource > outDsrc, std::string dsname)
The geographic operation Centroid.
std::vector< te::map::AbstractLayerPtr > getOutLayer()
This file defines a class for Basic Geometric Operation Wizard Page.
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
bool supportsPreparedQueryAPI() const
virtual bool paramsAreValid()
te::map::AbstractLayerPtr getInLayer()
The geographic operation Convex Hull.
A class that represents a data source component.
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
A layer with reference to a dataset.
std::auto_ptr< LayerSchema > getSchema() const
It returns the layer schema.
void setParams(std::vector< std::string > selectedProps, std::vector< te::vp::GeometricOperation > operations, te::vp::GeometricOpObjStrategy objStrategy, std::string attribute, bool outputLayer)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
GeometricOpWizard(QWidget *parent)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr