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)
151 m_initialized =
true;
157 if(act != 0 && mnu != 0)
159 QWidget* parent = act->parentWidget();
160 m_showWindow =
new QAction(QIcon::fromTheme(
"file-vector"), tr(
"Vector File..."), parent);
161 m_showWindow->setObjectName(
"Project.Add Layer.Vector File");
162 mnu->insertAction(act, m_showWindow);
167 connect (m_showWindow, SIGNAL(triggered()), SLOT(showWindow()));
183 m_initialized =
false;
193 if(fileNames.isEmpty())
196 QFileInfo info(fileNames.value(0));
201 std::map<std::string, std::string> shpWithoutSpatialIndex;
203 std::list<te::map::AbstractLayerPtr> layers;
205 for(QStringList::iterator it = fileNames.begin(); it != fileNames.end(); ++it)
209 ds->setAccessDriver(
"OGR");
211 std::string fpath = it->toStdString();
212 std::map<std::string, std::string> dsinfo;
213 dsinfo[
"URI"] = fpath;
215 ds->setConnInfo(dsinfo);
217 std::string desc(
"A single vector file: ");
219 ds->setDescription(desc);
221 boost::filesystem::path mpath(dsinfo[
"URI"]);
223 std::string fileBaseName = mpath.leaf().string();
225 ds->setTitle(fileBaseName);
229 boost::uuids::basic_random_generator<boost::mt19937> gen;
230 boost::uuids::uuid u = gen();
231 std::string
id = boost::uuids::to_string(u);
238 QString datasetName(fileBaseName.c_str());
239 datasetName.remove(
".shp", Qt::CaseInsensitive);
240 shpWithoutSpatialIndex[id] = datasetName.toStdString();
246 if(!shpWithoutSpatialIndex.empty())
249 tr(
"Spatial Index"), tr(
"Do you want create spatial index to the selected ESRI ShapeFiles?"),
250 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
252 QApplication::setOverrideCursor(Qt::WaitCursor);
254 std::map<std::string, std::string>::iterator it;
255 for(it = shpWithoutSpatialIndex.begin(); it != shpWithoutSpatialIndex.end(); ++it)
259 std::string command =
"CREATE SPATIAL INDEX ON " + it->second;
261 driver->execute(command);
264 QApplication::restoreOverrideCursor();
276 if(selectedLayers.size() == 1 && selectedLayers.front()->getType() ==
"FOLDERLAYER")
277 parentLayer = selectedLayers.front();
279 std::list<te::map::AbstractLayerPtr>::iterator it;
280 for(it = layers.begin(); it != layers.end(); ++it)
286 QString msgErr(tr(
"Layer %1 has SRID %2 that is not recognized by TerraLib. Setting it to unknown."));
287 msgErr = msgErr.arg((*it)->getTitle().c_str());
288 msgErr = msgErr.arg((*it)->getSRID());
291 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