Select to view content in your preferred language

Iterate through features to use as input for ExtractByMask

3297
2
10-19-2017 04:54 AM
JanHildebrand
Deactivated User

I need to iterate through each of the features of a feature class successively to use each one as the mask to extract from a raster with the ExtractByMask tool. Basically I'm looking for the "Iterate Feature Selection" function from ModelBuilder for Python scripting.

 

If I understand correctly, using a search cursor will return only the row of values from the attribute table, not the feature shape itself. Would iteratively creating a new shape with "Select_Analysis" be a feasible way to go about this instead? I suppose creating a new shape file for each feature would take quite long. Is there another, more efficient way?

0 Kudos
2 Replies
ChrisDonohue__GISP
MVP Alum
0 Kudos
DanPatterson_Retired
MVP Emeritus

searchcursor...

fc = 'your featureclass'
fields = ['SHAPE@XY']
with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:
        shp = row[0]
        # do stuff here

....