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())
114 std::auto_ptr<te::da::DataSetType> inDataSetType = m_inDsrc->getDataSetType(m_inDsetName);
117 std::auto_ptr<te::da::DataSet> dsAddress = m_inAddressDsrc->getDataSet(m_inAddressDsetName);
118 dsAddress->moveBeforeFirst();
121 std::auto_ptr<te::da::DataSetType> outDsType = getOutputDataSetType();
122 std::auto_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', ";
129 for(std::size_t i = 0; i < m_associatedProps.size(); ++i)
131 std::string value = dsAddress->getAsString(m_associatedProps[i]);
133 bool changed =
false;
144 if( m_streetNumber !=
"")
146 if(m_initialLeft !=
"" && m_finalLeft !=
"" && m_initialRight !=
"" && m_finalRight !=
"")
148 query+=
" AND (" + dsAddress->getAsString(m_streetNumber) +
" > " + m_initialLeft +
" OR " + dsAddress->getAsString(m_streetNumber) +
" > " + m_initialRight +
")"
149 " AND (" + dsAddress->getAsString(m_streetNumber) +
" < " + m_finalLeft +
" OR " + dsAddress->getAsString(m_streetNumber) +
" < " + m_finalRight +
")";
151 else if((m_initialLeft !=
"" && m_finalLeft !=
"" && m_initialRight ==
"" && m_finalRight ==
"")||
152 (m_initialLeft !=
"" && m_finalLeft !=
"" && m_initialRight !=
"" && m_finalRight ==
"")||
153 (m_initialLeft !=
"" && m_finalLeft !=
"" && m_initialRight ==
"" && m_finalRight !=
""))
155 query+=
" AND (" + dsAddress->getAsString(m_streetNumber) +
" > " + m_initialLeft +
" AND " + dsAddress->getAsString(m_streetNumber) +
" < " + m_finalLeft +
")";
157 else if((m_initialLeft ==
"" && m_finalLeft ==
"" && m_initialRight !=
"" && m_finalRight !=
"")||
158 (m_initialLeft ==
"" && m_finalLeft !=
"" && m_initialRight !=
"" && m_finalRight !=
"")||
159 (m_initialLeft !=
"" && m_finalLeft ==
"" && m_initialRight !=
"" && m_finalRight !=
""))
161 query+=
" AND (" + dsAddress->getAsString(m_streetNumber) +
" > " + m_initialRight +
" AND " + dsAddress->getAsString(m_streetNumber) +
" < " + m_finalRight +
")";
167 query +=
" ORDER BY " + gid->
getName();
171 std::auto_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());
194 if(vecProps[i]->getName() == m_initialLeft || vecProps[i]->getName() == m_initialRight)
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)
239 if(vecProps[i]->getName() == m_finalLeft || vecProps[i]->getName() == m_finalRight)
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::auto_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(dataSetMemory,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));
338 m_outDsrc->addPrimaryKey(m_outDsetName,pk);
346 std::auto_ptr<te::da::DataSetType> inDsType = m_inDsrc->getDataSetType(m_inDsetName);
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;
377 getLines(geom, 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::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.
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.
TECOMMONEXPORT 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.