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>
57 #include <QtCore/QFileInfo>
58 #include <QtGui/QAction>
59 #include <QtGui/QApplication>
60 #include <QtGui/QFileDialog>
61 #include <QtGui/QMenu>
62 #include <QtGui/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)
154 m_initialized =
true;
160 if(act != 0 && mnu != 0)
162 QWidget* parent = act->parentWidget();
163 m_showWindow =
new QAction(QIcon::fromTheme(
"file-vector"), tr(
"Vector File..."), parent);
164 m_showWindow->setObjectName(
"Project.Add Layer.Vector File");
165 mnu->insertAction(act, m_showWindow);
170 connect (m_showWindow, SIGNAL(triggered()), SLOT(showWindow()));
186 m_initialized =
false;
196 if(fileNames.isEmpty())
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 if(!shpWithoutSpatialIndex.empty())
252 tr(
"Spatial Index"), tr(
"Do you want create spatial index to the selected ESRI ShapeFiles?"),
253 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
255 QApplication::setOverrideCursor(Qt::WaitCursor);
257 std::map<std::string, std::string>::iterator it;
258 for(it = shpWithoutSpatialIndex.begin(); it != shpWithoutSpatialIndex.end(); ++it)
262 std::string command =
"CREATE SPATIAL INDEX ON " + it->second;
264 driver->execute(command);
267 QApplication::restoreOverrideCursor();
279 if(selectedLayers.size() == 1 && selectedLayers.front()->getType() ==
"FOLDERLAYER")
280 parentLayer = selectedLayers.front();
282 std::list<te::map::AbstractLayerPtr>::iterator it;
283 for(it = layers.begin(); it != layers.end(); ++it)
289 QString msgErr(tr(
"Layer %1 has SRID %2 that is not recognized by TerraLib. Setting it to unknown."));
290 msgErr = msgErr.arg((*it)->getTitle().c_str());
291 msgErr = msgErr.arg((*it)->getSRID());
294 tr(
"Layer SRS check"), msgErr);
The basic information about a plugin.
QMenu * findMenu(const QString &id) const
Returns the menu registered with key id.
#define TE_QT_PLUGIN_DATASOURCE_OGR_TEXT_DOMAIN
It contains the name of the text domain used in the translation of messages in TerraLib OGR driver im...
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
std::list< te::da::DataSetTypePtr > GetDataSetsInfo(const te::da::DataSourceInfoPtr &info)
TEQTWIDGETSEXPORT QString GetFilePathFromSettings(const QString &typeFile)
Returns the value of the last saved file path for the typeFile required.
A class that represents a data source component.
TEQTWIDGETSEXPORT void AddFilePathToSettings(const QString &path, const QString &typeFile)
Save last used path in QSettings.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Plugin implementation for the OGR data source widget.
static ApplicationController & getInstance()
It gives access to the controller singleton.
Plugin(const te::plugin::PluginInfo &pluginInfo)
#define TE_LOG_TRACE(msg)
Use this tag in order to log a message to a specified logger with the TRACE level.
void shutdown()
Do nothing! Just set plugin as stopped.
This event signals that a new layer was created.
bool HasShapeFileSpatialIndex(const QString &path)
#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...
Utility functions for the data access module.
boost::shared_ptr< DataSource > DataSourcePtr
void GetLayers(const te::da::DataSourceInfoPtr &info, std::list< te::map::AbstractLayerPtr > &layers)
#define TE_ADD_TEXT_DOMAIN(domain, domaindir, codeset)
It adds the given text domain located at domain-dir with the given codeset to the multilingual system...
#define TE_QT_PLUGIN_DATASOURCE_OGR_TEXT_DOMAIN_DIR
It contains the translation catalog directory.
bool IsShapeFile(const QString &path)
QString GetSupportedFiles()
#define TE_QT_PLUGIN_DATASOURCE_OGR(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
void startup()
Do nothing! Just set plugin as started.
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QString GetFileExtensionName(const std::string &type)
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
~Plugin()
Virtual destructor.
void broadcast(te::qt::af::evt::Event *evt)
Send events in broadcast for all registered components.
QAction * findAction(const QString &id) const
Returns the action identified by id or NULL if there's not an action identified by id...
te::qt::af::Project * getProject()
Get the current project.
TEQTAFEXPORT void AddActionToCustomToolbars(QAction *act)
Check QSettings for existance of act and adds it if necessary.
const std::list< te::map::AbstractLayerPtr > getSelectedLayers() const
It gets all the layers that are selected.