import os from ipyleaflet import Map, basemaps, Rectangle import leafmap def download_high_res_basemap(bounding_box, output_file): """ Downloads a high-resolution satellite basemap image within the specified bounding box and saves it as a GeoTIFF file. Parameters: bounding_box (list): A list containing the bounding box coordinates in the format [minx, miny, maxx, maxy]. output_file (str): The path to the output GeoTIFF file where the image will be saved. """ # Create a Leafmap Map object m = Map(center=[(bounding_box[1] + bounding_box[3]) / 2, (bounding_box[0] + bounding_box[2]) / 2], zoom=20) # Define a custom bounding box as a Rectangle rect = Rectangle(bounds=(bounding_box[1], bounding_box[0], bounding_box[3], bounding_box[2]), fill=False) m.add_layer(rect) # Use a high-resolution satellite basemap (you can change to other available basemaps) basemap = basemaps.Esri.WorldImagery # Set the basemap m.add_layer(basemap) m.save(output_file, format="png", width=800, height=800) # Display the map # display(m) # # Wait for the map to render # leafmap.waits.wait_for_map_to_load(m) # # Export the map as a GeoTIFF file # leafmap.save_map(m, output_file, dpi=300) # Example usage: bounding_box = [-122.4, 37.7, -122.1, 37.9] # Example bounding box for San Francisco, CA output_file = "satellite_basemap.png" download_high_res_basemap(bounding_box, output_file)