- // Hack into a modify request
- $sModifyXML = str_replace('<osm version="0.6" generator="OpenStreetMap server">',
- '<osmChange version="0.6" generator="OpenStreetMap server"><modify>', $sModifyXML);
- $sModifyXML = str_replace('</osm>', '</modify></osmChange>', $sModifyXML);
-
- // Outputing this is too verbose
- if ($aResult['verbose'] && false) var_dump($sModifyXML);
-
- $sDatabaseName = 'nominatim';
- $aSpec = array(
- 0 => array("pipe", "r"), // stdin
- 1 => array("pipe", "w"), // stdout
- 2 => array("pipe", "w") // stderr
- );
- $aPipes = array();
- $sCMD = CONST_Osm2pgsql_Binary.' -klas -C 2000 -O gazetteer -d '.$sDatabaseName.' -';
- echo $sCMD."\n";
- $hProc = proc_open($sCMD, $aSpec, $aPipes);
- if (!is_resource($hProc))
+ // derive change from normal osm file with osmosis
+ $sTemporaryFile = CONST_BasePath.'/data/osmosischange.osc';
+ if (isset($aResult['import-file']) && $aResult['import-file'])
+ {
+ $sCMD = CONST_Osmosis_Binary.' --read-xml \''.$aResult['import-file'].'\' --read-empty --derive-change --write-xml-change '.$sTemporaryFile;
+ echo $sCMD."\n";
+ exec($sCMD, $sJunk, $iErrorLevel);
+ if ($iErrorLevel)
+ {
+ echo "Error converting osm to osc, osmosis returned: $iErrorLevel\n";
+ exit;
+ }
+ }
+ else
+ {
+ $aSpec = array(
+ 0 => array("pipe", "r"), // stdin
+ 1 => array("pipe", "w"), // stdout
+ 2 => array("pipe", "w") // stderr
+ );
+ $sCMD = CONST_Osmosis_Binary.' --read-xml - --read-empty --derive-change --write-xml-change '.$sTemporaryFile;
+ echo $sCMD."\n";
+ $hProc = proc_open($sCMD, $aSpec, $aPipes);
+ if (!is_resource($hProc))
+ {
+ echo "Error converting osm to osc, osmosis failed\n";
+ exit;
+ }
+ fwrite($aPipes[0], $sModifyXMLstr);
+ fclose($aPipes[0]);
+ $sOut = stream_get_contents($aPipes[1]);
+ if ($aResult['verbose']) echo $sOut;
+ fclose($aPipes[1]);
+ $sErrors = stream_get_contents($aPipes[2]);
+ if ($aResult['verbose']) echo $sErrors;
+ fclose($aPipes[2]);
+ if ($iError = proc_close($hProc))
+ {
+ echo "Error converting osm to osc, osmosis returned: $iError\n";
+ echo $sOut;
+ echo $sErrors;
+ exit;
+ }
+ }
+
+ // import generated change file
+ $sCMD = CONST_Osm2pgsql_Binary.' -klas -C 2000 -O gazetteer -d '.$aDSNInfo['database'].' '.$sTemporaryFile;
+ if (!is_null(CONST_Osm2pgsql_Flatnode_File))