Select to view content in your preferred language

GetCountManagement for Mosaic Dataset

846
2
Jump to solution
02-24-2022 11:43 AM
KeonMonroe
Occasional Contributor

I'm trying to develop a geoprocessing tool for handling mosaic datasets. Using ArcGIS Pro - I can query a mosaic dataset and find how many primary rasters it contains. How can I replicate this behavior in a script? If I had a normal feature class I would make it a feature layer, select on the layer, then GetCount() to find the number of rows.

How would you do this with a mosaic dataset that contains primary and overview rasters?

 

def query_primary_rasters(input_md):
    """ Return the number of primary rasters in a given Mosaic dataset
    """
    arcpy.AddMessage(f"Input Mosaic Dataset:\n{input_md}")

    query_by = "Category = 1"  # primary rasters
    md_lyr = "md_lyr"
    # arcpy.MakeFeatureLayer_management(in_features=os.path.join(input_md, "Footprint"), out_layer = md_lyr, where_clause= query_by)
    # arcpy.MakeMosaicLayer_management(input_md, out_mosaic_layer= md_lyr, where_clause= query_by)
    
    # NOTE - below works but doesn't return selected row count (includes all items)
    arcpy.management.SelectLayerByAttribute(input_md, "NEW_SELECTION", query_by, None)
    count_primary = int(arcpy.GetCount_management(md_lyr)[0])

    arcpy.AddMessage(f"There are {count_primary} primary rasters in the mosaic dataset")
    return count_primary

update_md = arcpy.GetParameterAsText(0)
query_primary_rasters(update_md)

 

 

0 Kudos
1 Solution

Accepted Solutions
RhettZufelt
MVP Notable Contributor

It appears as if Pro's Table to Table tool will allow the mosaic as input, and let you put a query of "Category = 1".  This will output just the primary's to a new table (could probably go to memory, didn't test) that can now be fed into the GetCount tool.

 

R_

View solution in original post

2 Replies
RhettZufelt
MVP Notable Contributor

It appears as if Pro's Table to Table tool will allow the mosaic as input, and let you put a query of "Category = 1".  This will output just the primary's to a new table (could probably go to memory, didn't test) that can now be fed into the GetCount tool.

 

R_

KeonMonroe
Occasional Contributor

Thanks, works nicely. 

0 Kudos