4

I do a lot of proximity analysis using "select by location" and would like to cut down on the effort spent each time doing this!

I have put together a model using ModelBuilder that:

  1. Iterates over features in a feature layer (source layer);
  2. Selects features in a separate target layer based on the set parameters; and
  3. Uses summary statistics to summarize over a certain field.

Where I'm getting caught up is in making this as much like a standard tool as possible.

I have two issues I'm running into:

  1. I've set the "statistics field" of the Summary Statistics tool as a model parameter. However, when I go to run this tool through ArcToolbox, I set the target layer, but the statistics field isn't populated with the list of potential fields from the target layer. The drop down menu remains blank. Is there a way to make all the target layer fields populate similarly to how they would if you were using the Summary Statistics tool alone and set an input layer?
  2. Get Field Value gets the value of the first row of the specified field, but I do not know how to tell it to get the value of the field of what I just summarized on.

So, in Summary Statistics, if I told it to get the SUM of a field called POPTOTAL, then I want the Get Field Value tool to grab the value from the new field called "SUM_POPTOT" in the output statistics. There should only be one row of data, so I don't need to worry about getting the correct row. I have "Field" set as a model parameter currently, but I don't think it needs to be.

I've posted this thread in the ArcGIS forum, but I haven't received any feedback. I'm still new to ModelBuilder...I have some background in programming, so Python script would be fine (or maybe even better).

Iterative Proximity Analysis Model

Iterative Proximity Analysis Tool Dialog

4
  • 1
    Can you perhaps include a picture of your tool dialog? I think I understand what you want as your inputs but I am not so clear on your desired output. Are you wanting to see repeated tool dialogs - one per layer iterated - or just one at the start to choose the field to be used in all iterations? Your question is well worded but perhaps edit it to provide these clarifications.
    – PolyGeo
    Commented Mar 7, 2013 at 23:50
  • Thanks so much for getting back to me. I would like to see just one tool dialog at the start to choose the field to be used in all iterations. I've edited my original post to include a screen shot of my model and tool dialog. I've nested this tool inside another to actually create the output table (that was the best way I could figure out how to create an output table from this process.) Commented Mar 8, 2013 at 7:03
  • Are your data in a geodatabase or as shapefiles? In the past, I've had trouble with ModelBuilder failing to recognize values that don't exist yet, whereas freestanding files do not have the same problem. I mostly work in Python now, so I don't know if this is still a problem. Commented Mar 8, 2013 at 15:32
  • I've been running it so far with shapefiles. I haven't tried a geodatabase yet. Commented Mar 8, 2013 at 18:24

1 Answer 1

3

If I'm understanding the need correctly, you could modify the validation code so it will populate the list after selecting a layer. You might have to convert to a python script to get to it (it's in the Script Properties under the Validation tab).

The validation code contains functions that are run when the tool is opened, when a parameter is changed, and after internal validation runs. It doesn't reference a script file like the tool itself does. You have to either edit in place and save, or copy and paste your code in.

I modified this validation code to disable some parameter fields until the first parameter is picked. It also populates a pick list by grabbing the unique values from a feature class's attribute field. Basically, it's set up to wait for a connection to be picked by the user, uses that connection to look at feature class, populates a list based on the values found for one of the FC's fields, and only then makes the rest of the parameters available to fill in.

import arcpy
class ToolValidator:
    """Class for validating a tool's parameter values and controlling
    the behavior of the tool's dialog."""

    def __init__(self):
        """Setup the Geoprocessor and the list of tool parameters."""
        self.params = arcpy.GetParameterInfo()
        self.X = 0

    def initializeParameters(self):
        """Refine the properties of a tool's parameters.  This method is
        called when the tool is opened."""
        self.params[1].enabled = False
        self.params[2].enabled = False
        self.params[3].enabled = False
        #self.params[4].value = "False" #for debugging
        return

    def updateParameters(self):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""

        if self.X == 0:
            if self.params[0].altered == True:

                FC = str(self.params[0].value) + "\\gis.ELEC.ElectricDataset\\gis.ELEC.eCircuitBreaker"
                self.params[4].value = FC
                Col = "FeederID"

                self.params[1].filter.list = [str(val) for val in \
                                        sorted(\
                                            set(\
                                                row.getValue(Col) for row in \
                                                    arcpy.SearchCursor(FC, None, None, Col)\
                                            )\
                                        )\
                                    ]

                self.params[1].enabled = True
                self.params[2].enabled = True
                self.params[3].enabled = True
                self.X = 1
                                #self.params[4].value = "True" #for debugging

        return

    def updateMessages(self):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

Some resources on script validation:

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.