Are there plans to add this significant enhancement of the tool to ArcMap 10.8? Is it even a possibility?
Thank you for your question and this discussion.We are happy to announce that, in ArcGIS Pro 2.5 you can now use the Zonal Statistics as Table tool to calculate statistics for overlapping polygon zones. The zonal analysis will be performed for each individual polygon.
Zonal statistics could not be computed for feature 26 (zone = 26) ERROR 000601: Cannot delete C:\Research\Projects\xxxwk1\xyz.gdb\workfeat. May be locked by another application. Failed to execute (CopyFeatures).
I've been posting updated versions here for review, please use at your own risk and send comments:ftp://ftpext.usgs.gov/pub/nonvisible/cr/nact
I did, but I get errorsTraceback (most recent call last): File "Z:\Extraction of Bands\Extraction\Python for extraction\Trial\ZonalStatsOverlappingPolys (2)\makeZones.py", line 170, in <module> arcpy.CopyFeatures_management(inFeat, inFeatures) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 2226, in CopyFeatures raise eExecuteError: ERROR 000210: Cannot create output Z:\Extraction of Bands\Extraction\Python for extraction\Trial\Scratch.mdb\50m_buffer_P_selectionERROR 000361: The name starts with an invalid characterFailed to execute (CopyFeatures).Failed to execute (ZonesWOverlap).Failed at Wed Oct 31 10:37:07 2012 (Elapsed Time: 8.00 seconds)
I did finish the tool I was working on. The tool is faster than the individual polygon solution. Originally I produced 3 different solutions for breaking up the polygons and ended up using two of those methods. I have uploaded the tool and documented it. The tool uses Spatial Join and also breaks up the feature class into smaller pieces.http://www.arcgis.com/home/item.html?id=b859b33c616a47d2b99b5e133942db02
Even if you used my current (10x-compatible) version (ftp://ftpext.usgs.gov/pub/nonvisible/cr/nact) it would not be any faster than Jamie's code,as i also do one at a time. Have you tried Sue's tool? I haven't tried it yet, but it seems like a really good solution.
def makeOverlapDict(fc, returnID = None): """This function creates a dictionary relating each feature to a list of its overlapping features. The optional returnID parameter can be used to create an overlapDict with keys equal to a different unique ID than OID, which is the default.""" fcName = arcpy.Describe(fc).name if not returnID: returnID = 'FID_' + fcName returnID2 = 'FID_' + fcName + '_1' else: returnID2 = returnID + '_1' identity = arcpy.Identity_analysis(fc, fc, fcName + 'ID') overlapDict = {} with arcpy.da.SearchCursor(identity, (returnID, returnID2)) as cursor: for row in cursor: if row[0] <> row[1]: if not overlapDict.get(row[0]): overlapDict[row[0]] = [row[1]] else: overlapDict[row[0]].append(row[1]) arcpy.Delete_management(identity) return overlapDict def makeExplodeDict(overlapDict): """This function creates a new dictionary relating each feature to its explode value based on the overlapDict.""" # set initial explode value to 1 expl = 1 # create dictionary to hold explode values of oids explDict = {} overlapDict2 = overlapDict.copy() # while there are still keys in overlapDict2 not also in explDict while len([k for k in overlapDict2.iterkeys() if not explDict.get(k)]) > 0: # create list to hold overlapping oids ovSet = set() # loop over overlapDict2 for oid, ovlps in overlapDict2.iteritems(): if not explDict.get(oid) and oid not in ovSet: explDict[oid] = expl for o in ovlps: ovSet.add(o) for oid in explDict.iterkeys(): if overlapDict2.get(oid): del overlapDict2[oid] print expl expl += 1 return explDict def defineOverlaps(fc): """This function creates three fields: 'overlaps', which lists the OBJECTIDs of all other polygons overlapping each polygon, and 'ovlpCount', which counts the number of overlaps per feature, and 'expl', which separates all features into unique non-overlapping groups by value.""" # Build dicts used to relate each feature to all identical, overlapping shapes overlapDict = makeOverlapDict(fc) # Loop through overlapDict and give each oid an expl value that separates all oids into # non-overlapping groups explDict = makeExplodeDict(overlapDict) # Add remaining non-overlapping oids into explDict and give them an expl value # equal to the max expl; the max should have the least members, and this preserves # a good distribution of values so that each processing step is somewhat balanced maxExpl = max(explDict.itervalues()) query = str(tuple(explDict.keys())) fillVals = [] with arcpy.da.SearchCursor(fc, ("OID@"), '"OBJECTID" NOT IN ' + query) as cursor: for row in cursor: fillVals.append(row[0]) for val in fillVals: explDict[val] = maxExpl # Add overlaps, ovlpCount, and expl fields arcpy.AddField_management(fc,'overlaps',"TEXT",'','',1000) # the 1000 is the field character limit... increase if need be arcpy.AddField_management(fc,'ovlpCount',"SHORT") arcpy.AddField_management(fc,'expl',"SHORT") # For each row with an overlapping poly (i.e. with an entry in idDict) # give overlaps value of all overlapping ids, ovlpCount value of how # many overlaps occur, and expl value that separates all features into # unique non-overlapping groups (explode value) with arcpy.da.UpdateCursor(fc,("OID@","overlaps","ovlpCount","expl")) as cursor: for row in cursor: # If oid in overlapDict, write overlapping oids and their count # to the appropriate fields if overlapDict.get(row[0]): row[1] = str(overlapDict[row[0]]).strip('[]') row[2] = len(overlapDict[row[0]]) # Write expl value to expl field row[3] = explDict[row[0]] cursor.updateRow(row)
defineOverlaps(fc)
I believe the error (from CopyFeatures, not Sue's script) is telling you to avoid naming datasets starting with a number. I also suggest avoiding spaces in pathnames, it works most of the time but is just asking for trouble -- something will break when you most need it not to. 000361 : The name starts with an invalid character
ERROR 000361: The name starts with an invalid characterFailed to execute (CopyFeatures).
HiI'm trying to extraction band information from raster images using overlapping buffers. I tried using Jamie's code and it takes a long time. I can't ran Curtis' code. Does anymore have a code that works faster?Thanks
I wouldn't say it's a thing of the past. Setting up the model is not trivial for people new to ModelBuilder, especially how you aggregate the results. Please do post your model, IMHO this is a good "real-world" example of how iteration can be used to great advantage in Arc 10.The tool Sue just posted is better than a brute-force iteration though - it separates your overlapping polygons into non-overlapping groups - if you have thousands of overlapping polygons, this could mean a few hundred iterations instead of thousands.
The problem with overlapping polygons for Zonal Statistics is of the past. If you iterate over your features within a feature class and pass each one to zonal statists it works perfectly and writes out the results into a single table. If anyone would like I would gladly post my model.
Thats all I get from this tool.<type 'exceptions.RuntimeError'>: Row: Field FID does not existFailed to execute (StatisticsForOverlappingZones)
Take a look at the attached tool. It will allow you to do zonal statistics as table on overlapping polygons. you can add this tool directly to ArcToolbox.Jamie
# Note the select string will be different depending on the workspace desc = arcpy.Describe(env.workspace) if desc.extension == 'mdb': selStr = "[" + fCount + "] = " else: selStr = "\"" + fCount + "\" = "
# Note the select string will be different depending on the workspace dfCount = arcpy.AddFieldDelimiters(env.workspace,fCount) selStr = dfCount + " = "
I was working on separating a feature class with overlapping polygons into a minimal set of feature classes with non-overlapping polygons when I was asked to work on a solution for the Zonal Statistics problem described here. I came up with a different solution, probably because I was working on this from a different angle. The routine I wrote is recursive and uses spatial join. I'm only attaching the python code. Feel free to use it or modify it for your needs.Sue
How do you get this installed into ArcMap10??
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.