Select to view content in your preferred language

Feature Set from Mosaic Dataset Selection Using Arcpy

647
4
Jump to solution
07-19-2022 06:30 AM
KeonMonroe
New Contributor III

I'm developing an arcpy script that uses Manage Tile Cache. One of the parameters is "Area of Interest" which takes a Feature Set datatype.

In GIS I can select on the mosaic dataset, then use the footprint as input for that parameter and the tool works.

So programmatically I tried a similar approach but the selection fails. How can I capture the feature set of a mosaic dataset selection?

EDIT - Updated var names for mosaic dataset `input_md`. From `test_md`

 

 

# change workspace to Imagery gdb
md_name = os.path.basename(input_md) # `input_md` is a valid mosaic dataset w/ rasters
base_gdb = os.path.dirname(input_md)
arcpy.env.workspace = base_gdb

# query footprint Area of Interest
aoi_query = "Category = 1 And Name = 'DrakesCornerSP-2019-08-08_COG'"

# NOTE: Issue here. How to obtain Feature Set for `area_of_interest` param? 
arcpy.management.SelectLayerByAttribute(r"{}\Footprint".format(md_name), "NEW_SELECTION", aoi_query, None) # fail
# arcpy.management.SelectLayerByAttribute(md_name, "NEW_SELECTION", input_aoi_query, None) # fail
# arcpy.management.SelectLayerByAttribute(input_md, "NEW_SELECTION", input_aoi_query, None) # fail

# get scales list from cache .xml 
lst_scales = read_cache_xml(input_service_cache) 

base_folder = os.path.dirname(input_service_cache)
mode = "RECREATE_ALL_TILES"
cacheName = os.path.basename(input_service_cache)
useScheme = "ARCGISONLINE_SCHEME"

# update service cache
with arcpy.EnvManager(parallelProcessingFactor="100"):
    arcpy.AddMessage(f'\n\tRebuilding cache tiles for image service:\n\t{cacheName}')
    arcpy.ManageTileCache_management(in_cache_location = base_folder, 
        manage_mode = mode,
        in_cache_name = cacheName, 
        in_datasource = input_md, 
        tiling_scheme = useScheme,
        scales = lst_scales , 
        area_of_interest = f"{input_md}\Footprint"
        min_cached_scale = max(lst_scales), 
        max_cached_scale= min(lst_scales))

 

 

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
RhettZufelt
MVP Notable Contributor

It looks like it's just not finding the layer.

Try hard coding the entire path/name to the mosaic footprint dataset and see if you can get it working.

Then, you  can more easily figure out how/where it is losing it's way.

Also, a weird behavior that might be an issue.  If I use the makefeaturelayer with where clause "Category = 1", the created feature layer has exactly what I expect.  HOWEVER, if I add the AND Name = ...., the selection works correctly, but, the returned dataset is a raster catalog with the matching images in it, NOT a feature set of the footprints...

might need to make a selection/feature layer to get all the category 1 footprints, then perform a second query on that to get the feature.

R_

 

View solution in original post

0 Kudos
4 Replies
RhettZufelt
MVP Notable Contributor

Not anywhere I can test, but I don't see where you are defining the aoi layer (test_md).

Instead of select by layer, have you tried making a feature layer of the selected footprints, then feeding that to the manage cache?

in_features = r"{}\Footprint".format(md_name)
arcpy.management.MakeFeatureLayer(in_features, "test_md", aoi_query)
......
area_of_interest = "test_md"

R_

 

 

0 Kudos
KeonMonroe
New Contributor III

Sorry just updated vars in the original post. `test_md` was the old mosaic dataset name. 

Anyways I tried Make Feature Layer instead but getting an ExecuteError. Which is weird because I can make selections on the MD's footprint in GIS without any issues.

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset BelleMead\Footprint does not exist or is not supported
Failed to execute (MakeFeatureLayer).

 

0 Kudos
RhettZufelt
MVP Notable Contributor

It looks like it's just not finding the layer.

Try hard coding the entire path/name to the mosaic footprint dataset and see if you can get it working.

Then, you  can more easily figure out how/where it is losing it's way.

Also, a weird behavior that might be an issue.  If I use the makefeaturelayer with where clause "Category = 1", the created feature layer has exactly what I expect.  HOWEVER, if I add the AND Name = ...., the selection works correctly, but, the returned dataset is a raster catalog with the matching images in it, NOT a feature set of the footprints...

might need to make a selection/feature layer to get all the category 1 footprints, then perform a second query on that to get the feature.

R_

 

0 Kudos
KeonMonroe
New Contributor III

Hard coding the full path of the Mosaic worked! I actually didn't need to modify the query, but it's odd you experienced that. 

0 Kudos