27 #include "../../../../common/Config.h"
28 #include "../../../../common/Logger.h"
29 #include "../../../../common/Translator.h"
30 #include "../../../../srs/Config.h"
31 #include "../../../../srs/SpatialReferenceSystemManager.h"
32 #include "../../../../dataaccess/dataset/DataSetType.h"
33 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
34 #include "../../../../dataaccess/datasource/DataSourceManager.h"
35 #include "../../../../dataaccess/utils/Utils.h"
36 #include "../../../../maptools/AbstractLayer.h"
37 #include "../../../widgets/layer/utils/DataSet2Layer.h"
38 #include "../../../widgets/datasource/core/DataSourceTypeManager.h"
39 #include "../../../widgets/Utils.h"
40 #include "../../../af/ApplicationController.h"
41 #include "../../../af/Project.h"
42 #include "../../../af/Utils.h"
43 #include "../../../af/events/LayerEvents.h"
49 #include <ogrsf_frmts.h>
52 #include <boost/uuid/random_generator.hpp>
53 #include <boost/uuid/uuid_io.hpp>
54 #include <boost/filesystem.hpp>
59 #include <QApplication>
60 #include <QFileDialog>
62 #include <QMessageBox>
66 std::list<te::da::DataSetTypePtr> res;
72 std::vector<std::string> dsets = ds->getDataSetNames();
74 std::vector<std::string>::iterator it;
76 for(it = dsets.begin(); it != dsets.end(); ++it)
84 std::list<te::map::AbstractLayerPtr> res;
92 if(type.compare(
"ESRI Shapefile") == 0)
93 return QObject::tr(
"ESRI Shapefile (*.shp *.SHP)");
94 else if(type.compare(
"MapInfo File") == 0)
95 return QObject::tr(
"MapInfo File (*.mif *.MIF)");
96 else if(type.compare(
"DGN") == 0)
97 return QObject::tr(
"DGN File (*.dgn *.DGN)");
100 else if(type.compare(
"GML") == 0)
101 return QObject::tr(
"GML File (*.gml *.GML)");
102 else if(type.compare(
"KML") == 0)
103 return QObject::tr(
"KML File (*.kml *.KML)");
104 else if(type.compare(
"GeoJSON") == 0)
105 return QObject::tr(
"GeoJSON File (*.geojson *.GEOJSON)");
106 else if(type.compare(
"DXF") == 0)
107 return QObject::tr(
"DXF File (*.dxf *.DXF)");
115 OGRSFDriverRegistrar* dMgr = OGRSFDriverRegistrar::GetRegistrar();
117 int count = dMgr->GetDriverCount();
119 for(
int i=0; i<count; i++)
121 std::string dName = dMgr->GetDriver(i)->GetName();
152 m_initialized =
true;
158 if(act != 0 && mnu != 0)
160 QWidget* parent = act->parentWidget();
161 m_showWindow =
new QAction(QIcon::fromTheme(
"file-vector"), tr(
"Vector File..."), parent);
162 m_showWindow->setObjectName(
"Project.Add Layer.Vector File");
163 mnu->insertAction(act, m_showWindow);
168 connect (m_showWindow, SIGNAL(triggered()), SLOT(showWindow()));
184 m_initialized =
false;
202 if(fileNames.isEmpty())
205 QApplication::setOverrideCursor(Qt::WaitCursor);
207 QFileInfo info(fileNames.value(0));
212 std::map<std::string, std::string> shpWithoutSpatialIndex;
214 std::list<te::map::AbstractLayerPtr> layers;
216 bool hasErrors =
false;
217 QString errorMsg = tr(
"Error occurred trying to create layer(s):\n\n");
219 for(QStringList::iterator it = fileNames.begin(); it != fileNames.end(); ++it)
223 ds->setAccessDriver(
"OGR");
225 std::string fpath = it->toStdString();
226 std::map<std::string, std::string> dsinfo;
227 dsinfo[
"URI"] = fpath;
229 ds->setConnInfo(dsinfo);
231 std::string desc(
"A single vector file: ");
233 ds->setDescription(desc);
235 boost::filesystem::path mpath(dsinfo[
"URI"]);
237 std::string fileBaseName = mpath.leaf().string();
239 ds->setTitle(fileBaseName);
243 boost::uuids::basic_random_generator<boost::mt19937> gen;
244 boost::uuids::uuid u = gen();
245 std::string
id = boost::uuids::to_string(u);
253 QString datasetName(fileBaseName.c_str());
254 datasetName.remove(
".shp", Qt::CaseInsensitive);
255 shpWithoutSpatialIndex[id] = datasetName.toStdString();
265 errorMsg.append(
" - ");
266 errorMsg.append(fileBaseName.c_str());
267 errorMsg.append(
"\n");
270 catch (std::exception& e)
273 errorMsg.append(
" - ");
274 errorMsg.append(fileBaseName.c_str());
275 errorMsg.append(
"\n");
279 QApplication::restoreOverrideCursor();
286 if(!shpWithoutSpatialIndex.empty())
289 tr(
"Spatial Index"), tr(
"Do you want create spatial index to the selected ESRI ShapeFiles?"),
290 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
292 QApplication::setOverrideCursor(Qt::WaitCursor);
294 std::map<std::string, std::string>::iterator it;
295 for(it = shpWithoutSpatialIndex.begin(); it != shpWithoutSpatialIndex.end(); ++it)
299 std::string command =
"CREATE SPATIAL INDEX ON " + it->second;
301 driver->execute(command);
304 QApplication::restoreOverrideCursor();
316 if(selectedLayers.size() == 1 && selectedLayers.front()->getType() ==
"FOLDERLAYER")
317 parentLayer = selectedLayers.front();
319 std::list<te::map::AbstractLayerPtr>::iterator it;
320 for(it = layers.begin(); it != layers.end(); ++it)
326 QString msgErr(tr(
"Layer %1 has SRID %2 that is not recognized by TerraLib. Setting it to unknown."));
327 msgErr = msgErr.arg((*it)->getTitle().c_str());
328 msgErr = msgErr.arg((*it)->getSRID());
331 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.
#define TE_LOG_TRACE(msg)
Use this tag in order to log a message to a specified logger with the TRACE level.
This event signals that a new layer was created.
Utility functions for the data access module.
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::shared_ptr< DataSource > DataSourcePtr
bool IsShapeFile(const QString &path)
void GetLayers(const te::da::DataSourceInfoPtr &info, std::list< te::map::AbstractLayerPtr > &layers)
#define TE_TR(message)
It marks a string in order to get translated.
#define PLUGIN_CALL_BACK_IMPL(PLUGIN_CLASS_NAME)
This macro should be used by C++ plugins in order to declare the exportable/callable DLL function...
TEQTAFEXPORT void AddActionToCustomToolbars(QAction *act)
Check QSettings for existance of act and adds it if necessary.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
~Plugin()
Virtual destructor.
void shutdown()
Do nothing! Just set plugin as stopped.
void startup()
Do nothing! Just set plugin as started.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
This class models the concept of a project for the TerraLib Application Framework.
A class that represents a data source component.
QString GetSupportedFiles()
The basic information about a plugin.
QString GetFileExtensionName(const std::string &type)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
Plugin implementation for the OGR data source widget.
bool HasShapeFileSpatialIndex(const QString &path)
Plugin(const te::plugin::PluginInfo &pluginInfo)
std::list< te::da::DataSetTypePtr > GetDataSetsInfo(const te::da::DataSourceInfoPtr &info)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr