def generate_grid(iso3, side_length):
    '\n    Generate a spatial grid for the chosen country.\n    '
    directory = os.path.join(DATA_INTERMEDIATE, iso3, 'grid')
    if (not os.path.exists(directory)):
        os.makedirs(directory)
    filename = 'grid_{}_{}_km.shp'.format(side_length, side_length)
    path_output = os.path.join(directory, filename)
    if os.path.exists(path_output):
        return
    filename = 'national_outline.shp'
    path = os.path.join(DATA_INTERMEDIATE, iso3, filename)
    country_outline = gpd.read_file(path, crs='epsg:4326')
    country_outline.crs = 'epsg:4326'
    country_outline = country_outline.to_crs('epsg:3857')
    (xmin, ymin, xmax, ymax) = country_outline.total_bounds
    polygons = manually_create_grid(xmin, ymin, xmax, ymax, side_length, side_length)
    grid = gpd.GeoDataFrame({'geometry': polygons}, crs='epsg:3857')
    intersection = gpd.overlay(grid, country_outline, how='intersection')
    intersection.crs = 'epsg:3857'
    intersection['area_km2'] = (intersection['geometry'].area / 1000000.0)
    intersection = intersection.to_crs('epsg:4326')
    intersection.to_file(path_output, crs='epsg:4326')
    return intersection
Generate a spatial grid for the chosen country.
def generate_grid(iso3, side_length):
    '\n    \n    '
    directory = os.path.join(DATA_INTERMEDIATE, iso3, 'grid')
    if (not os.path.exists(directory)):
        os.makedirs(directory)
    filename = 'grid_{}_{}_km.shp'.format(side_length, side_length)
    path_output = os.path.join(directory, filename)
    if os.path.exists(path_output):
        return
    filename = 'national_outline.shp'
    path = os.path.join(DATA_INTERMEDIATE, iso3, filename)
    country_outline = gpd.read_file(path, crs='epsg:4326')
    country_outline.crs = 'epsg:4326'
    country_outline = country_outline.to_crs('epsg:3857')
    (xmin, ymin, xmax, ymax) = country_outline.total_bounds
    polygons = manually_create_grid(xmin, ymin, xmax, ymax, side_length, side_length)
    grid = gpd.GeoDataFrame({'geometry': polygons}, crs='epsg:3857')
    intersection = gpd.overlay(grid, country_outline, how='intersection')
    intersection.crs = 'epsg:3857'
    intersection['area_km2'] = (intersection['geometry'].area / 1000000.0)
    intersection = intersection.to_crs('epsg:4326')
    intersection.to_file(path_output, crs='epsg:4326')
    return intersection