24 #include "../common/StringUtils.h" 26 #include "../dataaccess/dataset/DataSet.h" 27 #include "../dataaccess/dataset/DataSetAdapter.h" 28 #include "../dataaccess/dataset/DataSetType.h" 29 #include "../dataaccess/dataset/DataSetTypeConverter.h" 30 #include "../dataaccess/dataset/ObjectIdSet.h" 31 #include "../dataaccess/datasource/DataSource.h" 32 #include "../dataaccess/datasource/DataSourceCapabilities.h" 33 #include "../dataaccess/utils/Utils.h" 35 #include "../datatype/Property.h" 36 #include "../datatype/StringProperty.h" 38 #include "../geometry/GeometryProperty.h" 39 #include "../geometry/GeometryCollection.h" 40 #include "../geometry/LineString.h" 41 #include "../geometry/Utils.h" 43 #include "../memory/DataSet.h" 44 #include "../memory/DataSetItem.h" 46 #include "../statistics/core/Utils.h" 51 #include <boost/lexical_cast.hpp> 59 std::string inDsetName,
62 std::string inAddressDsetName)
72 std::string streetNumber)
79 std::string finalLeft,
80 std::string initialRight,
81 std::string finalRight)
118 dsAddress->moveBeforeFirst();
122 std::unique_ptr<te::mem::DataSet> dataSetMemory(
new te::mem::DataSet(outDsType.get()));
124 while(dsAddress->moveNext())
126 std::string query =
"SELECT * FROM ";
127 query +=
m_inDsetName +
" WHERE tsvector @@ plainto_tsquery('english', ";
133 bool changed =
false;
167 query +=
" ORDER BY " + gid->
getName();
171 std::unique_ptr<te::da::DataSet> dsQuery =
m_inDsrc->query(query);
172 dsQuery->moveFirst();
179 if(dsQuery->size() > 0)
181 std::vector<te::dt::Property*> vecProps = inDataSetType->getProperties();
182 double initVal = boost::lexical_cast<
double>(dsAddress->getDouble(
m_streetNumber));
183 double finalVal = boost::lexical_cast<
double>(dsAddress->getDouble(
m_streetNumber));
187 for(std::size_t i = 0; i < vecProps.size(); ++i)
191 if(dsQuery->isNull(i) ==
false)
192 itemMemory->
setValue(vecProps[i]->getName(), dsQuery->getValue(i).release());
196 int type = vecProps[i]->getType();
202 aux_val = dsQuery->getInt16(i);
203 if(aux_val <= initVal)
209 aux_val = dsQuery->getInt32(i);
210 if(aux_val <= initVal)
216 aux_val = boost::lexical_cast<
double>(dsQuery->getInt64(i));
217 if(aux_val <= initVal)
223 aux_val = boost::lexical_cast<
double>(dsQuery->getDouble(i));
224 if(aux_val <= initVal)
230 aux_val = boost::lexical_cast<
double>(dsQuery->getNumeric(i));
231 if(aux_val <= initVal)
241 int type = vecProps[i]->getType();
247 aux_val = dsQuery->getInt16(i);
248 if(aux_val >= finalVal)
254 aux_val = dsQuery->getInt32(i);
255 if(aux_val >= finalVal)
261 aux_val = boost::lexical_cast<
double>(dsQuery->getInt64(i));
262 if(aux_val >= finalVal)
268 aux_val = boost::lexical_cast<
double>(dsQuery->getDouble(i));
269 if(aux_val >= finalVal)
275 aux_val = boost::lexical_cast<
double>(dsQuery->getNumeric(i).c_str());
276 if(aux_val >= finalVal)
291 std::unique_ptr<te::gm::Geometry> geom = dsQuery->getGeometry(geomPos);
298 int numTarget = boost::lexical_cast<
int>(dsAddress->getDouble(
m_streetNumber));
302 itemMemory->
setValue(geomPos, point);
304 dataSetMemory->add(itemMemory);
314 return save(std::move(dataSetMemory), std::move(outDsType));
324 std::map<std::string, std::string> options;
326 m_outDsrc->createDataSet(dsTypeResult, options);
329 result->moveBeforeFirst();
330 m_outDsrc->add(dsTypeResult->getName(),result.get(), options);
333 if (
m_outDsrc->getCapabilities().getDataSetTypeCapabilities().supportsPrimaryKey())
335 std::string pk_name = dsTypeResult->getName() +
"_pkey";
337 pk->
add(dsTypeResult->getProperty(0));
349 std::vector<te::dt::Property*> vecProps = inDsType->getProperties();
351 for(std::size_t i = 0; i < vecProps.size(); ++i)
355 outDsType->add(vecProps[i]->clone());
365 outDsType->add(geometry);
375 std::vector<te::gm::LineString*> vecLines;
379 if(vecLines.size() > 0)
382 for(std::size_t i = 1; i < vecLines.size(); ++i)
383 line->
Union(vecLines[i]);
396 getLines(dynamic_cast<te::gm::GeometryCollection*>(geom), lines);
400 getLines(dynamic_cast<te::gm::LineString*>(geom), lines);
void setParams(std::vector< std::string > associatedProps, std::string streetNumber)
std::string m_initialRight
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, int inSRID, te::da::DataSourcePtr inAddressDsrc, std::string inAddressDsetName)
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
void setGeometryType(GeomType t)
It sets the geometry subtype.
std::string m_inAddressDsetName
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the description of a dataset.
std::string m_streetNumber
File attribute that represents the address number.
std::vector< std::string > m_associatedProps
File attributes.
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
te::da::DataSourcePtr m_inAddressDsrc
DataSetType * getResult() const
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
void setNumAttributes(std::string initialLeft, std::string finalLeft, std::string initialRight, std::string finalRight)
An utility struct for representing 2D coordinates.
bool save(std::unique_ptr< te::mem::DataSet > result, std::unique_ptr< te::da::DataSetType > outDsetName)
Address Geocoding operation.
virtual Geometry * Union(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set union with another geometry.
std::string ReplaceSpecialChars(const std::string &str, bool &changed)
It replace special characters of a string.
It models a property definition.
An converter for DataSetType.
te::gm::GeometryCollection * gc
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void getLines(te::gm::Geometry *geom, std::vector< te::gm::LineString * > &lines)
LineString is a curve with linear interpolation between points.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
A point with x and y coordinate values.
void setOutput(te::da::DataSourcePtr outDsrc, std::string m_outDsetName)
std::unique_ptr< te::da::DataSetType > getOutputDataSetType()
TEGEOMEXPORT Coord2D * locateAlong(const LineString *line, double initial, double final, double target)
Make the line interpolation to find a target.
te::da::DataSourcePtr m_inDsrc
std::string m_outDsetName
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
te::da::DataSourcePtr m_outDsrc
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
It describes a primary key (pk) constraint.
It is a collection of other geometric objects.
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
te::gm::LineString * getLineString(te::gm::Geometry *geom)
std::string m_initialLeft
const std::string & getName() const
It returns the property name.