]> git.openstreetmap.org Git - nominatim.git/blobdiff - utils/setup.php
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / utils / setup.php
index 1ebee32ff1104df99e85cfbb4c2ed8bdb4bc995a..6dc8772499d7fb06db99b578aab4671cf890959c 100755 (executable)
                pgsqlRunScriptFile(CONST_BasePath.'/data/us_statecounty.sql');
                pgsqlRunScriptFile(CONST_BasePath.'/data/us_state.sql');
                pgsqlRunScriptFile(CONST_BasePath.'/data/us_postcode.sql');
-               pgsqlRunScriptFile(CONST_BasePath.'/data/worldboundaries.sql');
        }
 
        if ($aCMDResult['import-data'] || $aCMDResult['all'])
                        echo "Please download and build osm2pgsql.\nIf it is already installed, check the path in your local settings (settings/local.php) file.\n";
                        fail("osm2pgsql not found in '$osm2pgsql'");
                }
+               $osm2pgsql .= ' --tablespace-slim-index ssd --tablespace-main-index ssd --tablespace-main-data ssd --tablespace-slim-data data';
                $osm2pgsql .= ' -lsc -O gazetteer --hstore';
-               $osm2pgsql .= ' -C '.$iCacheMemory;
+               $osm2pgsql .= ' -C 16000';
                $osm2pgsql .= ' -P '.$aDSNInfo['port'];
                $osm2pgsql .= ' -d '.$aDSNInfo['database'].' '.$aCMDResult['osm-file'];
                passthruCheckReturn($osm2pgsql);
                $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";
+               $sSQL .= "from placex where postcode is not null and calculated_country_code not in ('ie') group by calculated_country_code,postcode) as x";
                if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection));
 
                $sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,calculated_country_code,geometry) ";
                $bDidSomething = true;
                $oDB =& getDB();
 
-               if (!file_exists(CONST_Osmosis_Binary)) fail("please download osmosis");
+               if (!file_exists(CONST_Osmosis_Binary))
+               {
+                       echo "Please download osmosis.\nIf it is already installed, check the path in your local settings (settings/local.php) file.\n";
+                       fail("osmosis not found in '".CONST_Osmosis_Binary."'");
+               }
                if (file_exists(CONST_BasePath.'/settings/configuration.txt'))
                {
                        echo "settings/configuration.txt already exists\n";
                else
                {
                        passthru(CONST_Osmosis_Binary.' --read-replication-interval-init '.CONST_BasePath.'/settings');
-                       // server layout changed afer license change, fix path to minutely diffs
-                       passthru("sed -i 's:minute-replicate:replication/minute:' ".CONST_BasePath.'/settings/configuration.txt');
+                       // update osmosis configuration.txt with our settings
+                       passthru("sed -i 's!baseUrl=.*!baseUrl=".CONST_Replication_Url."!' ".CONST_BasePath.'/settings/configuration.txt');
+                       passthru("sed -i 's:maxInterval = .*:maxInterval = ".CONST_Replication_MaxInterval.":' ".CONST_BasePath.'/settings/configuration.txt');
                }
 
                // Find the last node in the DB
-               $iLastOSMID = $oDB->getOne("select max(osm_id) as osm_id from place where osm_type = 'N'");
+               $iLastOSMID = $oDB->getOne("select max(id) from planet_osm_nodes");
 
                // Lookup the timestamp that node was created (less 3 hours for margin for changsets to be closed)
-               $sLastNodeURL = 'http://www.openstreetmap.org/api/0.6/node/'.$iLastOSMID;
+               $sLastNodeURL = 'http://www.openstreetmap.org/api/0.6/node/'.$iLastOSMID."/1";
                $sLastNodeXML = file_get_contents($sLastNodeURL);
                preg_match('#timestamp="(([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z)"#', $sLastNodeXML, $aLastNodeDate);
                $iLastNodeTimestamp = strtotime($aLastNodeDate[1]) - (3*60*60);
 
 
-               // Search for the correct state file - uses file timestamps
-               $sRepURL = 'http://planet.openstreetmap.org/replication/minute/';
-               $sRep = file_get_contents($sRepURL);
-               preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a> *(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER);
+               // Search for the correct state file - uses file timestamps so need to sort by date descending
+               $sRepURL = CONST_Replication_Url."/";
+               $sRep = file_get_contents($sRepURL."?C=M;O=D");
+               // download.geofabrik.de:    <a href="000/">000/</a></td><td align="right">26-Feb-2013 11:53  </td>
+               // planet.openstreetmap.org: <a href="273/">273/</a>                    22-Mar-2013 07:41    -
+               preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a>.*(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER);
                $aPrevRepMatch = false;
                foreach($aRepMatches as $aRepMatch)
                {
                if ($aPrevRepMatch) $aRepMatch = $aPrevRepMatch;
 
                $sRepURL .= $aRepMatch[1];
-               $sRep = file_get_contents($sRepURL);
-               preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a> *(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER);
+               $sRep = file_get_contents($sRepURL."?C=M;O=D");
+               preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a>.*(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER);
                $aPrevRepMatch = false;
                foreach($aRepMatches as $aRepMatch)
                {
                if ($aPrevRepMatch) $aRepMatch = $aPrevRepMatch;
 
                $sRepURL .= $aRepMatch[1];
-               $sRep = file_get_contents($sRepURL);
-               preg_match_all('#<a href="[0-9]{3}.state.txt">([0-9]{3}).state.txt</a> *(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER);
+               $sRep = file_get_contents($sRepURL."?C=M;O=D");
+               preg_match_all('#<a href="[0-9]{3}.state.txt">([0-9]{3}).state.txt</a>.*(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER);
                $aPrevRepMatch = false;
                foreach($aRepMatches as $aRepMatch)
                {
                @symlink(CONST_BasePath.'/website/search.php', $sTargetDir.'/index.php');
                @symlink(CONST_BasePath.'/website/deletable.php', $sTargetDir.'/deletable.php');
                @symlink(CONST_BasePath.'/website/polygons.php', $sTargetDir.'/polygons.php');
+               @symlink(CONST_BasePath.'/website/status.php', $sTargetDir.'/status.php');
                @symlink(CONST_BasePath.'/website/images', $sTargetDir.'/images');
                @symlink(CONST_BasePath.'/website/js', $sTargetDir.'/js');
                @symlink(CONST_BasePath.'/website/css', $sTargetDir.'/css');