27 #include "../../../../core/translator/Translator.h" 28 #include "../../../../core/uri/URI.h" 29 #include "../../../../core/uri/Utils.h" 30 #include "../../../../dataaccess/datasource/DataSource.h" 31 #include "../../../../dataaccess/datasource/DataSourceFactory.h" 32 #include "../../../../dataaccess/datasource/DataSourceInfo.h" 33 #include "../../../../dataaccess/datasource/DataSourceManager.h" 34 #include "../../../af/Utils.h" 35 #include "../../../widgets/Exception.h" 36 #include "../../../widgets/Utils.h" 38 #include "ui_OGRConnectorDialogForm.h" 42 #include <boost/uuid/random_generator.hpp> 43 #include <boost/uuid/uuid_io.hpp> 44 #include <boost/filesystem.hpp> 45 #include <boost/lexical_cast.hpp> 49 #include <QFileDialog> 50 #include <QMessageBox> 57 m_ui(new
Ui::OGRConnectorDialogForm)
67 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
68 m_ui->m_helpPushButton->setPageReference(
"plugins/ogr/ogr.html");
91 m_ui->m_datasourceTitleLineEdit->setText(QString::fromUtf8(
m_datasource->getTitle().c_str()));
93 m_ui->m_datasourceDescriptionTextEdit->setText(QString::fromUtf8(
m_datasource->getDescription().c_str()));
103 throw te::qt::widgets::Exception(
TE_TR(
"Sorry! No data access driver loaded for OGR data sources!"));
114 throw te::qt::widgets::Exception(
TE_TR(
"Could not open dataset via OGR due to an unknown error!"));
116 QString title =
m_ui->m_datasourceTitleLineEdit->text().trimmed();
119 title =
m_ui->m_featureRepoLineEdit->text();
128 boost::uuids::basic_random_generator<boost::mt19937> gen;
129 boost::uuids::uuid u = gen();
130 std::string dsId = boost::uuids::to_string(u);
135 m_datasource->setDescription(
m_ui->m_datasourceDescriptionTextEdit->toPlainText().toUtf8().data());
144 m_datasource->setDescription(
m_ui->m_datasourceDescriptionTextEdit->toPlainText().trimmed().toUtf8().data());
147 if(
m_ui->m_fileRadioButton->isChecked())
149 QString path =
m_ui->m_featureRepoLineEdit->text().trimmed();
152 if(QMessageBox::question(
this, windowTitle(), tr(
"Do you want create spatial index to the selected ESRI ShapeFile?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
154 std::vector<std::string> datasetNames =
m_driver->getDataSetNames();
155 assert(!datasetNames.empty());
157 std::string command =
"CREATE SPATIAL INDEX ON " + datasetNames[0];
159 QApplication::setOverrideCursor(Qt::WaitCursor);
163 QApplication::restoreOverrideCursor();
165 QMessageBox::information(
this, windowTitle(),
"Spatial index created with successfully!");
170 catch(
const std::exception& e)
172 QMessageBox::warning(
this,
173 tr(
"TerraLib Qt Components"),
179 QMessageBox::warning(
this,
180 tr(
"TerraLib Qt Components"),
181 tr(
"Unknown error while opening feature via OGR!"));
194 throw te::qt::widgets::Exception(
TE_TR(
"Sorry! No data access driver loaded for OGR data sources!"));
200 if(ds.get() ==
nullptr)
201 throw te::qt::widgets::Exception(
TE_TR(
"Could not open feature repository via OGR!"));
203 if (
m_ui->m_dirRadioButton->isChecked() && ds->getNumberOfDataSets() <= 0)
204 QMessageBox::information(
this,
205 tr(
"TerraLib Qt Components"),
206 tr(
"Directory does not contain datasets!"));
208 QMessageBox::information(
this,
209 tr(
"TerraLib Qt Components"),
210 tr(
"Data source is ok!"));
212 catch(
const std::exception& e)
214 QMessageBox::warning(
this,
215 tr(
"TerraLib Qt Components"),
220 QMessageBox::warning(
this,
221 tr(
"TerraLib Qt Components"),
222 tr(
"Unknown error while testing OGR data source!"));
228 if(
m_ui->m_fileRadioButton->isChecked())
230 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open Vector File"),
231 te::qt::widgets::GetFilePathFromSettings(
"vector"), tr(
"Esri Shapefile (*.shp *.SHP);; Mapinfo File (*.mif *.MIF);; GeoJSON (*.geojson *.GeoJSON);; GML (*.gml *.GML);; KML (*.kml *.KML);; All Files (*.*)"),
232 nullptr, QFileDialog::ReadOnly);
234 if(fileName.isEmpty())
237 QFileInfo info(fileName);
241 m_ui->m_featureRepoLineEdit->setText(fileName);
243 else if(
m_ui->m_dirRadioButton->isChecked())
245 QString dirName = QFileDialog::getExistingDirectory(
this, tr(
"Select a directory with shape files"),
248 if(dirName.isEmpty())
253 m_ui->m_featureRepoLineEdit->setText(dirName);
257 QMessageBox::warning(
this,
258 tr(
"TerraLib Qt Components"),
259 tr(
"Sorry, network files are not implemented yet!\nWe will provide it soon!"));
267 std::string strURI =
"file://";
269 qstr =
m_ui->m_featureRepoLineEdit->text().trimmed();
272 throw te::qt::widgets::Exception(
TE_TR(
"Please select a feature file first!"));
274 strURI += qstr.toUtf8().data();
286 m_ui->m_featureRepoLineEdit->setText(QString::fromUtf8(path.c_str()));
288 if(boost::filesystem::is_directory(path))
289 m_ui->m_dirRadioButton->setChecked(
true);
290 else if(boost::filesystem::is_regular_file(path))
291 m_ui->m_fileRadioButton->setChecked(
true);
const te::da::DataSourcePtr & getDriver() const
std::string path() const
Retrieving the path.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
static bool find(const std::string &dsType)
boost::shared_ptr< DataSource > DataSourcePtr
const std::string getConnectionInfo() const
bool IsShapeFile(const QString &path)
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
te::da::DataSourceInfoPtr m_datasource
void openPushButtonPressed()
const te::da::DataSourceInfoPtr & getDataSource() const
std::string host() const
Retrieving the host.
std::unique_ptr< Ui::OGRConnectorDialogForm > m_ui
A dialog window for showing the OGR connector widget.
A class for representing an Uniform Resource Identifier (URI).
void set(const te::da::DataSourceInfoPtr &ds)
This file contains utility functions used to manipulate data from a URI.
A class that represents a data source component.
void testPushButtonPressed()
void searchFeatureToolButtonPressed()
TECOREEXPORT std::string URIDecode(const std::string &srcUri)
Decodes an encoded URI. The algorithm implementation is based on http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm.
te::da::DataSourcePtr m_driver
OGRConnectorDialog(QWidget *parent=0, Qt::WindowFlags f=0)
bool HasShapeFileSpatialIndex(const QString &path)
void setConnectionInfo(const std::string &connInfo)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr