I'm creating a script to analyse landcover within an AOI which I'll turn into a geoprocessing tool. I want to use the ESA 2022 landcover and download from within the tool using the code provided on the ESA data access page (Script below).
I'm aware I need to install geopandas into the conda environment most recommendations seem to suggest doing this in the Python Command Prompt. However, eventually, this tool needs to stand alone and be used by non-techincal staff to carry out the landcover analysis, i.e. just run from the geoprocessing pane.
Is there a way I can include the installation of geopandas to allow me to download relevant landcover data WITHIN the script for the geoprocessing tool I'm creating so no additional steps are required from those using the tool?
import geopandas as gpd
s3_url_prefix = "https://esa-worldcover.s3.eu-central-1.amazonaws.com"
# load natural earth low res shapefile
ne = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
# get AOI geometry (Italy in this case)
country = 'Italy'
geom = ne[ne.name == country].iloc[0].geometry
# load worldcover grid
url = f'{s3_url_prefix}/v100/2020/esa_worldcover_2020_grid.geojson'
grid = gpd.read_file(url)
# get grid tiles intersecting AOI
tiles = grid[grid.intersects(geom)]
# use requests library to download them
import requests
from tqdm.auto import tqdm # provides a progressbar
for tile in tqdm(tiles.ll_tile):
url = f"{s3_url_prefix}/v100/2020/map/ESA_WorldCover_10m_2020_v100_{tile}_Map.tif\n"
r = requests.get(url, allow_redirects=True)
out_fn = f"ESA_WorldCover_10m_2020_v100_{tile}_Map.tif"
with open(out_fn, 'wb') as f:
f.write(r.content)I'm using ArcPro 3.0.