27 #include "../../../../common/Config.h"
28 #include "../../../../common/Translator.h"
29 #include "../../../../common/Logger.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();
134 te::plugin::
Plugin(pluginInfo),
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;
194 if(fileNames.isEmpty())
197 QApplication::setOverrideCursor(Qt::WaitCursor);
199 QFileInfo info(fileNames.value(0));
204 std::map<std::string, std::string> shpWithoutSpatialIndex;
206 std::list<te::map::AbstractLayerPtr> layers;
208 for(QStringList::iterator it = fileNames.begin(); it != fileNames.end(); ++it)
212 ds->setAccessDriver(
"OGR");
214 std::string fpath = it->toStdString();
215 std::map<std::string, std::string> dsinfo;
216 dsinfo[
"URI"] = fpath;
218 ds->setConnInfo(dsinfo);
220 std::string desc(
"A single vector file: ");
222 ds->setDescription(desc);
224 boost::filesystem::path mpath(dsinfo[
"URI"]);
226 std::string fileBaseName = mpath.leaf().string();
228 ds->setTitle(fileBaseName);
232 boost::uuids::basic_random_generator<boost::mt19937> gen;
233 boost::uuids::uuid u = gen();
234 std::string
id = boost::uuids::to_string(u);
241 QString datasetName(fileBaseName.c_str());
242 datasetName.remove(
".shp", Qt::CaseInsensitive);
243 shpWithoutSpatialIndex[id] = datasetName.toStdString();
249 QApplication::restoreOverrideCursor();
251 if(!shpWithoutSpatialIndex.empty())
254 tr(
"Spatial Index"), tr(
"Do you want create spatial index to the selected ESRI ShapeFiles?"),
255 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
257 QApplication::setOverrideCursor(Qt::WaitCursor);
259 std::map<std::string, std::string>::iterator it;
260 for(it = shpWithoutSpatialIndex.begin(); it != shpWithoutSpatialIndex.end(); ++it)
264 std::string command =
"CREATE SPATIAL INDEX ON " + it->second;
266 driver->execute(command);
269 QApplication::restoreOverrideCursor();
281 if(selectedLayers.size() == 1 && selectedLayers.front()->getType() ==
"FOLDERLAYER")
282 parentLayer = selectedLayers.front();
284 std::list<te::map::AbstractLayerPtr>::iterator it;
285 for(it = layers.begin(); it != layers.end(); ++it)
291 QString msgErr(tr(
"Layer %1 has SRID %2 that is not recognized by TerraLib. Setting it to unknown."));
292 msgErr = msgErr.arg((*it)->getTitle().c_str());
293 msgErr = msgErr.arg((*it)->getSRID());
296 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.
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