def convert_pbf(c):
    """Run the conversion of the OSM file"""
    import sys

    get_pbf(c)

    op = pylib.OsmProcessor(None)
    
    p = Path.cwd().joinpath('data',pbf_file)
    out_dir = p.parent.joinpath('csv')
    
    if out_dir.joinpath('lines.csv').exists():
        return
    
    if not p.exists():
        points_logger.error("ERROR: Download https://download.geofabrik.de/north-america-latest.osm.pbf and put it in the data directory"
              " or run `invoke get_pbf`")
        
        sys.exit(1)
    
    if out_dir.exists():
        print(f"ERROR: output dir {out_dir} should not exist")
        sys.exit(1)

    points_logger.info('Convert PBF file')
    op.convert_pbf(p, out_dir)
def build_osm_blocks(c):
    """Build blocks geo file and assign OSM points to blocks"""
    pkg_dir = str(Path(__file__).parent.resolve())
    pkg = mp.open_package(pkg_dir)
    points_logger.info(f"Pkg dir: {pkg_dir}")

    pylib.build_osm_points(pkg)
def build_clusters(c):

    pkg_dir = str(Path(__file__).parent.resolve())
    pkg = mp.open_package(pkg_dir)
    points_logger.info(f"Pkg dir: {pkg_dir}")

    pylib.build_clusters(pkg)
def create_points_files(c):
    """Build the geohash_tags.csv file"""
    
    pkg_dir = str(Path(__file__).parent.resolve())
    pkg = mp.open_package(pkg_dir)
    points_logger.info(f"Pkg dir: {pkg_dir}")

    convert_pbf(c)
    
    pylib.build_points(pkg)
def get_pbf(c):

    dd = Path.cwd().joinpath('data')

    if not dd.exists():
        dd.mkdir(parents=True )

    if not dd.joinpath(pbf_file).exists():
        points_logger.info(f'Downloading {pbf_url}')
        c.run(f'curl --progress-bar -o data/{pbf_file} {pbf_url}')
    else:
        points_logger.info(f'File data/{pbf_file} already exists')