26 #include "../../../../dataaccess/dataset/ObjectIdSet.h" 27 #include "../../../../dataaccess/dataset/ObjectId.h" 28 #include "../../../../dataaccess/datasource/DataSourceTransactor.h" 29 #include "../../../../dataaccess/utils/Utils.h" 30 #include "../../../../datatype/SimpleData.h" 31 #include "../../../../geometry/GeometryProperty.h" 32 #include "../../../../geometry/MultiPoint.h" 33 #include "../../../../geometry/Point.h" 34 #include "../../../../memory/DataSet.h" 35 #include "../../../../memory/DataSetItem.h" 37 #include "../Config.h" 42 #include <boost/uuid/random_generator.hpp> 43 #include <boost/uuid/uuid_io.hpp> 49 m_outputDataSource(0),
80 int gpkgDataSetAttrPKIdx = -1;
81 if (gpkgDsType->getPrimaryKey())
97 dsTypeAux->remove(dsTypeAux->getProperty(
"FID"));
110 std::vector<std::string> pnames;
113 std::vector<te::dt::Property*> props = dsTypeAux2->getProperties();
115 static boost::uuids::basic_random_generator<boost::mt19937> gen;
117 gpkgDataSet->moveBeforeFirst();
119 while (gpkgDataSet->moveNext())
124 boost::uuids::uuid u = gen();
125 std::string
id = boost::uuids::to_string(u);
130 for (std::size_t t = 0; t < props.size(); ++t)
132 if (props[t]->getName() ==
"FID" || props[t]->getName() ==
"fid")
149 std::auto_ptr<te::gm::Geometry> geom = gpkgDataSet->getGeometry(gpkgDataSetGeomIdx);
166 point->
transform(outputGeomProp->getSRID());
175 dsItem->
setValue(props[t]->getName(), gpkgDataSet->getValue(props[t]->getName()).release());
181 insertDataSetDataSource->
add(dsItem);
190 for (std::size_t t = 0; t < props.size(); ++t)
192 if (props[t]->getName() ==
"FID" || props[t]->getName() ==
"fid")
196 std::string sql =
"SELECT FID from ";
197 sql += dsTypeAux2->getName();
206 if (!dataSetQuery->isEmpty())
208 dataSetQuery->moveFirst();
210 int idValue = dataSetQuery->getInt32(0);
221 std::auto_ptr<te::gm::Geometry> geom = gpkgDataSet->getGeometry(props[t]->getName());
238 point->
transform(outputGeomProp->getSRID());
247 dsItem->
setValue(props[t]->getName(), gpkgDataSet->getValue(props[t]->getName()).release());
252 updateDataSetDataSource->
add(dsItem);
258 std::string sql =
"SELECT * from ";
259 sql += dsTypeAux2->getName();
268 if (!dataSetQuery->isEmpty())
270 dataSetQuery->moveFirst();
279 if (!insertDataSetDataSource->
isEmpty())
283 std::map<std::string, std::string> op;
291 transactor->rollBack();
295 catch (
const std::exception& e)
297 transactor->rollBack();
303 transactor->rollBack();
308 transactor->commit();
312 if (!updateDataSetDataSource->
isEmpty())
318 std::vector<size_t> ids;
321 std::vector< std::set<int> > properties;
322 std::size_t dsSize = updateDataSetDataSource->
size();
324 for (std::size_t t = 0; t < dsSize; ++t)
326 std::set<int> setPos;
333 properties.push_back(setPos);
336 transactor->update(
m_outputDataset, updateDataSetDataSource, properties, ids);
340 transactor->rollBack();
344 catch (
const std::exception& e)
346 transactor->rollBack();
352 transactor->rollBack();
356 transactor->commit();
360 if (objIdSet->size() != 0)
370 transactor->rollBack();
374 catch (
const std::exception& e)
376 transactor->rollBack();
382 transactor->rollBack();
387 transactor->commit();
std::size_t size() const
It returns the collection size, if it is known.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
virtual std::unique_ptr< DataSourceTransactor > getTransactor()=0
It returns the set of parameters used to set up the access channel to the underlying repository...
TEDATAACCESSEXPORT void GetEmptyOIDSet(const DataSetType *type, ObjectIdSet *&set)
Returns an empty ObjectIdSet, with the definitions of fields that compose it.
void setSRID(int srid) _NOEXCEPT_OP(true)
It sets the Spatial Reference System ID of the Point.
TEDATAACCESSEXPORT ObjectId * GenerateOID(DataSet *dataset, const std::vector< std::string > &names)
void setInputParameters(te::da::DataSource *inputDataSource, std::string inputDataSet, te::da::DataSource *outputDataSource, std::string outputDataset)
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
bool isEmpty() const
It returns true if the collection is empty.
TEDATAACCESSEXPORT int GetPropertyIndex(te::da::DataSet *dataSet, const std::string propName)
~GeoPackageSynchronizer()
te::da::DataSource * m_inputDataSource
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
virtual std::unique_ptr< DataSet > query(const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. This method always returns a dis...
std::string m_inputDataSet
te::da::DataSource * m_outputDataSource
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
MultiPoint is a GeometryCollection whose elements are restricted to points.
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
A point with x and y coordinate values.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
void transform(int srid) _NOEXCEPT_OP(false)
It converts the coordinate values of the point to the new spatial reference system.
virtual std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
#define LAYER_GATHERING_STATUS_COLUMN
virtual std::unique_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. This method always returns a disconnected dataset...
It describes a primary key (pk) constraint.
#define LAYER_GATHERING_OBJID_COLUMN
TEDATAACCESSEXPORT void GetOIDPropertyNames(const DataSetType *type, std::vector< std::string > &pnames)
A template for atomic data types (integers, floats, strings and others).
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
std::string m_outputDataset
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.