How to Split single raster within multiple polygons

693
4
08-27-2013 03:04 AM
Jacqueline_IsabellaGisen
New Contributor
Hello,

I have a raster ('slope') which content only one attribute in the table. On the other hand I have a feature which content several polygons (catchments) in the attributes table. I would like to obtain the area or count of the 'slope' for each catchments. Are there any faster way to do it without separating the catchments and mask the raster one by one? Thank you.
0 Kudos
4 Replies
JimCousins
MVP Regular Contributor
Will Zonal Statistics handle this for you?
0 Kudos
TrevorHavelka
New Contributor II
Have you used python before?  You could use a searchcursor to loop through the catchments.  For each catchment you could then mask the raster and perform whatever calculations you needed.  Sample code is below, you would just need to add the mask and calculations.

import arcpy
shapefile = r"catchments"  ##Folder path of your catchments
rows = arcpy.SearchCursor(shapefile, "", "", "FID") 

# Iterate through the rows in the cursor 
for row in rows: 
    in_select = shapefile  ##Folder path of your catchments
    out_select = r"outputfeature"  ##Output for each catchment
    where_clause = "\"FID\" = %d"% (row.FID)
    arcpy.Select_analysis(in_select, out_select, where_clause) ##selects feature

    ###Mask and perform calculations
    
    arcpy.Delete_management(out_select)  ###Delete your catchment and start loop over
0 Kudos
Jacqueline_IsabellaGisen
New Contributor
Hi there,

I tried again with zonal statistic as table and it works! The problem previously was I uncheck the Ignore NoData in calculation option. Once it is checked, it works. Thank you.
0 Kudos
JimCousins
MVP Regular Contributor
That's great. Could you mark the thread as answered, so people know you reached a solution?
0 Kudos