http://lemuria.org/dragoneye/index.php?title=Fix_population&feed=atom&action=historyFix population - Revision history2024-03-29T11:20:33ZRevision history for this page on the wikiMediaWiki 1.36.0http://lemuria.org/dragoneye/index.php?title=Fix_population&diff=1550&oldid=prevTom: Created page with "Save this as fix_population.php and use it as outlined in part 3 of the video tutorial, feeding it the burgs.csv file from Azgaar's FMG. <source> <?php $fp = fopen("php://st..."2019-12-09T08:53:15Z<p>Created page with "Save this as fix_population.php and use it as outlined in part 3 of the video tutorial, feeding it the burgs.csv file from Azgaar's FMG. <source> <?php $fp = fopen("php://st..."</p>
<p><b>New page</b></p><div>Save this as fix_population.php and use it as outlined in part 3 of the video tutorial, feeding it the burgs.csv file from Azgaar's FMG.<br />
<br />
<source><br />
<?php<br />
<br />
$fp = fopen("php://stdin", "r") or die("cannot open stdin");<br />
<br />
$input_data = file_get_contents("php://stdin");<br />
<br />
$json = json_decode($input_data);<br />
<br />
foreach ($json->features as &$feature) {<br />
preg_match('/([0-9\.]+K?) \(([0-9\.]+K?) rural, urban ([0-9\.]+K?)\)/', $feature->properties->population, $matches);<br />
if ($matches[1] > 0) {<br />
$feature->properties->population = k_to_number($matches[1]);<br />
$feature->properties->rural = k_to_number($matches[2]);<br />
$feature->properties->urban = k_to_number($matches[3]);<br />
}<br />
}<br />
<br />
function k_to_number($data) {<br />
if (preg_match('/([0-9]+)(\.([0-9])+)?K/', $data, $matches)) {<br />
if (isset($matches[3])) {<br />
return $matches[1].$matches[3].'00';<br />
} else {<br />
return $matches[1].'000';<br />
}<br />
} else {<br />
return $data;<br />
}<br />
}<br />
<br />
echo json_encode($json, JSON_PRETTY_PRINT);<br />
<br />
?><br />
</source></div>Tom