Skip to content

Instantly share code, notes, and snippets.

@wboykinm
Last active December 23, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wboykinm/6639131 to your computer and use it in GitHub Desktop.
Save wboykinm/6639131 to your computer and use it in GitHub Desktop.
<?php
header('Content-type: text/plain');
# Grab URL
$ch = curl_init($_GET['url']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$urlin = curl_exec($ch);
curl_close($ch);
# Load it in as XML
$xmlin = simplexml_load_file($urlin);
# Build GeoJSON feature collection array
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
);
# Loop through rows to build feature arrays
foreach ($xmlin->iati-activity->location as $site):
$feature = array(
'type' => 'Feature',
'geometry' => array(
'type' => 'Point',
'coordinates' => array(
(float)$site->coordinates['longitude'],
(float)$site->coordinates['latitude']
)
),
'title' => (string)$site->xpath('..')->title,
'description' => (string)$site->xpath('..')->description,
'sector' => (string)$site->xpath('..')->sector,
'collaboration-type' => (string)$site->xpath('..')->collaboration-type,
'gazetteer-entry' => (string)$site->gazetteer-entry
);
array_push($geojson['features'], $feature);
endforeach;
# Push GeoJSON Output
header('Content-type: application/json');
echo json_encode($geojson, JSON_NUMERIC_CHECK);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment