This file is indexed.

/usr/include/terralib/functions/TeAddressLocator.h is in libterralib-dev 4.0.0-5ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/************************************************************************************
TerraLib - a library for developing GIS applications.
Copyright © 2001-2007 INPE and Tecgraf/PUC-Rio.

This code is part of the TerraLib library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

You should have received a copy of the GNU Lesser General Public
License along with this library.

The authors reassure the license terms regarding the warranties.
They specifically disclaim any warranties, including, but not limited to,
the implied warranties of merchantability and fitness for a particular purpose.
The library provided hereunder is on an "as is" basis, and the authors have no
obligation to provide maintenance, support, updates, enhancements, or modifications.
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
indirect, special, incidental, or consequential damages arising out of the use
of this library and its documentation.
*************************************************************************************/
/*! \file TeAddressLocator.h
    \brief This file contains algorithms for address location generation.
*/

/**
  *@author Gilberto Ribeiro de Queiroz and Ricardo Cartaxo
  */

#ifndef  __TERRALIB_INTERNAL_ADDRESSLOCATOR_H
#define  __TERRALIB_INTERNAL_ADDRESSLOCATOR_H

#include <TeDatabase.h>
#include <TeLayer.h>

#include "TeFunctionsDefines.h"

#include <string>
#include <map>

using namespace std;

/** @defgroup GeoCod Geocoding 
    @{
	Structures and classes supporting geocoding operations.
 */

//! A dictionary of geocoding parameters
typedef multimap<string, string> TeGeocoderDictionary;


/*! \struct TeAddressMetadata
	Metadata for a table used as a base for geocoding
*/
struct TLFUNCTIONS_DLL TeAddressMetadata
{
	int tableId_;					//!< This value is a foreign key from te_layer_table indicates the table wich will be used for the address locator
	string tableName_;				//!< The table to use for geocoding process
	string linkColumnName_;			//!< The column used as link to line geometry
	string initialLeftNumber_;		//!< The field name with the initial location left number
	string finalLeftNumber_;		//!< The field name with the final location left number
	string initialRightNumber_;		//!< The field name with the initial location right number
	string finalRightNumber_;		//!< The field name with the final location right number
	string locationType_;			//!< The field name with location type (Av., Rua, R., Pr., Jz., Pres. ...)
	string locationTitle_;			//!< The field name with location title (Dr., Dra., PRF ...)
	string locationPreposition_;	//!< The field name with the preposition used to form the location name (Dos, Das, De, 
	string locationName_;			//!< The field name with the location name
	string locationCompleteName_;	//!< The field name with composed location name
	string leftNeighborhood_;		//!< The field name for the left location neighborhood 
	string rightNeighborhood_;		//!< The field name for the right location neighborhood
	string leftZipCode_;			//!< The field name for the left location zip code
	string rightZipCode_;			//!< The field name for the right location zip code
};

//!  Types for centroid field name finding
TLFUNCTIONS_DLL enum TeCentroidFieldType { TeNEIGHBORHOOD, TeZIPCODE };

/*! \struct TeCentroidAddressMetadata
	Metadata for a table used as a base for geocoding when an address is not found and a centroid for the zip code or neighborhood exists
*/
struct TLFUNCTIONS_DLL TeCentroidAddressMetadata
{
	string centroidName_;			//!< This field may be the neighborhood name or zip code name

	TeCentroidFieldType fieldType_;	//!< Field type

	string attributeTableName_;		//!< Attribute table name

	TeLayer* centroidLayer_;		//!< Polygon or point layer to extract centroid from

	TeCentroidAddressMetadata()
		: centroidLayer_(0)
	{
	}
};

/*! \struct TeGeocodeTableMetadata
	Metadata for the table that contains address to be geocode
*/
struct TLFUNCTIONS_DLL TeGeocodeTableMetadata
{
	string tableName_;						//!< The table to be geocoding
	string linkColumnName_;					//!< The column used as link column in geocoding
	string keyColumnName_;					//!< The column with index
	int tableId_;							//!< The id of the table for geocoding
	string locationTypeColumnName_;			//!< The field name with location type (Av., Rua, R., Pr., Jz., Pres. ...)
	string locationTitleColumnName_;		//!< The field name with location title (Dr., Dra., PRF ...)
	string locationPrepositionColumnName_;	//!< The field name with the preposition used to form the location name (Dos, Das, De, 
	string locationNameColumnName_;			//!< The field name with the location name
	string locationNumberColumnName_;		//!< The field name with the ocation number
	string neighborhoodColumnName_;			//!< The field name for the location neighborhood
	string zipCodeColumnName_;				//!< The field name for the location zip code	
};


/*! \struct TeAddress
	Information of an address that will be geocoded
*/
struct TLFUNCTIONS_DLL TeAddress
{
	string locationLink_;			//!< The value that unique identifies the location	
	string locationType_;			//!< Location type
	string locationTitle_;			//!< Location title
	string locationPreposition_;	//!< Location preposition
	string locationName_;			//!< Location name
	int locationNumber_;			//!< Location number
	string neighborhood_;			//!< Location neighborhood
	string zipCode_;				//!< Location zip code
};


/* \struct TeAddressDescription
	Information about a found address
 */
struct TLFUNCTIONS_DLL TeAddressDescription
{
	string locationLink_;			//!< The value that unique identifies the location
	int initialLeftNumber_;			//!< The initial location left number
	int finalLeftNumber_;			//!< The final location left number
	int initialRightNumber_;		//!< The initial location right number
	int finalRightNumber_;			//!< The final location right number
	string locationType_;			//!< The location type (Av., Rua, R., Pr., Jz., Pres. ...)
	string locationTitle_;			//!< The location title (Dr., Dra., PRF ...)
	string locationPreposition_;	//!< The preposition used to form the location name (Dos, Das, De, 
	string locationName_;			//!< The location name
	string locationCompleteName_;		//!< The complete location name
	string leftNeighborhood_;		//!< The left location neighborhood 
	string rightNeighborhood_;		//!< The right location neighborhood
	string leftZipCode_;			//!< The eft location zip code
	string rightZipCode_;			//!< The right location zip code
	TeCoord2D pt_;					//!< point location of the address
	bool isValid_;					//!< Tells if pt_ is a valid coordinate or the segment range was not found

	TeAddressDescription()
		: locationLink_(""), initialLeftNumber_(0), finalLeftNumber_(0),
		  initialRightNumber_(0), finalRightNumber_(0), locationType_(""),
		  locationTitle_(""), locationPreposition_(""), locationName_(""), locationCompleteName_(""), 
		  leftNeighborhood_(""), rightNeighborhood_(""), leftZipCode_(""),
		  rightZipCode_(""), isValid_(false)
	{
	}
};


//! An abstract class to support interactivity in geocoding
/*!
	Subclasses of this class must implement the "operator()" method
*/
class TLFUNCTIONS_DLL TeAbstractAddressNotifyFunctor
{
	public:

		virtual int operator()(const TeAddress& searchedAddress, vector<TeAddressDescription>& foundAddresses) = 0;

		virtual ~TeAbstractAddressNotifyFunctor()
		{
		}
};

//! A class to handle the geocoder support
/*!
	Instances of this class contains information about
	a table that can be used for geocoding and methods
	to geocode a given address.
*/
class TLFUNCTIONS_DLL TeAddressLocator
{
	protected:

		TeDatabase* db_;							//!< Database connection
		TeAddressMetadata metadata_;				//!< Metadata information for a geocoding base table
		TeLayer* referenceLayer_;					//!< Ther layer used as reference for geocoding 
		TeCentroidAddressMetadata cmetadata_;		//!< Centroid metadata
		bool isMetadataLoaded_;						//!< Flag to indicate if the metadata is loaded
		string errMsg_;								//!< Error message description
		TeGeocoderDictionary dictionary_;			//!< Use a geocoder dictionary
		bool changeSpecialChars_;					//!< If true should replace special characters
		bool removeHifen_;							//!< If true the hifen is removed in zip code
		bool removeHifenFromCentroid_;				//!< If true the hifen is removed in zip code from the centroid table
		char hifen_;
		string splitChar_;							//!< Used to split address name and number
		
		vector<string> typesVector_;				//!< Vector with default types for street names
		vector<string> titlesVector_;				//!< Vector with default titles for street names
		vector<string> prepositionsVector_;			//!< Vector with default prepositions for street names

	public:

		//! Constructor
		TeAddressLocator(TeDatabase* db)
			: db_(db), referenceLayer_(0), isMetadataLoaded_(false), errMsg_(""), changeSpecialChars_(false), removeHifen_(false), removeHifenFromCentroid_(false)
		{
		}

		//! Virtual destructor
		virtual ~TeAddressLocator()
		{
		}
		
		//! Creates the table to store metadata for geocoding tables
		bool createAddressMetadataTable(void);

		//! Inserts a new metadata for an attribute table layer and saves in the database
		bool insertAddressMetadata(const TeAddressMetadata& metadata);

		//! Updates the metadata of an attribute table layer and saves in the database
		bool updateAddressMetadata(const TeAddressMetadata& metadata);

		//! Removes the metadata for the attribute table layer on the database an clear memory
		bool deleteAddressMetadata(const int& tableId);
		
		//! Loads a metadata for an attribute table layer
		bool loadAddressMetadata(const int& tableId);

		//! Returns true if metadata was loaded
		bool isMetadataLoaded() const
		{
			return isMetadataLoaded_;
		}

		//! Returns the metadata of the geocode base table
		TeAddressMetadata getAddressLocatorMetadata() const
		{
			return metadata_;
		}

		//! Set the metadata
		bool setAddressLocatorMetadata(const TeAddressMetadata& m);

		//! Returns the error message
		string errorMessage() const
		{
			return errMsg_;
		}

		//! Information about a layer to be used as an alternative for geocoding
		void setCentroidAddressMetadata(const TeCentroidAddressMetadata& cMetadata)
		{
			removeHifenFromCentroid_ = false;

			cmetadata_ = cMetadata;

			if(cmetadata_.fieldType_ == TeZIPCODE && !cmetadata_.centroidName_.empty() && !cmetadata_.attributeTableName_.empty())
				removeHifenFromCentroid_ = !verifyHifen(cmetadata_.attributeTableName_, cmetadata_.centroidName_);
		}

		void setReplaceSpecialChars(const bool& r)
		{
			changeSpecialChars_ = r;
		}

		bool getReplaceSpecialChars(void) const
		{
			return changeSpecialChars_;
		}

		void setSplitChar(const string& splitChar)
		{
			splitChar_ = splitChar;
		}
		
		//! Retrieves all metadata for a layer
		bool getAllAddressMetadataLayer(const int& layerId, vector<TeAddressMetadata>& addVec);

		//! Retrieves all metadata for a theme
		bool getAllAddressMetadataTheme(const int& themeId, vector<TeAddressMetadata>& addVec);

		//! Retrieves all layer name that has an address location table
		bool getAddressLocatorLayers(vector<pair<int, string> >& layerNameVec);

		//! Retrieves all layer table names that is register as an address find table for a given layerId
		bool getAddressLocatorLayerTables(vector<pair<int, string> >& tableNameVec, const int& layerId);

		//! Finds all geocoding table in a TerraLib database
		bool findGeocodingTables(vector<pair<int, string> >& tableNames);
		
		//! Looks the attribute description to transform a name location on an address
		int findAddress(const TeAddress& address, vector<TeAddressDescription>& addressesFound, const bool& doExaustiveSearch = false);

		//! Finds segment and does an interpolation
		void findCoordinates(const TeAddress& add, vector<TeAddressDescription>& addresses);

		//! Finds segment and does an interpolation
		void findCoordinate(const TeAddress& add, TeAddressDescription& address);

		//! Spatialize a table based on the indicated fields
		bool addressGeocode(TeGeocodeTableMetadata& tableMetadata,
							const string& newLayerName,
							const string& reportName,
							const string& reportDir,
							const bool& doExaustive = false,
							TeAbstractAddressNotifyFunctor* notifyFunction = 0);

		//! Load a dictionary to change words in the searched addresses 
		bool loadDictionary(const string& dictionaryFileName);

		//! 
		bool loadAddressCompoundNames();

		//! Used to make columns in upper case
		bool convertColumnNameToUpper();

		//! Used to join columns in one field
		bool addCompleteNameColumn();

	protected:

		//! Looks the attribute description to transform a name location on an address
		int findExact(const TeAddress& address, const string& fullName, const bool& withNumber, vector<TeAddressDescription>& addressesFound);

		//! Looks the attribute description to transform a name location on an address
		int findPattern(const TeAddress& address, const string& fullName, const bool& withNumber, vector<TeAddressDescription>& addressesFound, const bool& disabletype = false, const bool& disabletitle = false, const bool& disablepreposition = false);


		//! Looks the attribute description to transform a name location on an address
		int findWithDictionary(const TeAddress& address, const string& fullName, const bool& withNumber, vector<TeAddressDescription>& addressesFound);

		//! Looks the attribute description to transform a name location on an address
		int findWithoutAllName(const TeAddress& address, const string& fullName, vector<TeAddressDescription>& addressesFound, const bool& disabletype = false, const bool& disabletitle = false, const bool& disablepreposition = false);

		//! Looks the attribute description to transform a name location on an address
		bool findSimilarAddress(const TeAddress& address, const string& fullName, TeAddressDescription& descript);

		//! Try to find a centroid for zip code or neighborhood
		bool findByCentroid(const TeAddress& addressToFind, vector<TeAddressDescription>& addressesFound);

		//! Fill the metadata parameter
		void fillAddressMetadata(TeAddressMetadata& metadata, TeDatabasePortal* p);

		//! Fill address descriptions
		void fillAddressesDescription(vector<TeAddressDescription>& addresses, TeDatabasePortal* p);

		//!
		void fillAddressDescription(TeAddressDescription& descript, TeDatabasePortal* p);

		//! Fill address information
		void fillAddress(TeAddress& add, const TeGeocodeTableMetadata& tableMetadata, TeDatabasePortal* p);

		//! Mount a SQL to look for an address
		string mountExactWhereSQL(const TeAddress& address, const string& fullName);

		string mountLikeWhereSQL(const TeAddress& address, const string& fullName);

		string mountPatternWhereSQL(const TeAddress& address, const string& fullName, const bool& disabletype = false, const bool& disabletitle = false, const bool& disablepreposition = false);

		//!
		string mountSimilarWhereSQL(const TeAddress& address);

		//! Do some conversions in address fields
		void normalizeAddress(TeAddress& address, string& completeName);

		//! Removes hifen if remove flag is true
		void removeHifen(string& zipCode) const;

		//! Removes hifen if remove flag is true
		void insertHifen(string& zipCode) const;

		//! Inserts a special character in string for Like comparasion
		string makeLikeExpression(const string& str) const;

		//! Remove caracteres como ponto e troca acentuados por não acentuados
		void removeSpecialCharacters(string& str) const;

		//!
		bool verifyHifen(const string& tableName, const string& columnName);

		//!
		bool addReportColumn(TeGeocodeTableMetadata& tableMetadata, pair<string, string>& newColumns);

		//!
		bool findTableMetadata(TeGeocodeTableMetadata& tableMetadata);

		//! Update the table that contains address to be geocoded with the code returned by the geocoding process and a description of the process match
		bool updateAddressTable(const string& c1, const int& v1, TeGeocodeTableMetadata& tableMetadata, const string& objectId);

		//! Returns a portal to the address table
		TeDatabasePortal* getAddressTablePortal(TeGeocodeTableMetadata& tableMetadata, int& numRows);

		//! 
		void refineFoundedLocationsByNeighBorhood(const TeAddress& address, vector<TeAddressDescription>& addressesFound);

		//! 
		void refineFoundedLocationsByZipCode(const TeAddress& address, vector<TeAddressDescription>& addressesFound);		

		//! 
		void refineFoundedLocationsByNumberNeighboor(const TeAddress& address, vector<TeAddressDescription>& addressesFound);

		//! 
		void refineFoundedLocationsByNumberZipCode(const TeAddress& address, vector<TeAddressDescription>& addressesFound);

		void cleanAddressesFound(const string& locName, vector<TeAddressDescription>& addressesFound, const bool& disabletype = false, const bool& disabletitle = false, const bool& disablepreposition = false);

		//! Split address name and number
		void splitAddress(TeAddress& add);

		//! Only to query addresses and fill result
		void queryAddresses(const string& strSQL, bool& queryExecuted, vector<TeAddressDescription>& addressesFound);

		//! No copy allowed
		TeAddressLocator(const TeAddressLocator& other);
		TeAddressLocator& operator=(const TeAddressLocator& other);
};
/** @} */
#endif	// __TERRALIB_INTERNAL_ADDRESSLOCATOR_H