Skip to content

Commit

Permalink
Generate GeoJSON instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
repeat committed Nov 16, 2013
1 parent 4d73162 commit 9ea3e05
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion hsr.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,43 @@
foreach ($lines as $line) {
$stations[] = str_getcsv($line);
}
echo json_encode($stations, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

// remove keys.
unset($stations[0]);

$geometry = [
'type' => 'Point'
];

foreach ($stations as $station) {
list($id, $name, $zipcode, $address, $lat, $lon, $future) = $station;

if (1 == $future) {
continue;
}

$geometry['coordinates'] = [(float) $lon, (float) $lat];
$properties = [
'編號' => (string) $id,
'站名' => $name,
'郵遞區號' => (int) $zipcode,
'地址' => $address,
'緯度' => (float) $lat,
'經度' => (float) $lon
];

$feature = [
'type' => 'Feature',
'geometry' => $geometry,
'properties' => $properties
];

$features[] = $feature;
}

$geojson = [
'type' => 'FeatureCollection',
'features' => $features
];

echo json_encode($geojson, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

0 comments on commit 9ea3e05

Please sign in to comment.