예제 #1
0
function getAddressDetails(&$oDB, $sLanguagePrefArraySQL, $iPlaceID, $sCountryCode = false, $bRaw = false)
{
    $sSQL = "select *,get_name_by_language(name,{$sLanguagePrefArraySQL}) as localname from get_addressdata({$iPlaceID})";
    if (!$bRaw) {
        $sSQL .= " WHERE isaddress OR type = 'country_code'";
    }
    $sSQL .= " order by rank_address desc,isaddress desc";
    $aAddressLines = $oDB->getAll($sSQL);
    if (PEAR::IsError($aAddressLines)) {
        var_dump($aAddressLines);
        exit;
    }
    if ($bRaw) {
        return $aAddressLines;
    }
    //echo "<pre>";
    //var_dump($aAddressLines);
    $aAddress = array();
    $aClassType = getClassTypes();
    foreach ($aAddressLines as $aLine) {
        $aTypeLabel = false;
        if (isset($aClassType[$aLine['class'] . ':' . $aLine['type'] . ':' . $aLine['admin_level']])) {
            $aTypeLabel = $aClassType[$aLine['class'] . ':' . $aLine['type'] . ':' . $aLine['admin_level']];
        } elseif (isset($aClassType[$aLine['class'] . ':' . $aLine['type']])) {
            $aTypeLabel = $aClassType[$aLine['class'] . ':' . $aLine['type']];
        } else {
            $aTypeLabel = array('simplelabel' => $aLine['class']);
        }
        if ($aTypeLabel && ($aLine['localname'] || $aLine['housenumber'])) {
            $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel']) ? $aTypeLabel['simplelabel'] : $aTypeLabel['label']);
            $sTypeLabel = str_replace(' ', '_', $sTypeLabel);
            if (!isset($aAddress[$sTypeLabel]) && $aLine['localname']) {
                $aAddress[$sTypeLabel] = $aLine['localname'] ? $aLine['localname'] : $aLine['housenumber'];
            }
        }
    }
    //var_dump($aAddress);
    //exit;
    return $aAddress;
    $aHouseNumber = $oDB->getRow('select housenumber, get_name_by_language(name,ARRAY[\'addr:housename\']) as housename,rank_search,postcode from placex where place_id = ' . $iPlaceID);
    $sHouseNumber = $aHouseNumber['housenumber'];
    $sHouseName = $aHouseNumber['housename'];
    $sPostcode = $aHouseNumber['postcode'];
    $iRank = $aHouseNumber['rank_search'];
    // Address
    $sSQL = "select country_code, placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, ";
    $sSQL .= "get_searchrank_label(rank_search) as rank_search_label, fromarea, isaddress, distance, ";
    $sSQL .= " CASE WHEN type = 'postcode' THEN postcode ELSE get_name_by_language(name,{$sLanguagePrefArraySQL}) END as localname, ";
    $sSQL .= " length(name::text) as namelength ";
    $sSQL .= " from place_addressline join placex on (address_place_id = placex.place_id)";
    $sSQL .= " where place_addressline.place_id = {$iPlaceID} and (rank_address > 0 OR address_place_id = {$iPlaceID})";
    if (!$bRaw) {
        $sSQL .= " and isaddress";
    }
    $sSQL .= " order by cached_rank_address desc,isaddress desc,fromarea desc,distance asc,rank_search desc,namelength desc";
    //var_dump($sSQL);
    $aAddressLines = $oDB->getAll($sSQL);
    if (PEAR::IsError($aAddressLines)) {
        var_dump($aAddressLines);
        exit;
    }
    if ($bRaw) {
        return $aAddressLines;
    }
    $aClassType = getClassTypes();
    $iMinRank = 100;
    $aAddress = array();
    if ($iRank >= 28 && $sHouseNumber) {
        $aAddress['house_number'] = $sHouseNumber;
    }
    if ($iRank >= 28 && $sHouseName) {
        $aAddress['house_name'] = $sHouseName;
    }
    foreach ($aAddressLines as $aLine) {
        if (!$sCountryCode) {
            $sCountryCode = $aLine['country_code'];
        }
        if ($aLine['rank_address'] < $iMinRank) {
            $aTypeLabel = false;
            if (isset($aClassType[$aLine['class'] . ':' . $aLine['type'] . ':' . $aLine['admin_level']])) {
                $aTypeLabel = $aClassType[$aLine['class'] . ':' . $aLine['type'] . ':' . $aLine['admin_level']];
            } elseif (isset($aClassType[$aLine['class'] . ':' . $aLine['type']])) {
                $aTypeLabel = $aClassType[$aLine['class'] . ':' . $aLine['type']];
            } else {
                $aTypeLabel = array('simplelabel' => $aLine['class']);
            }
            if ($aTypeLabel && ($aLine['localname'] || $aLine['housenumber'])) {
                $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel']) ? $aTypeLabel['simplelabel'] : $aTypeLabel['label']);
                $sTypeLabel = str_replace(' ', '_', $sTypeLabel);
                if (!isset($aAddress[$sTypeLabel]) && $aLine['localname']) {
                    $aAddress[$sTypeLabel] = $aLine['localname'] ? $aLine['localname'] : $aLine['housenumber'];
                }
            }
            $iMinRank = $aLine['rank_address'];
        }
    }
    if ($sPostcode) {
        $aAddress['postcode'] = $sPostcode;
    }
    if ($iMinRank > 4 && $sCountryCode) {
        $sSQL = "select get_name_by_language(country_name.name,{$sLanguagePrefArraySQL}) as name";
        $sSQL .= " from country_name where country_code = '{$sCountryCode}'";
        $sCountryName = $oDB->getOne($sSQL);
        if ($sCountryName) {
            $aAddress['country'] = $sCountryName;
        }
    }
    if ($sCountryCode) {
        $aAddress['country_code'] = $sCountryCode;
    }
    return $aAddress;
}
예제 #2
0
파일: lib.php 프로젝트: physycom/Nominatim
function getAddressDetails(&$oDB, $sLanguagePrefArraySQL, $iPlaceID, $sCountryCode = false, $bRaw = false)
{
    $sSQL = "select *,get_name_by_language(name,{$sLanguagePrefArraySQL}) as localname from get_addressdata({$iPlaceID})";
    if (!$bRaw) {
        $sSQL .= " WHERE isaddress OR type = 'country_code'";
    }
    $sSQL .= " order by rank_address desc,isaddress desc";
    $aAddressLines = $oDB->getAll($sSQL);
    if (PEAR::IsError($aAddressLines)) {
        var_dump($aAddressLines);
        exit;
    }
    if ($bRaw) {
        return $aAddressLines;
    }
    //echo "<pre>";
    //var_dump($aAddressLines);
    $aAddress = array();
    $aFallback = array();
    $aClassType = getClassTypes();
    foreach ($aAddressLines as $aLine) {
        $bFallback = false;
        $aTypeLabel = false;
        if (isset($aClassType[$aLine['class'] . ':' . $aLine['type'] . ':' . $aLine['admin_level']])) {
            $aTypeLabel = $aClassType[$aLine['class'] . ':' . $aLine['type'] . ':' . $aLine['admin_level']];
        } elseif (isset($aClassType[$aLine['class'] . ':' . $aLine['type']])) {
            $aTypeLabel = $aClassType[$aLine['class'] . ':' . $aLine['type']];
        } elseif (isset($aClassType['boundary:administrative:' . (int) ($aLine['rank_address'] / 2)])) {
            $aTypeLabel = $aClassType['boundary:administrative:' . (int) ($aLine['rank_address'] / 2)];
            $bFallback = true;
        } else {
            $aTypeLabel = array('simplelabel' => 'address' . $aLine['rank_address']);
            $bFallback = true;
        }
        if ($aTypeLabel && (isset($aLine['localname']) && $aLine['localname'] || isset($aLine['housenumber']) && $aLine['housenumber'])) {
            $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel']) ? $aTypeLabel['simplelabel'] : $aTypeLabel['label']);
            $sTypeLabel = str_replace(' ', '_', $sTypeLabel);
            if (!isset($aAddress[$sTypeLabel]) || isset($aFallback[$sTypeLabel]) && $aFallback[$sTypeLabel] || $aLine['class'] == 'place') {
                $aAddress[$sTypeLabel] = $aLine['localname'] ? $aLine['localname'] : $aLine['housenumber'];
            }
            $aFallback[$sTypeLabel] = $bFallback;
        }
    }
    return $aAddress;
}
예제 #3
0
        }
    }
}
if ($iPlaceID) {
    $sSQL = "select placex.*,";
    $sSQL .= " get_address_by_language(place_id, {$sLanguagePrefArraySQL}) as langaddress,";
    $sSQL .= " get_name_by_language(name, {$sLanguagePrefArraySQL}) as placename,";
    $sSQL .= " get_name_by_language(name, ARRAY['ref']) as ref,";
    $sSQL .= " st_y(st_centroid(geometry)) as lat, st_x(st_centroid(geometry)) as lon";
    $sSQL .= " from placex where place_id = {$iPlaceID} ";
    //var_dump($sSQL);
    $aPlace = $oDB->getRow($sSQL);
    if ($bShowAddressDetails) {
        $aAddress = getAddressDetails($oDB, $sLanguagePrefArraySQL, $iPlaceID, $aPlace['country_code']);
    }
    $aClassType = getClassTypes();
    $sAddressType = '';
    $sClassType = $aPlace['class'] . ':' . $aPlace['type'] . ':' . $aPlace['admin_level'];
    if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel'])) {
        $sAddressType = $aClassType[$aClassType]['simplelabel'];
    } else {
        $sClassType = $aPlace['class'] . ':' . $aPlace['type'];
        if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel'])) {
            $sAddressType = $aClassType[$sClassType]['simplelabel'];
        } else {
            $sAddressType = $aPlace['class'];
        }
    }
    $aPlace['addresstype'] = $sAddressType;
}
include CONST_BasePath . '/lib/template/address-' . $sOutputFormat . '.php';
예제 #4
0
 function getAddressNames()
 {
     $aAddressLines = $this->getAddressDetails(false);
     $aAddress = array();
     $aFallback = array();
     $aClassType = getClassTypes();
     foreach ($aAddressLines as $aLine) {
         $bFallback = false;
         $aTypeLabel = false;
         if (isset($aClassType[$aLine['class'] . ':' . $aLine['type'] . ':' . $aLine['admin_level']])) {
             $aTypeLabel = $aClassType[$aLine['class'] . ':' . $aLine['type'] . ':' . $aLine['admin_level']];
         } elseif (isset($aClassType[$aLine['class'] . ':' . $aLine['type']])) {
             $aTypeLabel = $aClassType[$aLine['class'] . ':' . $aLine['type']];
         } elseif (isset($aClassType['boundary:administrative:' . (int) ($aLine['rank_address'] / 2)])) {
             $aTypeLabel = $aClassType['boundary:administrative:' . (int) ($aLine['rank_address'] / 2)];
             $bFallback = true;
         } else {
             $aTypeLabel = array('simplelabel' => 'address' . $aLine['rank_address']);
             $bFallback = true;
         }
         if ($aTypeLabel && (isset($aLine['localname']) && $aLine['localname'] || isset($aLine['housenumber']) && $aLine['housenumber'])) {
             $sTypeLabel = strtolower(isset($aTypeLabel['simplelabel']) ? $aTypeLabel['simplelabel'] : $aTypeLabel['label']);
             $sTypeLabel = str_replace(' ', '_', $sTypeLabel);
             if (!isset($aAddress[$sTypeLabel]) || isset($aFallback[$sTypeLabel]) && $aFallback[$sTypeLabel] || $aLine['class'] == 'place') {
                 $aAddress[$sTypeLabel] = $aLine['localname'] ? $aLine['localname'] : $aLine['housenumber'];
             }
             $aFallback[$sTypeLabel] = $bFallback;
         }
     }
     return $aAddress;
 }