27 #include "../../../../dataaccess/dataset/DataSetType.h" 28 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h" 29 #include "../../../../dataaccess/datasource/DataSourceManager.h" 30 #include "../../../../dataaccess/utils/Utils.h" 31 #include "../../../../maptools/AbstractLayer.h" 32 #include "../../../../srs/SpatialReferenceSystemManager.h" 33 #include "../../../widgets/layer/utils/DataSet2Layer.h" 34 #include "../../../af/ApplicationController.h" 35 #include "../../../af/events/LayerEvents.h" 39 #include <QApplication> 42 #include <QMessageBox> 48 #include <boost/uuid/random_generator.hpp> 49 #include <boost/uuid/uuid_io.hpp> 50 #include <boost/filesystem.hpp> 54 std::list<te::da::DataSetTypePtr> res;
60 std::vector<std::string> dsets = ds->getDataSetNames();
62 std::vector<std::string>::iterator it;
64 for (it = dsets.begin(); it != dsets.end(); ++it)
72 std::list<te::map::AbstractLayerPtr> res;
80 QFileInfo fileInfo(path);
82 if(!fileInfo.isFile())
85 if(fileInfo.suffix().toLower() ==
"shp")
95 QFileInfo fileInfo(path);
98 QString fileName = fileInfo.fileName();
101 QDir dir(fileInfo.absolutePath());
104 QString qixFile = fileName;
105 qixFile.replace(
".shp",
".qix");
106 if(dir.exists(qixFile))
110 QString sbnFile = fileName;
111 sbnFile.replace(
".shp",
".sbn");
112 if(dir.exists(sbnFile))
120 QApplication::setOverrideCursor(Qt::WaitCursor);
123 std::map<std::string, std::string> shpWithoutSpatialIndex;
125 bool hasErrors =
false;
126 QString errorMsg = QObject::tr(
"Error occurred trying to create layer(s):\n\n");
128 for (QStringList::iterator it = fileNames.begin(); it != fileNames.end(); ++it)
132 ds->setAccessDriver(
"OGR");
134 std::string fpath = it->toUtf8().data();
136 ds->setConnInfo(
"file://" + fpath);
138 std::string desc(
"A single vector file: ");
140 ds->setDescription(desc);
142 boost::filesystem::path mpath(fpath);
144 std::string fileBaseName = mpath.leaf().string();
146 ds->setTitle(fileBaseName);
150 boost::uuids::basic_random_generator<boost::mt19937> gen;
151 boost::uuids::uuid u = gen();
152 std::string
id = boost::uuids::to_string(u);
162 QString datasetName(fileBaseName.c_str());
163 datasetName.remove(
".shp", Qt::CaseInsensitive);
164 shpWithoutSpatialIndex[id] = datasetName.toUtf8().data();
174 errorMsg.append(
" - ");
175 errorMsg.append(fileBaseName.c_str());
176 errorMsg.append(
"\n");
179 catch (std::exception&)
182 errorMsg.append(
" - ");
183 errorMsg.append(fileBaseName.c_str());
184 errorMsg.append(
"\n");
188 QApplication::restoreOverrideCursor();
197 if (!shpWithoutSpatialIndex.empty())
200 QObject::tr(
"Spatial Index"), QObject::tr(
"Do you want create spatial index to the selected ESRI ShapeFiles?"),
201 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
203 QApplication::setOverrideCursor(Qt::WaitCursor);
205 std::map<std::string, std::string>::iterator it;
206 for (it = shpWithoutSpatialIndex.begin(); it != shpWithoutSpatialIndex.end(); ++it)
214 std::string command =
"CREATE SPATIAL INDEX ON " + it->second;
216 driver->execute(command);
218 QApplication::restoreOverrideCursor();
224 QApplication::restoreOverrideCursor();
227 catch (std::exception&)
231 QApplication::restoreOverrideCursor();
239 std::list<te::map::AbstractLayerPtr>::iterator it;
240 for (it = layers.begin(); it != layers.end(); ++it)
246 QString msgErr(QObject::tr(
"Layer %1 has SRID %2 that is not recognized by TerraLib. Setting it to unknown."));
247 msgErr = msgErr.arg((*it)->getTitle().c_str());
248 msgErr = msgErr.arg((*it)->getSRID());
251 QObject::tr(
"Layer SRS check"), msgErr);
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::shared_ptr< DataSource > DataSourcePtr
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
This event signals that a list of layers have been created.
bool IsShapeFile(const QString &path)
std::list< te::da::DataSetTypePtr > GetDataSetsInfo(const te::da::DataSourceInfoPtr &info)
static te::dt::Date ds(2010, 01, 01)
void CreateLayers(QStringList fileNames, std::list< te::map::AbstractLayerPtr > &layers)
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
Utility functions for the data access module.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A class that represents a data source component.
void GetLayers(const te::da::DataSourceInfoPtr &info, std::list< te::map::AbstractLayerPtr > &layers)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
bool HasShapeFileSpatialIndex(const QString &path)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr