Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Commit

Permalink
Lower precision of lat/lon
Browse files Browse the repository at this point in the history
  • Loading branch information
khawkins98 committed Jun 12, 2018
1 parent 941aa3e commit 4971c68
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions parseLogMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
if (time() - filemtime($cacheFileName) < 6) {
header("Map-cache-creation: ". urlencode(filemtime($cacheFileName)));
header("Map-cache-server-time: ". urlencode(time()));
require $cacheFileName;
require $cacheFileName;
exit; // dump the cahced contents and go home
}
}
Expand All @@ -40,7 +40,7 @@
// what's been requested
switch ($desiredFile) {
case 'all':
default:
default:
$desiredFile = 'all'; // cleanup wild url requests
$desiredFiles = array($dataSources["ebi"],$dataSources["portals"],$dataSources["uniprot"]);
$pointType = array('markerClustersEBI','markerClustersPortals','markerClustersUniprot');
Expand All @@ -66,16 +66,30 @@ function curlFileAsXml($url) {
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

if (empty($buffer)) {
return "Nothing returned from url.";
} else {
return simplexml_load_string($buffer);
}
}

// Reusable function to fuzzy-ify the lat/long string
// in: 0.7000,51.5333,0
// out: 0.70,51.53,0
function lowerPrecision($incoming) {
$processed = explode(",", $incoming);

$processed[0] = round($processed[0], 2);
$processed[1] = round($processed[1], 2);

$output = $processed[0] . "," . $processed[1] . "," . $processed[2];

return $output;
}

// Write the data CSV
// -----------
// CSV header
Expand All @@ -90,7 +104,7 @@ function curlFileAsXml($url) {
$rowCounter = 0;
foreach($fetchedData as $item) {
$rowCounter++;
$output .= $pointType[$key] . ",".$item->Point->coordinates . "\r\n";
$output .= $pointType[$key] . "," . lowerPrecision($item->Point->coordinates) . "\r\n";
}
}

Expand All @@ -100,4 +114,4 @@ function curlFileAsXml($url) {
// save to the cache
file_put_contents($cacheFileName, $output);

?>
?>

1 comment on commit 4971c68

@jonathanhickford
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.