Select to view content in your preferred language

access Mosaic dataset raster via Python API

05-02-2023 12:26 AM
Labels (3)
New Contributor


I am trying to work on some raster via Python API. even if the documentation and the videos are very explicative I didn`t find anything on this subject.

As far as I know a Mosaic dataset is a special type of  `layer` where each attribute in the attribute table points to a specific raster stored somewhere. 

now let`s say that I want to do some processing on some rasters in the mosaic. for example a minus operation on two rasters stored in the mosaic.

how do I access a single raster into the mosaic? this is the procedure that I am using. 

    gis = GIS("https://Myportal", username="usr", password="pwd")
except Exception as e:
     print("An exception occurred: ", e)
#accessing my mosaic dataset item
lyr1 = gis.content.get('7d562782877aec8fc3')
#accessing my mosaic layer
lyr1 = lyr1.layers[0]
#filtering my mosaic layer to isolate only one raster inside it
filtered_lyr1 = lyr1.filter_by(where="objectid = 10")
filtered_lyr2 = lyr1.filter_by(where="objectid = 9")
#applying processing functions to the layers 
processedLyr = apply(filtered_lyr1 , 'DBX_Bathy_Hillshade')


0 Kudos
0 Replies