Skip to content

Instantly share code, notes, and snippets.

@pjaudiomv
Created January 26, 2019 14:48
Show Gist options
  • Save pjaudiomv/e8fb0ee6f1e8fc83fcba4c038a6964b0 to your computer and use it in GitHub Desktop.
Save pjaudiomv/e8fb0ee6f1e8fc83fcba4c038a6964b0 to your computer and use it in GitHub Desktop.
<?php
// Get all Counties for the following state, AL, FL, GA, NC, SC
$al_file="http://www2.census.gov/geo/docs/reference/codes/files/st01_al_cou.txt";
$fl_file="https://www2.census.gov/geo/docs/reference/codes/files/st12_fl_cou.txt";
$ga_file="https://www2.census.gov/geo/docs/reference/codes/files/st13_ga_cou.txt";
$nc_file="https://www2.census.gov/geo/docs/reference/codes/files/st37_nc_cou.txt";
$sc_file="https://www2.census.gov/geo/docs/reference/codes/files/st45_sc_cou.txt";
$states = array($al_file, $fl_file, $ga_file, $nc_file, $sc_file);
$allCounties = array();
foreach ($states as $state) {
$csv = array_map('str_getcsv', file($state));
array_walk($csv, function(&$a) use ($csv) {
$a = array_combine(array('STATE','STATEFP','COUNTYFP','COUNTYNAME','CLASSFP'), $a);
});
$allCounties[] = array_column($csv, 'COUNTYNAME');
}
$iter = new RecursiveIteratorIterator(new RecursiveArrayIterator($allCounties));
$new_arr = array();
foreach($iter as $v) {
$new_arr[]=$v;
}
$finalCountyArray = array();
foreach ($new_arr as $arr) {
$finalCountyArray[] = str_replace(' County', '', trim(ucwords(strtolower($arr))));
}
array_push($finalCountyArray,"Greensville","Giles");
sort($finalCountyArray);
$uniqueCounties = array_unique($finalCountyArray);
echo "\n" . count($uniqueCounties) . "\n";
// Get existing Counties in SEZF Server
$counties_sezf = json_decode(file_get_contents("https://sezf.charlestonna.org/main_server/client_interface/json/?switcher=GetFieldValues&meeting_key=location_sub_province"), true);
$finalCountiesArray_sezf = array();
foreach ($counties_sezf as $county_sezf) {
$finalCountiesArray_sezf[] = str_replace(' County', '', trim(ucwords(strtolower($county_sezf['location_sub_province']))));
}
$uniqueCounties_sezf = array_unique($finalCountiesArray_sezf);
echo "\n" . count($uniqueCounties_sezf) . "\n";
// Now Merge the Two
$countiesArrayMerged = array_unique (array_merge ($uniqueCounties, $uniqueCounties_sezf));
sort($countiesArrayMerged);
echo "\n" . count($countiesArrayMerged) . "\n";
$allCounties = '';
foreach ($countiesArrayMerged as $uniqueCounty) {
$allCounties .= "'" . addslashes($uniqueCounty) . "',"; //add slashes just in case
}
$allCounties = rtrim($allCounties,","); // trim last comma ,
echo '$meeting_counties_and_sub_provinces = array(';
echo $allCounties;
echo ');';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment