예제 #1
0
 }
 foreach ($aPartitions as $sPartition) {
     if (!pg_query($oDB->connection, 'TRUNCATE location_road_' . $sPartition)) {
         fail(pg_last_error($oDB->connection));
     }
     echo '.';
 }
 // used by getorcreate_word_id to ignore frequent partial words
 if (!pg_query($oDB->connection, 'CREATE OR REPLACE FUNCTION get_maxwordfreq() RETURNS integer AS $$ SELECT ' . CONST_Max_Word_Frequency . ' as maxwordfreq; $$ LANGUAGE SQL IMMUTABLE')) {
     fail(pg_last_error($oDB->connection));
 }
 echo ".\n";
 // pre-create the word list
 if (!$aCMDResult['disable-token-precalc']) {
     echo "Loading word list\n";
     pgsqlRunScriptFile(CONST_BasePath . '/data/words.sql');
 }
 echo "Load Data\n";
 $aDBInstances = array();
 for ($i = 0; $i < $iInstances; $i++) {
     $aDBInstances[$i] =& getDB(true);
     $sSQL = 'insert into placex (osm_type, osm_id, class, type, name, admin_level, ';
     $sSQL .= 'housenumber, street, addr_place, isin, postcode, country_code, extratags, ';
     $sSQL .= 'geometry) select * from place where osm_id % ' . $iInstances . ' = ' . $i;
     if ($aCMDResult['verbose']) {
         echo "{$sSQL}\n";
     }
     if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) {
         fail(pg_last_error($oDB->connection));
     }
 }
예제 #2
0
    while (($sLine = fgets($hFile, 4096)) !== false && $sLine && substr($sLine, 0, 1) != '#') {
        list($sClass, $sType) = explode(' ', trim($sLine));
        $sScript .= "create table place_classtype_" . $sClass . "_" . $sType . " as ";
        $sScript .= "select place_id as place_id,geometry as centroid from placex limit 0;\n";
        $sScript .= "CREATE INDEX idx_place_classtype_" . $sClass . "_" . $sType . "_centroid ";
        $sScript .= "ON place_classtype_" . $sClass . "_" . $sType . " USING GIST (centroid);\n";
        $sScript .= "CREATE INDEX idx_place_classtype_" . $sClass . "_" . $sType . "_place_id ";
        $sScript .= "ON place_classtype_" . $sClass . "_" . $sType . " USING btree(place_id);\n";
    }
    fclose($hFile);
    pgsqlRunScript($sScript);
}
if ($aCMDResult['create-tables'] || $aCMDResult['all']) {
    echo "Tables\n";
    $bDidSomething = true;
    pgsqlRunScriptFile(CONST_BasePath . '/sql/tables.sql');
    // re-run the functions
    $sTemplate = file_get_contents(CONST_BasePath . '/sql/functions.sql');
    $sTemplate = str_replace('{modulepath}', CONST_BasePath . '/module', $sTemplate);
    pgsqlRunScript($sTemplate);
}
if ($aCMDResult['create-partitions'] || $aCMDResult['all']) {
    echo "Partitions\n";
    $bDidSomething = true;
    $oDB =& getDB();
    $sSQL = 'select partition from country_name order by country_code';
    $aPartitions = $oDB->getCol($sSQL);
    if (PEAR::isError($aPartitions)) {
        fail($aPartitions->getMessage());
    }
    $aPartitions[] = 0;
예제 #3
0
        }
        fclose($hFile);
        $bAnyBusy = true;
        while ($bAnyBusy) {
            $bAnyBusy = false;
            for ($i = 0; $i < $iInstances; $i++) {
                if (pg_connection_busy($aDBInstances[$i]->connection)) {
                    $bAnyBusy = true;
                }
            }
            usleep(10);
        }
        echo "\n";
    }
    echo "Creating indexes\n";
    pgsqlRunScriptFile(CONST_BasePath . '/sql/tiger_import_finish.sql');
}
if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {
    $bDidSomething = true;
    $oDB =& getDB();
    if (!pg_query($oDB->connection, 'DELETE from placex where osm_type=\'P\'')) {
        fail(pg_last_error($oDB->connection));
    }
    $sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,calculated_country_code,geometry) ";
    $sSQL .= "select 'P',nextval('seq_postcodes'),'place','postcode',postcode,calculated_country_code,";
    $sSQL .= "ST_SetSRID(ST_Point(x,y),4326) as geometry from (select calculated_country_code,postcode,";
    $sSQL .= "avg(st_x(st_centroid(geometry))) as x,avg(st_y(st_centroid(geometry))) as y ";
    $sSQL .= "from placex where postcode is not null group by calculated_country_code,postcode) as x";
    if (!pg_query($oDB->connection, $sSQL)) {
        fail(pg_last_error($oDB->connection));
    }