27 #include "../../../../common/StringUtils.h" 28 #include "../../../../dataaccess/utils/Utils.h" 29 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h" 30 #include "../../../../dataaccess/datasource/DataSourceManager.h" 31 #include "../../../../geometry/GeometryProperty.h" 32 #include "../../../../maptools/DataSetLayer.h" 33 #include "../../../widgets/utils/DoubleListWidget.h" 34 #include "../../../widgets/utils/ScopedCursor.h" 35 #include "../core/form/Serializer.h" 36 #include "../utils/Utils.h" 44 #include <QMessageBox> 47 #include <boost/date_time/posix_time/posix_time.hpp> 48 #include <boost/date_time/posix_time/posix_time_io.hpp> 49 #include <boost/lexical_cast.hpp> 50 #include <boost/uuid/random_generator.hpp> 51 #include <boost/uuid/uuid_io.hpp> 57 this->setWizardStyle(QWizard::ModernStyle);
58 this->setFixedSize(640, 480);
59 this->setWindowTitle(tr(
"GeoPackage Builder Wizard"));
81 std::vector<std::string> inputLayerNames;
82 std::vector<std::string> gatheringLayerNames;
86 std::list<te::map::AbstractLayerPtr>::iterator it = list.begin();
88 while (it != list.end())
94 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
96 if (dsType->hasGeom())
98 inputLayerNames.push_back(l->getTitle());
105 gatheringLayerNames.push_back(l->getTitle());
108 else if (dsType->hasRaster())
110 inputLayerNames.push_back(l->getTitle());
138 std::vector<std::string> names =
m_inputLayersPage->getWidget()->getOutputValues();
185 std::string gpkgName =
m_outputPage->getGeoPackageFilePath();
187 if (gpkgName.empty())
189 QMessageBox::warning(
this, tr(
"GeoPackage Builder"),
"The name for the output geopackage can not be empty.");
194 std::map<std::string, Section*> sectionsMap =
m_formsPage->getSections();
199 std::list<te::map::AbstractLayerPtr> inputLayers =
getInputLayers();
201 std::list<te::map::AbstractLayerPtr>::iterator it;
205 bool visible =
false;
211 for (it = gatheringLayers.begin(); it != gatheringLayers.end(); ++it)
213 std::auto_ptr<te::da::DataSetType> dsType = (*it)->getSchema();
214 std::string dataSourceId = (*it)->getDataSourceId();
217 std::string dataSetName = dsType->getName();
226 ds->addProperty(dsType->getName(), statusProp);
236 ds->addProperty(dsType->getName(), objIdProp);
245 dsType = (*it)->getSchema();
249 if (!visible && !aux)
251 visible = (*it)->getVisibility();
252 aux = (*it)->getVisibility();
261 m_outputPage->appendLogMesssage(
"Exporting gathering layer " + dsType->getName());
263 std::string
insert =
"INSERT INTO tm_layer_settings ('layer_name', 'enabled', 'position', 'datasource_uri') values('" + dsType->getName() +
"', " +
264 boost::lexical_cast<std::string>(aux)+
", " + boost::lexical_cast<std::string>(pos)+
", '" + dsInfo->getConnInfoAsString() +
"'); ";
268 m_outputPage->appendLogMesssage(
"Gathering layer " + dsType->getName() +
" successfuly exported.");
271 for (it = inputLayers.begin(); it != inputLayers.end(); ++it)
273 std::string dataSourceId = (*it)->getDataSourceId();
276 visible = (*it)->getVisibility();
278 std::auto_ptr<te::da::DataSetType> dsType = (*it)->getSchema();
279 std::string name = dsType->getName();
282 if (dsType->hasRaster())
284 std::vector<std::string> values;
287 for (
size_t i = 0; i < values.size() - 1; ++i)
291 m_outputPage->appendLogMesssage(
"Exporting input layer " + name);
293 std::string
insert =
"INSERT INTO tm_layer_settings ('layer_name', 'enabled', 'position', 'datasource_uri') values('" + name +
"', " + boost::lexical_cast<std::string>(visible)+
", " +
294 boost::lexical_cast<std::string>(pos)+
", '" + dsInfo->getConnInfoAsString() +
"'); ";
300 m_outputPage->appendLogMesssage(
"Input layer " + name +
" successfuly exported.");
304 std::map<std::string, Section*>::iterator itb = sectionsMap.begin();
305 std::map<std::string, Section*>::iterator ite = sectionsMap.end();
311 std::string
insert =
"INSERT INTO tm_layer_form ('gpkg_layer_identify', 'tm_form', 'tm_media_table') values('" + itb->first +
"', '" + jsonStr +
"', '" +
"" +
"');";
321 std::string minX, minY, maxX, maxY;
327 std::string insert1 =
"INSERT INTO tm_settings ('key', 'value') values ('default_xmin', '" + minX +
"');";
328 std::string insert2 =
"INSERT INTO tm_settings ('key', 'value') values ('default_ymin', '" + minY +
"');";
329 std::string insert3 =
"INSERT INTO tm_settings ('key', 'value') values ('default_xmax', '" + maxX +
"');";
330 std::string insert4 =
"INSERT INTO tm_settings ('key', 'value') values ('default_ymax', '" + maxY +
"');";
339 boost::uuids::basic_random_generator<boost::mt19937> gen;
340 boost::uuids::uuid u = gen();
341 std::string id_ds = boost::uuids::to_string(u);
343 std::string insPrjId =
"INSERT INTO tm_settings ('key', 'value') values ('project_id', '" + id_ds +
"');";
346 std::string insProjStatus =
"INSERT INTO tm_settings ('key', 'value') values ('project_status', '" + boost::lexical_cast<std::string>(0) +
"');";
349 std::string insGpkgVrs =
"INSERT INTO tm_settings ('key', 'value') values ('gpkg_version', '1.0');";
352 boost::gregorian::date current_date(boost::gregorian::day_clock::local_day());
353 std::locale fmt(std::locale::classic(),
new boost::gregorian::date_facet(
"%d/%m/%Y"));
354 std::ostringstream os;
358 std::string insDate =
"INSERT INTO tm_settings ('key', 'value') values ('creation_date','" + os.str() +
"'); ";
361 std::string gpkgDesc =
m_outputPage->getGeoPackageDescription();
362 if (!gpkgDesc.empty())
364 std::string insDesc =
"INSERT INTO tm_settings ('key', 'value') values ('description','" + gpkgDesc +
"'); ";
371 for (
size_t i = 0; i < triggers.size(); ++i)
373 std::string drop =
"drop trigger " + triggers[i] +
";";
379 for (
size_t i = 0; i < tables.size(); ++i)
381 std::string drop =
"drop table " + tables[i] +
";";
385 catch (std::exception& e)
387 QMessageBox::warning(
this, tr(
"Warning"), e.what());
392 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal error generating geopackage file."));
396 QMessageBox::information(
this, tr(
"Information"), tr(
"Generated Geopackage File Successfully."));
403 std::list<te::map::AbstractLayerPtr> list;
408 for (std::size_t t = 0; t < names.size(); ++t)
410 std::list<te::map::AbstractLayerPtr>::iterator it;
414 if (names[t] == it->get()->getTitle())
416 list.push_back(it->get());
426 std::list<te::map::AbstractLayerPtr> list;
429 std::vector<std::string> names =
m_inputLayersPage->getWidget()->getOutputValues();
431 for (std::size_t t = 0; t < names.size(); ++t)
433 std::list<te::map::AbstractLayerPtr>::iterator it;
437 if (names[t] == it->get()->getTitle())
439 list.push_back(it->get());
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void makeInvalid()
It will invalidated the envelope.
std::list< te::map::AbstractLayerPtr > getGatheringLayers()
An atomic property like an integer or double.
boost::shared_ptr< DataSource > DataSourcePtr
void queryGPKG(std::string query, te::da::DataSource *dsGPKG)
std::vector< std::string > getItemNames(std::string type, te::da::DataSource *dsGPKG)
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
GeoPackageBuilderWizard(QWidget *parent=0, Qt::WindowFlags f=0)
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
static te::dt::Date ds(2010, 01, 01)
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
This interface is used to get the gathering layers parameters for GeoPackage Builder wizard operation...
std::auto_ptr< te::da::DataSource > createGeopackage(std::string gpkgName)
It models a property definition.
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
void exportToGPKG(te::map::AbstractLayerPtr layer, te::da::DataSource *dsGPKG, std::string outFileName, const te::gm::Envelope extent)
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
virtual bool validateCurrentPage()
An Envelope defines a 2D rectangular region.
std::auto_ptr< te::qt::plugins::terramobile::BuilderFormsWizardPage > m_formsPage
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
te::gm::Envelope m_extent
void setExtent(const te::gm::Envelope &extent)
void fillExtraColumns(te::da::DataSource *ds, std::string dataSetName)
#define LAYER_GATHERING_STATUS_COLUMN
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
std::string Write(te::qt::plugins::terramobile::Section *section)
#define LAYER_GATHERING_OBJID_COLUMN
std::auto_ptr< te::qt::plugins::terramobile::BuilderOutputWizardPage > m_outputPage
A layer with reference to a dataset.
This interface is used to configure the form json file for GeoPackage Builder wizard operation...
~GeoPackageBuilderWizard()
This interface is used to get the output parameters for GeoPackage Builder wizard operation...
std::auto_ptr< te::qt::plugins::terramobile::BuilderInputLayersWizardPage > m_inputLayersPage
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
std::auto_ptr< te::qt::plugins::terramobile::BuilderGatheringLayersWizardPage > m_gatheringLayersPage
void setLayerList(std::list< te::map::AbstractLayerPtr > list)
This interface is used to get the input layers parameters for GeoPackage Builder wizard operation...
bool isValid() const
It tells if the rectangle is valid or not.
std::list< te::map::AbstractLayerPtr > getInputLayers()
std::list< te::map::AbstractLayerPtr > m_list
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr