import os import leafmap from samgeo import SamGeo, tms_to_geotiff, get_basemaps def extract(bbox): m = leafmap.Map(center=[bbox[0], bbox[3]], zoom=15) m.add_basemap("SATELLITE") m image = 'satellite_temp.tif' tms_to_geotiff(output=image, bbox=bbox, zoom=19, source="Satellite", overwrite=True) m.layers[-1].visible = False # turn off the basemap m.add_raster(image, layer_name="Image") m sam = SamGeo( model_type="vit_h", checkpoint="sam_vit_h_4b8939.pth", sam_kwargs=None, ) mask = "segment.tif" sam.generate(image, mask, batch=True, foreground=True, erosion_kernel=(3, 3), mask_multiplier=255) vector = "segment.gpkg" sam.tiff_to_gpkg(mask, vector, simplify_tolerance=None) shapefile = "segment.kml" sam.tiff_to_vector(mask, shapefile) extract([77.63566218316555,21.3112579693753,77.63566218316555,21.313189840738627])