24 #include "../common/progress/TaskProgress.h" 25 #include "../core/logger/Logger.h" 26 #include "../core/translator/Translator.h" 27 #include "../dataaccess/dataset/DataSet.h" 28 #include "../dataaccess/query/DataSetName.h" 29 #include "../dataaccess/query/EqualTo.h" 30 #include "../dataaccess/query/Field.h" 31 #include "../dataaccess/query/Fields.h" 32 #include "../dataaccess/query/From.h" 33 #include "../dataaccess/query/FromItem.h" 34 #include "../dataaccess/query/LiteralString.h" 35 #include "../dataaccess/query/PropertyName.h" 36 #include "../dataaccess/query/Select.h" 37 #include "../dataaccess/query/ST_Buffer.h" 38 #include "../dataaccess/query/ST_IsValid.h" 39 #include "../dataaccess/query/ST_MakeValid.h" 40 #include "../dataaccess/query/ST_Multi.h" 41 #include "../dataaccess/query/Where.h" 43 #include "../dataaccess/datasource/DataSourceCapabilities.h" 44 #include "../dataaccess/datasource/DataSourceTransactor.h" 46 #include "../dataaccess/utils/Utils.h" 48 #include "../geometry/FixGeometryTopology.h" 49 #include "../geometry/Geometry.h" 50 #include "../geometry/GeometryProperty.h" 51 #include "../geometry/Utils.h" 53 #include "../memory/DataSet.h" 54 #include "../memory/DataSetItem.h" 59 #include "boost/lexical_cast.hpp" 62 const std::string &dataSetName,
63 std::string& errorMessage,
70 return makeValidQuery(dataSource, dataSetName, errorMessage, oidSet);
86 std::unique_ptr<te::da::DataSetType> dsType(
94 std::vector<te::dt::Property*> props = dsType->getProperties();
95 for(std::size_t
p = 0;
p < props.size(); ++
p)
101 fields.push_back(field);
122 fields.push_back(f_geometry);
126 from.push_back(fromItem);
140 std::unique_ptr<te::da::DataSet>
ds;
144 ds.reset(dataSource->query(select).release());
149 TE_TR(
"Fix Geometry") +
": " + e.
what());
151 errorMessage = e.
what();
154 catch (
const std::exception& e)
157 TE_TR(
"Fix Geometry") +
": " + e.what());
159 errorMessage = e.what();
165 TE_TR(
"Fix Geometry") +
": Unknown Excption.");
167 errorMessage =
"Unknown Excption.";
181 std::vector<std::size_t> ids;
183 for (
size_t i = 0; i < numProps; ++i)
186 ids.push_back(dsType->getPropertyPosition(propName));
189 std::set<int> posSet;
190 posSet.insert((
int)dsType->getPropertyPosition(geometryProperty->
getName()));
191 std::vector< std::set<int> > propsPos;
193 for(std::size_t
p = 0;
p < ds->size(); ++
p)
194 propsPos.push_back(posSet);
196 std::unique_ptr<te::da::DataSourceTransactor> transactor =
197 dataSource->getTransactor();
201 transactor->update(dataSetName, ds.get(), propsPos, ids);
206 TE_TR(
"Fix Geometry") +
": " + e.
what());
208 errorMessage = e.
what();
210 transactor->rollBack();
213 catch (
const std::exception& e)
216 TE_TR(
"Fix Geometry") +
": " + e.what());
218 errorMessage = e.what();
220 transactor->rollBack();
226 TE_TR(
"Fix Geometry") +
": Unknown Excption.");
228 errorMessage =
"Unknown Excption.";
230 transactor->rollBack();
234 transactor->commit();
240 const std::string& dataSetName,
241 std::string& errorMessage,
244 std::unique_ptr<te::da::DataSourceTransactor> transactor =
245 dataSource->getTransactor();
247 std::unique_ptr<te::da::DataSetType> dataSetType(
253 std::unique_ptr<te::da::DataSet> dataSetToFix;
254 std::unique_ptr<te::mem::DataSet> fixedDataSet(
new te::mem::DataSet(dataSetType.get()));
259 std::vector<std::string> oidprops;
263 if(oidSet && oidSet->
size() > 0)
265 dataSetToFix = dataSource->getDataSet(dataSetName, oidSet);
270 dataSetToFix = dataSource->getDataSet(dataSetName);
276 dataSetToFix->moveBeforeFirst();
281 while(dataSetToFix->moveNext())
285 errorMessage =
TE_TR(
"Fix geometry canceled!");
291 std::unique_ptr<te::gm::Geometry> geometryToFix =
292 dataSetToFix->getGeometry(geometryProperty->
getName());
294 std::vector<te::gm::Geometry*> fixedGeometryVec;
307 TE_TR(
"Fix Geometry") +
": " +
308 TE_TR(
"Could not fix geometry") +
": " + topologyError.
m_message +
"; " +
309 TE_TR(
"Coordinate") +
": (" + boost::lexical_cast<std::string>(topologyError.
m_coordinate.
getX()) +
"," +
310 boost::lexical_cast<std::string>(topologyError.
m_coordinate.
getY()) +
"); " +
311 TE_TR(
"Geometry WKT") +
": " + geometryToFix->asText());
313 errorMessage =
"Some geometries could not be fixed. Check the log file for more information.";
318 for(std::size_t i = 0; i < fixedGeometryVec.size(); ++i)
324 fixedDataSet->add(dataSetItemMemory);
331 for (std::string
p : oidprops)
340 std::map<std::string, std::string> options;
342 transactor->remove(dataSetName, oidSet);
343 transactor->add(dataSetName, fixedDataSet.get(), options);
347 std::unique_ptr<te::gm::Geometry> geometryToFix = dataSetToFix->getGeometry(geometryProperty->
getName());
350 TE_TR(
"Fix Geometry") +
": " +
351 TE_TR(
"Could not fix geometry") +
": " + e.
what() +
"; " +
352 TE_TR(
"Geometry WKT") +
": " + geometryToFix->asText());
354 errorMessage = e.
what();
357 catch (
const std::exception& e)
359 std::unique_ptr<te::gm::Geometry> geometryToFix = dataSetToFix->getGeometry(geometryProperty->
getName());
362 TE_TR(
"Fix Geometry") +
": " +
363 TE_TR(
"Could not fix geometry") +
": " + e.what() +
"; " +
364 TE_TR(
"Geometry WKT") +
": " + geometryToFix->asText());
366 errorMessage = e.what();
371 std::unique_ptr<te::gm::Geometry> geometryToFix = dataSetToFix->getGeometry(geometryProperty->
getName());
374 TE_TR(
"Fix Geometry") +
": " +
375 TE_TR(
"Could not fix geometry") +
": Unknown Excption; " +
376 TE_TR(
"Geometry WKT") +
": " + geometryToFix->asText());
378 errorMessage =
"Unknown Excption.";
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
An abstract class that models a source of data in a query.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
TEDATAACCESSEXPORT ObjectId * GenerateOID(DataSet *dataset, const std::vector< std::string > &names)
A class that models the name of a dataset used in a From clause.
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the name of any property of an object.
virtual const char * what() const
It outputs the exception message.
static bool makeValidMemory(const te::da::DataSourcePtr dataSource, const std::string &dataSetName, std::string &errorMessage, te::da::ObjectIdSet *oidSet=0)
It tries to fix invalid geometry by GEOS and updates the source data.
This class can be used to inform the progress of a task.
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
TEGEOMEXPORT bool IsMultiType(te::gm::GeomType geomType)
Verifies if the geomType is a collection type.
te::da::QueryCapabilities queryCapabilities
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
double getY() const
It returns the y-coordinate.
static te::dt::Date ds(2010, 01, 01)
void addProperty(const std::string &name, std::size_t pos, int type)
It adds a property that will be used to generate the unique ids.
#define TE_TR(message)
It marks a string in order to get translated.
const QueryCapabilities & getQueryCapabilities() const
It models a property definition.
bool isActive() const
Verify if the task is active.
This is an abstract class that models a query expression.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
void setTotalSteps(int value)
Set the task total stepes.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
A class that informs the query support of a given data source.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
This class represents an unique id for a data set element.
std::size_t size() const
It returns the object id set size.
Spatial operator that tries to make geometry valid.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
A class that can be used to model a filter expression that can be applied to a query.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
bool supportsSpatialSQLDialect() const
Utility functions for the data access module.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
static bool makeValid(const te::da::DataSourcePtr dataSource, const std::string &dataSetName, std::string &errorMessage, te::da::ObjectIdSet *oidSet=0)
This method gets the datasource capabilities and calls the specific function to fix geometry...
A Select models a query to be used when retrieving data from a DataSource.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
int getType() const
It returns the property data type.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
double getX() const
It returns the x-coordinate.
It describes a primary key (pk) constraint.
static bool makeValidQuery(const te::da::DataSourcePtr dataSource, const std::string &dataSetName, std::string &errorMessage, te::da::ObjectIdSet *oidSet=0)
It tries to fix invalid geometry by SQL clause ST_MakeValid and updates the source data...
It models the comparison operator.
static bool fixTopology(const te::gm::Geometry &geometry, std::vector< te::gm::Geometry * > &fixedGeometryVector, TopologyValidationError topologyError)
This method gets a topologically inconsistent geometry and calls specific functions to fix this geome...
void clear()
It clears this object id set.
TEGEOMEXPORT bool CheckValidity(const Geometry *geom, te::gm::TopologyValidationError &error)
It check geometry validity using GEOS.
TEVPEXPORT te::mem::DataSetItem * GetFilledItemMemory(te::da::DataSet *dataSet)
It returns a memory item with all properties filled with values from the current position dataset...
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
TEDATAACCESSEXPORT void GetOIDPropertyNames(const DataSetType *type, std::vector< std::string > &pnames)
void add(ObjectId *oid)
It adds an object id to this object id set.
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
Spatial is valid operator.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
This struct contains informations about GEOS TopologyValidationError.
Functions to make geometry valid.
This class models a string Literal value.
const std::string & getName() const
It returns the property name.