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)
65 m_inDsetName = inDsetName;
67 m_inAddressDsrc = inAddressDsrc;
68 m_inAddressDsetName = inAddressDsetName;
72 std::string streetNumber)
74 m_associatedProps = associatedProps;
75 m_streetNumber = streetNumber;
79 std::string finalLeft,
80 std::string initialRight,
81 std::string finalRight)
83 m_initialLeft = initialLeft;
84 m_finalLeft = finalLeft;
85 m_initialRight = initialRight;
86 m_finalRight = finalRight;
92 m_outDsetName = outDsetName;
97 if (!m_inDsrc.get() || !m_inAddressDsrc.get())
99 if (m_inDsetName.empty() || m_inAddressDsetName.empty())
101 if (m_associatedProps.empty())
103 if (!m_outDsrc.get())
105 if (m_outDsetName.empty())
116 std::auto_ptr<te::da::DataSetType> inDataSetType = m_inDsrc->getDataSetType(m_inDsetName);
119 std::auto_ptr<te::da::DataSet> dsAddress = m_inAddressDsrc->getDataSet(m_inAddressDsetName);
120 dsAddress->moveBeforeFirst();
123 std::auto_ptr<te::da::DataSetType> outDsType = getOutputDataSetType();
124 std::auto_ptr<te::mem::DataSet> dataSetMemory(
new te::mem::DataSet(outDsType.get()));
126 while(dsAddress->moveNext())
128 std::string query =
"SELECT * FROM ";
129 query += m_inDsetName +
" WHERE tsvector @@ plainto_tsquery('english', ";
131 for(std::size_t i = 0; i < m_associatedProps.size(); ++i)
133 std::string value = dsAddress->getAsString(m_associatedProps[i]);
135 bool changed =
false;
146 if( m_streetNumber !=
"")
148 if(m_initialLeft !=
"" && m_finalLeft !=
"" && m_initialRight !=
"" && m_finalRight !=
"")
150 query+=
" AND (" + dsAddress->getAsString(m_streetNumber) +
" > " + m_initialLeft +
" OR " + dsAddress->getAsString(m_streetNumber) +
" > " + m_initialRight +
")"
151 " AND (" + dsAddress->getAsString(m_streetNumber) +
" < " + m_finalLeft +
" OR " + dsAddress->getAsString(m_streetNumber) +
" < " + m_finalRight +
")";
153 else if((m_initialLeft !=
"" && m_finalLeft !=
"" && m_initialRight ==
"" && m_finalRight ==
"")||
154 (m_initialLeft !=
"" && m_finalLeft !=
"" && m_initialRight !=
"" && m_finalRight ==
"")||
155 (m_initialLeft !=
"" && m_finalLeft !=
"" && m_initialRight ==
"" && m_finalRight !=
""))
157 query+=
" AND (" + dsAddress->getAsString(m_streetNumber) +
" > " + m_initialLeft +
" AND " + dsAddress->getAsString(m_streetNumber) +
" < " + m_finalLeft +
")";
159 else if((m_initialLeft ==
"" && m_finalLeft ==
"" && m_initialRight !=
"" && m_finalRight !=
"")||
160 (m_initialLeft ==
"" && m_finalLeft !=
"" && m_initialRight !=
"" && m_finalRight !=
"")||
161 (m_initialLeft !=
"" && m_finalLeft ==
"" && m_initialRight !=
"" && m_finalRight !=
""))
163 query+=
" AND (" + dsAddress->getAsString(m_streetNumber) +
" > " + m_initialRight +
" AND " + dsAddress->getAsString(m_streetNumber) +
" < " + m_finalRight +
")";
169 query +=
" ORDER BY " + gid->
getName();
173 std::auto_ptr<te::da::DataSet> dsQuery = m_inDsrc->query(query);
174 dsQuery->moveFirst();
181 if(dsQuery->size() > 0)
183 std::vector<te::dt::Property*> vecProps = inDataSetType->getProperties();
184 double initVal = boost::lexical_cast<
double>(dsAddress->getDouble(m_streetNumber));
185 double finalVal = boost::lexical_cast<
double>(dsAddress->getDouble(m_streetNumber));
189 for(std::size_t i = 0; i < vecProps.size(); ++i)
193 if(dsQuery->isNull(i) ==
false)
194 itemMemory->
setValue(vecProps[i]->getName(), dsQuery->getValue(i).release());
196 if(vecProps[i]->getName() == m_initialLeft || vecProps[i]->getName() == m_initialRight)
198 int type = vecProps[i]->getType();
204 aux_val = dsQuery->getInt16(i);
205 if(aux_val <= initVal)
211 aux_val = dsQuery->getInt32(i);
212 if(aux_val <= initVal)
218 aux_val = boost::lexical_cast<
double>(dsQuery->getInt64(i));
219 if(aux_val <= initVal)
225 aux_val = boost::lexical_cast<
double>(dsQuery->getDouble(i));
226 if(aux_val <= initVal)
232 aux_val = boost::lexical_cast<
double>(dsQuery->getNumeric(i));
233 if(aux_val <= initVal)
241 if(vecProps[i]->getName() == m_finalLeft || vecProps[i]->getName() == m_finalRight)
243 int type = vecProps[i]->getType();
249 aux_val = dsQuery->getInt16(i);
250 if(aux_val >= finalVal)
256 aux_val = dsQuery->getInt32(i);
257 if(aux_val >= finalVal)
263 aux_val = boost::lexical_cast<
double>(dsQuery->getInt64(i));
264 if(aux_val >= finalVal)
270 aux_val = boost::lexical_cast<
double>(dsQuery->getDouble(i));
271 if(aux_val >= finalVal)
277 aux_val = boost::lexical_cast<
double>(dsQuery->getNumeric(i).c_str());
278 if(aux_val >= finalVal)
293 std::auto_ptr<te::gm::Geometry> geom = dsQuery->getGeometry(geomPos);
300 int numTarget = boost::lexical_cast<
int>(dsAddress->getDouble(m_streetNumber));
304 itemMemory->
setValue(geomPos, point);
306 dataSetMemory->add(itemMemory);
316 return save(dataSetMemory,outDsType);
326 std::map<std::string, std::string> options;
328 m_outDsrc->createDataSet(dsTypeResult, options);
331 result->moveBeforeFirst();
332 m_outDsrc->add(dsTypeResult->getName(),result.get(), options);
335 if (m_outDsrc->getCapabilities().getDataSetTypeCapabilities().supportsPrimaryKey())
337 std::string pk_name = dsTypeResult->getName() +
"_pkey";
339 pk->
add(dsTypeResult->getProperty(0));
340 m_outDsrc->addPrimaryKey(m_outDsetName,pk);
348 std::auto_ptr<te::da::DataSetType> inDsType = m_inDsrc->getDataSetType(m_inDsetName);
351 std::vector<te::dt::Property*> vecProps = inDsType->getProperties();
353 for(std::size_t i = 0; i < vecProps.size(); ++i)
357 outDsType->add(vecProps[i]->clone());
367 outDsType->add(geometry);
377 std::vector<te::gm::LineString*> vecLines;
379 getLines(geom, vecLines);
381 if(vecLines.size() > 0)
384 for(std::size_t i = 1; i < vecLines.size(); ++i)
385 line->
Union(vecLines[i]);
398 getLines(dynamic_cast<te::gm::GeometryCollection*>(geom), lines);
402 getLines(dynamic_cast<te::gm::LineString*>(geom), lines);
void setParams(std::vector< std::string > associatedProps, std::string streetNumber)
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.
CharEncoding
Supported charsets (character encoding).
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the description of a dataset.
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.
Address Geocoding operation.
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.
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.
bool save(std::auto_ptr< te::mem::DataSet > result, std::auto_ptr< te::da::DataSetType > outDsetName)
void setOutput(te::da::DataSourcePtr outDsrc, std::string m_outDsetName)
TEGEOMEXPORT Coord2D * locateAlong(const LineString *line, double initial, double final, double target)
Make the line interpolation to find a target.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
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.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
std::auto_ptr< te::da::DataSetType > getOutputDataSetType()
It describes a primary key (pk) constraint.
virtual Geometry * Union(const Geometry *const rhs) const
It returns a geometric object that represents the point set union with another geometry.
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)
const std::string & getName() const
It returns the property name.