Esempio n. 1
0
$input_file = $options['inputfile'];
$output_file = $options['outputfile'];
$top_left = $options['top_left'];
$bottom_right = $options['bottom_right'];
$verbose = $options['verbose'];
$top_left_parts = explode(',', $top_left);
if (count($top_left_parts) !== 2) {
    print "Bad top_left parameter '{$top_left}'";
    cliargs_print_usage_and_exit($cliargs);
}
$bottom_right_parts = explode(',', $bottom_right);
if (count($bottom_right_parts) !== 2) {
    print "Bad bottom_right parameter '{$bottom_right}'";
    cliargs_print_usage_and_exit($cliargs);
}
$min_lat = min($top_left_parts[0], $bottom_right_parts[0]);
$max_lat = max($top_left_parts[0], $bottom_right_parts[0]);
$min_lon = min($top_left_parts[1], $bottom_right_parts[1]);
$max_lon = max($top_left_parts[1], $bottom_right_parts[1]);
if ($verbose) {
    error_log("Starting load of '{$input_file}'");
}
$input_osm_ways = new OSMWays();
$input_contents = file_get_contents($input_file) or die("Couldn't read file '{$input_file}'");
$input_osm_ways->deserialize_from_xml($input_contents);
$output_osm_ways = crop_ways_to_box($input_osm_ways, $min_lat, $min_lon, $max_lat, $max_lon, $verbose);
if ($verbose) {
    error_log("Starting save of '{$output_file}'");
}
$output_contents = $output_osm_ways->serialize_to_xml();
file_put_contents($output_file, $output_contents) or die("Couldn't write file '{$output_file}'");
Esempio n. 2
0
        $current_parts = fgetcsv($file_handle);
        $line_index += 1;
        if ($line_index < 2) {
            continue;
        }
        $bla_code = $current_parts[0];
        $fips_code = $current_parts[1];
        $series_code = $current_parts[2];
        if (!isset($result[$bla_code])) {
            $result[$bla_code] = array();
        }
        $result[$bla_code][] = array('fips_code' => $fips_code, 'series_code' => $series_code);
    }
    fclose($file_handle);
    return $result;
}
$cliargs = array('inputfile' => array('short' => 'i', 'type' => 'optional', 'description' => 'The folder containing the unemployment data from the BLS - if unset, will read from stdin', 'default' => 'php://stdin'), 'blatofipsfile' => array('short' => 'b', 'type' => 'required', 'description' => 'The file containing the mapping of BLA codes to FIPS'), 'outputfile' => array('short' => 'o', 'type' => 'optional', 'description' => 'The file to write the output csv data to - if unset, will write to stdout', 'default' => 'php://stdout'), 'waysfile' => array('short' => 'w', 'type' => 'optional', 'description' => 'A file containing the way shapes that this data will be drawn onto', 'default' => ''));
$options = cliargs_get_options($cliargs);
$input_file = $options['inputfile'];
$output_file = $options['outputfile'];
$bla_to_fips_file = $options['blatofipsfile'];
$ways_file = $options['waysfile'];
if (!empty($ways_file)) {
    $osm_ways = new OSMWays();
    $osm_xml_string = file_get_contents($ways_file) or die("Couldn't open '{$ways_file}' for reading");
    $osm_ways->deserialize_from_xml($osm_xml_string);
} else {
    $osm_ways = null;
}
$bla_to_fips = load_bla_to_fips($bla_to_fips_file);
convert_unemployment_file($input_file, $output_file, $bla_to_fips, $osm_ways);