2

I am using ArcMap 10.4 (with Spatial Analyst.)

I have a feature layer with ~11.000 partly overlapping but similar features. For each feature I want to extract some values from ~25 underlying rasters.

Overlapping polygon features on top a raster

I set up a model that iterates the raster folder and applies the needed values to the features. It works as intended, except for Zonal Statistics as a table doesn't handle overlapping features.

Initial functioning model

I have tried the following in order of solving this problem:

  • Set up the iterators in submodels, but they only run once. In order of fixing that I tried making them preconditions for the forthcoming tools. That didn't solve produce intended result.
  • I tried simply deleting every second feature, by MOD(layerFID,2)=1, which was close to correct, but isn't really a solution.
  • I set up an iterator that handles the overlapping features, by splitting the into separate shapefiles, performs Zonal Statistics as a table on them, and merges them again. It works, despite of being very slow. And then I can't iterate the raster folder.
  • I tried running Zonal Statistics 2 (and 3), with and without "arcpy.env.overwriteOutput = False". I yields odd results. As far as I know COUNT should be the same for all the zones when the area and the raster is the same.

Output table from Zonal Statistics 2

I don't see any decent solutions that doesn't involve two iterators.

4
  • 1
    You better avoid ArcGIS Pro and ArcMap for Zonal Statistics. See this blog post about the problem: blog.gisky.be/2018/03/dont-use-zonal-statistics-in-arcgis.html Commented Mar 9, 2018 at 8:03
  • You could try using Python instead. If Zonal Statistics cant handle overlapping zones you need to iterate over each individual polygon, for example with the da.SearchCursor, and over each raster.
    – Bera
    Commented Mar 9, 2018 at 8:11
  • I know the tool is bad, the whole idea of vector to raster conversion, is bound to be bad news. For this specific task it doesn't matter too much.
    – Mathias
    Commented Mar 9, 2018 at 8:17
  • I've reduced the scope of your question from asking about three products to just being about one. As per the Tour there should be only one question asked per question. The first answer is about ArcGIS Desktop so that is the product I reduced the scope of this Q&A to. If you also want to ask about and report your testing of ArcGIS Pro and/or QGIS, then please do that in separate questions.
    – PolyGeo
    Commented Mar 12, 2018 at 8:39

2 Answers 2

1

If you want to handle overlapping polygons, you should give the Zonal Statistics as Table 2 tool from the Spatial Analyst Supplemental Tools a try. It will work with ArcGIS Desktop 10.4, but not yet with Pro.

The original Zonal Statistics as Table tool summarizes into a table the values of a raster within the zones of another dataset. However, if the input zones have any overlap, those will be flattened down into one layer before performing the operation. This new Zonal Statistics as Table 2 tool processes the input in a different way, preserving the overlapping nature of zonal inputs.

2
  • Thank you for the suggestion. I attached an image, so my reply is in the original question.
    – Mathias
    Commented Mar 12, 2018 at 8:23
  • 1
    Your vector circles will be converted to raster in the analysis, so depending on the circles' position on the grid (and depending on the grid you use as Snap Raster) they might have a different rasterized area and cell count. Do your 25 rasters have the same cell size? Are they all aligned the same way? What Cell Size and Snap Raster parameter do you use in you model/tool environment?
    – GISGe
    Commented Mar 12, 2018 at 9:03
1

I was never able to solve my problem inside modelbuilder. Zonal Statistics as a Table 2 didn't perform as I had hoped. My solution ended up being python, heavily based on some script I found [here].1 The first thing I do is to use a model to export the single features to individual shapefiles. Then I add all my rasters to a singel folder. The raster must all be of the same kind (eg. 8bit or 32bit).

Hope the script below is able to help somebody else: ` #!/usr/bin/env python # -- coding: utf-8 --

import arcpy, os, sys, string, glob

arcpy.CheckOutExtension("spatial")
arcpy.env.overwriteOutput = True

tbl = "C:/TEMP/"
InZnValFld = "Nr"
fieldname1 = "Shp"
fieldname2 = "Raster"
Template = "C:/TEMP/Template.dbf"

def zonal_for_overlaps(rasWS, shpWS):  
arcpy.env.workspace = rasWS    
rasterlist = arcpy.ListRasters() 
for raster in rasterlist:
    print raster
arcpy.env.workspace = shpWS  
shplist = arcpy.ListFeatureClasses()    

for k in rasterlist:   
    rasterfil = rasWS+k 
    arcpy.Copy_management(Template,tbl+'\\'+'Tabel'+rasterfil[-5:-4]+'.dbf')
    tempTabel = tbl+'\\'+'Tabel'+rasterfil[-5:-4]+'.dbf'
    print rasterfil
    for i in shplist:    
        out_tbl = tbl + "\\" + k + "_ZStats"    
        print '==============================================='    
        print 'Zonal Statistics for overlapping polygons : ' + rasterfil    
        print '......'    
        # Preform zonal statistics on the polygon file within the variable 'znlyr'    
        # Do not ever use FID as identifier - ZSAAT can't handle it.
        z = arcpy.gp.ZonalStatisticsAsTable_sa(i, InZnValFld, rasterfil, out_tbl, "DATA", "ALL")    
        # Create a new field to add the filename information    
        arcpy.AddField_management(z, fieldname1, "DOUBLE")    
        # Add the idenitifer value from the shp-filename to the new field, this value is the one to be used for an optional join    
        arcpy.AddField_management(z, fieldname2, "TEXT")    
        # Add the idenitifer value from the raster-filename to the new field 
        arcpy.CalculateField_management(z, fieldname1,float(i[0:3]))

        rasterfieldnavn = str(rasterfil[-5:-4])   
        print rasterfieldnavn 
        # Add the idenitifer value from the filename to the new field
        arcpy.CalculateField_management(z, fieldname2,str(rasterfieldnavn))
        #Collects all in template-.dbf
        arcpy.Append_management(z, tempTabel, "","","")  

zonal_for_overlaps("C:/temp/rasfiler/", "C:/Users/kusk3092/OneDrive Corp/OneDrive - Atkins Ltd/Documents/ArcGIS/Projects/IteratorTest/shp/")  

`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.