| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/functions/TeAddressLocator.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright � 2001-2007 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular purpose.
    00017 The library provided hereunder is on an "as is" basis, and the authors have no
    00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00020 indirect, special, incidental, or consequential damages arising out of the use
    00021 of this library and its documentation.
    00022 *************************************************************************************/
    00031 #ifndef  __TERRALIB_INTERNAL_ADDRESSLOCATOR_H
    00032 #define  __TERRALIB_INTERNAL_ADDRESSLOCATOR_H
    00033
    00034 #include "../kernel/TeDatabase.h"
    00035 #include "../kernel/TeLayer.h"
    00036
    00037 #include "TeFunctionsDefines.h"
    00038
    00039 #include <string>
    00040 #include <map>
    00041
    00042 using namespace std;
    00043
    00049
    00050 typedef multimap<string, string> TeGeocoderDictionary;
    00051
    00052
    00056 struct TLFUNCTIONS_DLL TeAddressMetadata
    00057 {
    00058            int tableId_;
    00059            string tableName_;
    00060            string linkColumnName_;
    00061            string initialLeftNumber_;
    00062            string finalLeftNumber_;
    00063            string initialRightNumber_;
    00064            string finalRightNumber_;
    00065            string locationType_;
    00066            string locationTitle_;
    00067            string locationPreposition_;
    00068            string locationName_;
    00069            string locationCompleteName_;
    00070            string leftNeighborhood_;
    00071            string rightNeighborhood_;
    00072            string leftZipCode_;
    00073            string rightZipCode_;
    00074 };
    00075
    00077 TLFUNCTIONS_DLL enum TeCentroidFieldType { TeNEIGHBORHOOD, TeZIPCODE };
    00078
    00082 struct TLFUNCTIONS_DLL TeCentroidAddressMetadata
    00083 {
    00084            string centroidName_;
    00085
    00086            TeCentroidFieldType fieldType_;
    00087
    00088            string attributeTableName_;
    00089
    00090            TeLayer* centroidLayer_;
    00091
    00092            TeCentroidAddressMetadata()
    00093                       : centroidLayer_(0)
    00094            {
    00095            }
    00096 };
    00097
    00101 struct TLFUNCTIONS_DLL TeGeocodeTableMetadata
    00102 {
    00103            string tableName_;
    00104            string linkColumnName_;
    00105            string keyColumnName_;
    00106            int tableId_;
    00107            string locationTypeColumnName_;
    00108            string locationTitleColumnName_;
    00109            string locationPrepositionColumnName_;
    00110            string locationNameColumnName_;
    00111            string locationNumberColumnName_;
    00112            string neighborhoodColumnName_;
    00113            string zipCodeColumnName_;
    00114 };
    00115
    00116
    00120 struct TLFUNCTIONS_DLL TeAddress
    00121 {
    00122            string locationLink_;
    00123            string locationType_;
    00124            string locationTitle_;
    00125            string locationPreposition_;
    00126            string locationName_;
    00127            int locationNumber_;
    00128            string neighborhood_;
    00129            string zipCode_;
    00130 };
    00131
    00132
    00133 /* \struct TeAddressDescription
    00134            Information about a found address
    00135  */
    00136 struct TLFUNCTIONS_DLL TeAddressDescription
    00137 {
    00138            string locationLink_;
    00139            int initialLeftNumber_;
    00140            int finalLeftNumber_;
    00141            int initialRightNumber_;
    00142            int finalRightNumber_;
    00143            string locationType_;
    00144            string locationTitle_;
    00145            string locationPreposition_;
    00146            string locationName_;
    00147            string locationCompleteName_;
    00148            string leftNeighborhood_;
    00149            string rightNeighborhood_;
    00150            string leftZipCode_;
    00151            string rightZipCode_;
    00152            TeCoord2D pt_;
    00153            bool isValid_;
    00154
    00155            TeAddressDescription()
    00156                       : locationLink_(""), initialLeftNumber_(0), finalLeftNumber_(0),
    00157                         initialRightNumber_(0), finalRightNumber_(0), locationType_(""),
    00158                         locationTitle_(""), locationPreposition_(""), locationName_(""), locationCompleteName_(""),
    00159                         leftNeighborhood_(""), rightNeighborhood_(""), leftZipCode_(""),
    00160                         rightZipCode_(""), isValid_(false)
    00161            {
    00162            }
    00163 };
    00164
    00165
    00167
    00170 class TLFUNCTIONS_DLL TeAbstractAddressNotifyFunctor
    00171 {
    00172            public:
    00173
    00174                       virtual int operator()(const TeAddress& searchedAddress, vector<TeAddressDescription>& foundAddresses) = 0;
    00175
    00176                       virtual ~TeAbstractAddressNotifyFunctor()
    00177                       {
    00178                       }
    00179 };
    00180
    00182
    00187 class TLFUNCTIONS_DLL TeAddressLocator
    00188 {
    00189            protected:
    00190
    00191                       TeDatabase* db_;
    00192                       TeAddressMetadata metadata_;
    00193                       TeLayer* referenceLayer_;
    00194                       TeCentroidAddressMetadata cmetadata_;
    00195                       bool isMetadataLoaded_;
    00196                       string errMsg_;
    00197                       TeGeocoderDictionary dictionary_;
    00198                       bool changeSpecialChars_;
    00199                       bool removeHifen_;
    00200                       bool removeHifenFromCentroid_;
    00201                       char hifen_;
    00202                       string splitChar_;
    00203
    00204                       vector<string> typesVector_;
    00205                       vector<string> titlesVector_;
    00206                       vector<string> prepositionsVector_;
    00207
    00208            public:
    00209
    00211                       TeAddressLocator(TeDatabase* db)
    00212                                  : db_(db), referenceLayer_(0), isMetadataLoaded_(false), errMsg_(""), changeSpecialChars_(false), removeHifen_(false), removeHifenFromCentroid_(false)
    00213                       {
    00214                       }
    00215
    00217                       virtual ~TeAddressLocator()
    00218                       {
    00219                       }
    00220
    00222                       bool createAddressMetadataTable(void);
    00223
    00225                       bool insertAddressMetadata(const TeAddressMetadata& metadata);
    00226
    00228                       bool updateAddressMetadata(const TeAddressMetadata& metadata);
    00229
    00231                       bool deleteAddressMetadata(const int& tableId);
    00232
    00234                       bool loadAddressMetadata(const int& tableId);
    00235
    00237                       bool isMetadataLoaded() const
    00238                       {
    00239                                  return isMetadataLoaded_;
    00240                       }
    00241
    00243                       TeAddressMetadata getAddressLocatorMetadata() const
    00244                       {
    00245                                  return metadata_;
    00246                       }
    00247
    00249                       bool setAddressLocatorMetadata(const TeAddressMetadata& m);
    00250
    00252                       string errorMessage() const
    00253                       {
    00254                                  return errMsg_;
    00255                       }
    00256
    00258                       void setCentroidAddressMetadata(const TeCentroidAddressMetadata& cMetadata)
    00259                       {
    00260                                  removeHifenFromCentroid_ = false;
    00261
    00262                                  cmetadata_ = cMetadata;
    00263
    00264                                  if(cmetadata_.fieldType_ == TeZIPCODE && !cmetadata_.centroidName_.empty() && !cmetadata_.attributeTableName_.empty())
    00265                                             removeHifenFromCentroid_ = !verifyHifen(cmetadata_.attributeTableName_, cmetadata_.centroidName_);
    00266                       }
    00267
    00268                       void setReplaceSpecialChars(const bool& r)
    00269                       {
    00270                                  changeSpecialChars_ = r;
    00271                       }
    00272
    00273                       bool getReplaceSpecialChars(void) const
    00274                       {
    00275                                  return changeSpecialChars_;
    00276                       }
    00277
    00278                       void setSplitChar(const string& splitChar)
    00279                       {
    00280                                  splitChar_ = splitChar;
    00281                       }
    00282
    00284                       bool getAllAddressMetadataLayer(const int& layerId, vector<TeAddressMetadata>& addVec);
    00285
    00287                       bool getAllAddressMetadataTheme(const int& themeId, vector<TeAddressMetadata>& addVec);
    00288
    00290                       bool getAddressLocatorLayers(vector<pair<int, string> >& layerNameVec);
    00291
    00293                       bool getAddressLocatorLayerTables(vector<pair<int, string> >& tableNameVec, const int& layerId);
    00294
    00296                       bool findGeocodingTables(vector<pair<int, string> >& tableNames);
    00297
    00299                       int findAddress(const TeAddress& address, vector<TeAddressDescription>& addressesFound, const bool& doExaustiveSearch = false);
    00300
    00302                       void findCoordinates(const TeAddress& add, vector<TeAddressDescription>& addresses);
    00303
    00305                       void findCoordinate(const TeAddress& add, TeAddressDescription& address);
    00306
    00308                       bool addressGeocode(TeGeocodeTableMetadata& tableMetadata,
    00309                                                                              const string& newLayerName,
    00310                                                                              const string& reportName,
    00311                                                                              const string& reportDir,
    00312                                                                              const bool& doExaustive = false,
    00313                                                                              TeAbstractAddressNotifyFunctor* notifyFunction = 0);
    00314
    00316                       bool loadDictionary(const string& dictionaryFileName);
    00317
    00319                       bool loadAddressCompoundNames();
    00320
    00322                       bool convertColumnNameToUpper();
    00323
    00325                       bool addCompleteNameColumn();
    00326
    00327            protected:
    00328
    00330                       int findExact(const TeAddress& address, const string& fullName, const bool& withNumber, vector<TeAddressDescription>& addressesFound);
    00331
    00333                       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);
    00334
    00335
    00337                       int findWithDictionary(const TeAddress& address, const string& fullName, const bool& withNumber, vector<TeAddressDescription>& addressesFound);
    00338
    00340                       int findWithoutAllName(const TeAddress& address, const string& fullName, vector<TeAddressDescription>& addressesFound, const bool& disabletype = false, const bool& disabletitle = false, const bool& disablepreposition = false);
    00341
    00343                       bool findSimilarAddress(const TeAddress& address, const string& fullName, TeAddressDescription& descript);
    00344
    00346                       bool findByCentroid(const TeAddress& addressToFind, vector<TeAddressDescription>& addressesFound);
    00347
    00349                       void fillAddressMetadata(TeAddressMetadata& metadata, TeDatabasePortal* p);
    00350
    00352                       void fillAddressesDescription(vector<TeAddressDescription>& addresses, TeDatabasePortal* p);
    00353
    00355                       void fillAddressDescription(TeAddressDescription& descript, TeDatabasePortal* p);
    00356
    00358                       void fillAddress(TeAddress& add, const TeGeocodeTableMetadata& tableMetadata, TeDatabasePortal* p);
    00359
    00361                       string mountExactWhereSQL(const TeAddress& address, const string& fullName);
    00362
    00363                       string mountLikeWhereSQL(const TeAddress& address, const string& fullName);
    00364
    00365                       string mountPatternWhereSQL(const TeAddress& address, const string& fullName, const bool& disabletype = false, const bool& disabletitle = false, const bool& disablepreposition = false);
    00366
    00368                       string mountSimilarWhereSQL(const TeAddress& address);
    00369
    00371                       void normalizeAddress(TeAddress& address, string& completeName);
    00372
    00374                       void removeHifen(string& zipCode) const;
    00375
    00377                       void insertHifen(string& zipCode) const;
    00378
    00380                       string makeLikeExpression(const string& str) const;
    00381
    00383                       void removeSpecialCharacters(string& str) const;
    00384
    00386                       bool verifyHifen(const string& tableName, const string& columnName);
    00387
    00389                       bool addReportColumn(TeGeocodeTableMetadata& tableMetadata, pair<string, string>& newColumns);
    00390
    00392                       bool findTableMetadata(TeGeocodeTableMetadata& tableMetadata);
    00393
    00395                       bool updateAddressTable(const string& c1, const int& v1, TeGeocodeTableMetadata& tableMetadata, const string& objectId);
    00396
    00398                       TeDatabasePortal* getAddressTablePortal(TeGeocodeTableMetadata& tableMetadata, int& numRows);
    00399
    00401                       void refineFoundedLocationsByNeighBorhood(const TeAddress& address, vector<TeAddressDescription>& addressesFound);
    00402
    00404                       void refineFoundedLocationsByZipCode(const TeAddress& address, vector<TeAddressDescription>& addressesFound);
    00405
    00407                       void refineFoundedLocationsByNumberNeighboor(const TeAddress& address, vector<TeAddressDescription>& addressesFound);
    00408
    00410                       void refineFoundedLocationsByNumberZipCode(const TeAddress& address, vector<TeAddressDescription>& addressesFound);
    00411
    00412                       void cleanAddressesFound(const string& locName, vector<TeAddressDescription>& addressesFound, const bool& disabletype = false, const bool& disabletitle = false, const bool& disablepreposition = false);
    00413
    00415                       void splitAddress(TeAddress& add);
    00416
    00418                       void queryAddresses(const string& strSQL, bool& queryExecuted, vector<TeAddressDescription>& addressesFound);
    00419
    00421                       TeAddressLocator(const TeAddressLocator& other);
    00422                       TeAddressLocator& operator=(const TeAddressLocator& other);
    00423 };
    00425 #endif     // __TERRALIB_INTERNAL_ADDRESSLOCATOR_H
    00426

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines