Skip to content

Instantly share code, notes, and snippets.

@totegamma
Created July 20, 2020 10:57
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 totegamma/b69227eadf3985e4fdcdbc6b8c284a50 to your computer and use it in GitHub Desktop.
Save totegamma/b69227eadf3985e4fdcdbc6b8c284a50 to your computer and use it in GitHub Desktop.
<?php
$todofuken=array(
'北海道'=>'hokkaido',
'青森県'=>'aomori',
'岩手県'=>'iwate',
'宮城県'=>'miyagi',
'秋田県'=>'akita',
'山形県'=>'yamagata',
'福島県'=>'fukushima',
'茨城県'=>'ibaraki',
'栃木県'=>'tochigi',
'群馬県'=>'gunma',
'埼玉県'=>'saitama',
'千葉県'=>'chiba',
'東京都'=>'tokyo',
'神奈川県'=>'kanagawa',
'新潟県'=>'niigata',
'富山県'=>'toyama',
'石川県'=>'ishikawa',
'福井県'=>'fukui',
'山梨県'=>'yamanashi',
'長野県'=>'nagano',
'岐阜県'=>'gifu',
'静岡県'=>'shizuoka',
'愛知県'=>'aichi',
'三重県'=>'mie',
'滋賀県'=>'shiga',
'京都府'=>'kyoto',
'大阪府'=>'osaka',
'兵庫県'=>'hyogo',
'奈良県'=>'nara',
'和歌山県'=>'wakayama',
'鳥取県'=>'tottori',
'島根県'=>'shimane',
'岡山県'=>'okayama',
'広島県'=>'hiroshima',
'山口県'=>'yamaguchi',
'徳島県'=>'tokushima',
'香川県'=>'kagawa',
'愛媛県'=>'ehime',
'高知県'=>'kochi',
'福岡県'=>'fukuoka',
'佐賀県'=>'saga',
'長崎県'=>'nagasaki',
'熊本県'=>'kumamoto',
'大分県'=>'oita',
'宮崎県'=>'miyazaki',
'鹿児島県'=>'kagoshima',
'沖縄県'=>'okinawa',
);
function getbb($path) {
$text = file_get_contents(__DIR__ . $path);
if ($text === false) {
throw new \RuntimeException('file not found.');
}
$json = json_decode($text);
$features = $json->features;
$coords = $features[0]->geometry->coordinates[0];
//print_r($coords);
$minlng = 180;
$maxlng = -180;
$minlat = 90;
$maxlat = -90;
foreach ($coords as $elem) {
$lng = $elem[0];
$lat = $elem[1];
if ($lng < $minlng) $minlng = $lng;
if ($maxlng < $lng) $maxlng = $lng;
if ($lat < $minlat) $minlat = $lat;
if ($maxlat < $lat) $maxlat = $lat;
}
return [
"minlng" => $minlng,
"maxlng" => $maxlng,
"minlat" => $minlat,
"maxlat" => $maxlat
];
}
$text = file_get_contents(__DIR__ . '/README.md');
if ($text === false) {
throw new \RuntimeException('file not found.');
}
//print_r(explode("\n", $text));
$textarr = explode("\n", $text);
$dict = [];
$citylist_arr = [];
$keylist_arr = [];
$pubofficetext = file_get_contents(__DIR__ . '/puboffice.json');
if ($text === false) {
throw new \RuntimeException('file not found.');
}
$puboffice = json_decode($pubofficetext);
foreach ($textarr as $elem) {
$elemarr = explode("|", $elem);
$id = trim($elemarr[2]);
$name = trim($elemarr[1]);
if (!ctype_digit($id)) continue;
//print_r($id . ":" . $name . "\n");
$childtext = file_get_contents(__DIR__ . "/" . $id . '/readme.md');
if ($childtext === false) {
throw new \RuntimeException('file not found.');
}
$childtextarr = explode("\n", $childtext);
foreach ($childtextarr as $childelem) {
$childelemarr = explode("|", $childelem);
$childid = trim($childelemarr[4]);
$childname = trim($childelemarr[3]);
if (!ctype_digit($childid)) continue;
//print_r($childelemarr);
$pref = trim($childelemarr[1]);
$jiscode = (int)($childid);
$info = $puboffice->$jiscode;
if ($info->nameroma == "") continue;
$record = [];
$record["name"] = $info->name;
$record["namekana"] = $info->namekana;
$record["jiscode"] = $jiscode;
$record["zipcode"] = $info->zipcode;
$record["center_lat"] = floatval($info->lat);
$record["center_lng"] = floatval($info->lon);
$record["key"] = "/" . $id . "/" . $childid . ".json";
$citylist_arr[] = $pref . trim($childelemarr[3]);
$keylist_arr[] = "/" . $todofuken[$pref] . "/" . $info->nameroma;
$dict[$todofuken[$pref]][$info->nameroma] = $record;
//print_r($jiscode . "\n");
//$record = getbb("/" . $id . "/" . $childid . ".json");
//$record["key"] = "/" . $id . "/" . $childid . ".json";
//$record["pref"] = $name;
//$dict[$name . $childname] = $record;
}
}
//print_r($dict);
$citylist = "var citylist = []string{";
foreach ($citylist_arr as $elem) {
$citylist .= "\"" . $elem . "\",\n";
}
$citylist .= "\"dummy\"}\n";
$keylist = "var keylist = []string{";
foreach ($keylist_arr as $elem) {
$keylist .= "\"" . $elem . "\",\n";
}
$keylist .= "\"dummy\"}\n";
//print_r($citylist);
//print_r($keylist);
print(json_encode($dict, JSON_UNESCAPED_UNICODE));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment