reverse-geocoder-cn 0.1.0

离线为中国的区县进行逆地理编码;Offline reverse geocoding for Chinese province, city and county boundaries
Documentation
use std::{env, fs, path::PathBuf, process::ExitCode};

fn main() -> ExitCode {
    let mut args = env::args_os().skip(1);
    let source = args
        .next()
        .map(PathBuf::from)
        .unwrap_or_else(|| PathBuf::from("cn_geojson"));
    let output = args
        .next()
        .map(PathBuf::from)
        .unwrap_or_else(|| PathBuf::from("cn_admin.bin"));
    if args.next().is_some() {
        eprintln!("usage: cargo run --bin build-data -- [geojson-directory] [output-file]");
        return ExitCode::FAILURE;
    }
    match reverse_geocoder_cn::build_data(
        source.join("中国_省.geojson"),
        source.join("中国_市.geojson"),
        source.join("中国_县.geojson"),
    ) {
        Ok(bytes) => match fs::write(&output, bytes) {
            Ok(()) => {
                println!("wrote {}", output.display());
                ExitCode::SUCCESS
            }
            Err(error) => {
                eprintln!("cannot write {}: {error}", output.display());
                ExitCode::FAILURE
            }
        },
        Err(error) => {
            eprintln!("cannot build data: {error}");
            ExitCode::FAILURE
        }
    }
}