2

enter image description here

In the ModelBuilder of ArcGIS Pro 2.8.1, using Iterate Layers, I want to iterate over features that are in a group layer. It seems like I should be able to identify this group layer by using a Wildcard, which the user will provide as a parameter. I am then passing these layers as the input to the rest of the model. The issue is when I choose Layer Type as Group Layer (within the Iterate Layer options), I later get the error 000840 (The value is not a Feature Layer), when I try to pass the Output Layer to the next tool, which is Feature Class to Feature Class. It does not accept Group Layers as an input.

My goal is to iterate through all layers(which are feature services) in a group layer, export them to a gbd, then export them as shapefile to a folder. The purpose is creating backups of field data that can then be edited in ArcGIS Pro project. I am going with this Group Layer Approach since the ArcGIS Pro project template has a group layer "Field Data". Field staff will drag in the appropriate layers that need backed up by this Model.

The model as pictured runs when Iterate Features is set to Feature Layers, but not Group Layers.

So how do I just iterate through all the layers within the desired Group Layer?

0

2 Answers 2

3

This can be solved in modelbuilder with a tiny bit of python as hinted by @keggering.

The model is this:

Model

  1. The iterator is simply iterating over ALL FeatureLayers with no wildcards

  2. The string variable GroupLayer name contains the name of the group layer in the map, in your case "Field data", note it is a precondition to the calculate value tool whose output is a precondition to the copy feature tool. Also note the output Name from the iterator is also a precondition to the calculate value tool.

  3. Calculate value tool is set up as:

Calculate Value tool

The code block is:

import arcpy
def inGroup(grplyr,layername):
  aprx = arcpy.mp.ArcGISProject("CURRENT")
  map = aprx.listMaps()[0]
  layer = map.listLayers(layername)[0]
  longName = layer.longName
  if grplyr in longName:
    return True
  else:
    return False

The code is simply asking if the full path name in the project includes the group layer name, if it does set output to TRUE else FALSE. The code is assuming you have only 1 map in the project file, if you have more it is taking the top one only.

0
2

I like Hornbydd's approach but I am also going to post a bit of code in here that I got to work in case others find it useful. This code looks at a specific map (Delineation Map) and exports, projects, and renames the layers that are housed within the Group Layer "Field Data"

import os
import arcpy

arcpy.env.outputCoordinateSystem = arcpy.SpatialReference("NAD 1983 StatePlane Colorado South FIPS 0503 (US Feet)")
arcpy.env.geographicTransformations = "WGS_1984_(ITRF00)_To_NAD_1983"
outDir = 'S:\\CAD_GIS Base Data\\Map Templates\\scratch.gdb'

proj = arcpy.mp.ArcGISProject('CURRENT')
m = proj.listMaps('Delineation Map')[0]
ml = m.listLayers()
for l in ml:   
    if l.isGroupLayer and l.name == 'Field Data':
        print(l) 
        lyrs = l.listLayers()      
        for lyr in lyrs:
            print(lyr)
            
            new_lyrs = str(lyr.name)
            new_lyrs = ("Field2021_" + new_lyrs)
            arcpy.FeatureClassToFeatureClass_conversion(lyr, outDir, new_lyrs)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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