Select to view content in your preferred language

Create single feature when using Feature Sets

641
2
07-13-2018 08:57 AM
AndrewWillingale
Occasional Contributor

Hi. I have an existing model which is used in ArcGIS Desktop 10.3 which I would like to improve.

To use the model the user chooses a start and end point on the map and the model then calculates distances using different methods. The start and end points have been configured as feature sets and are interactively entered from the model tool dialog box. 

The issue I have is that there is nothing stopping the user clicking more than once and ending up with multiple start and end points. This provides a poor user experience and breaks the model. 

Can anyone tell me whether it is possible when using feature sets to restrict the user to only creating one feature? Alternatively, can anyone suggest a neat way of taking a feature set with multiple features and reducing it to one feature?

Many thanks,

Andrew.

0 Kudos
2 Replies
JakeSimms1
Esri Contributor

Andrew,

In short yes, but requires ingenuity. Which in a sense I have done for you.

Here's the end model (this is example data as scenario, you will only need the Get Count and Calculate Value Part):

Since you already have a Feature Set (as it is an input to a tool) you'll insert the Get Count and Calculate Value as a precondition to the tool the Feature Set would connect to.

In this scenario I want to add new schools to the existing feature class (Existing Schools) using the Append Tool. The New School Locations is the Feature Set.

Add the Get Count tool with the Feature Set as the input, make sure to rename the output variable to rowcount (this is important because this output is used in the Calculate Value expression/code block).

Add the Calculate Value tool (model builder only tool- in Model Builder > Insert > Model Only Tools > Calculate Value). Set the Get Count output as a precondition to the Calculate Value as we need the Get Count to run first to count how many features are added to the in-memory table.

Right click and Open the Calculate Value tool to modify the expression and code block. This is the code:

Expression:

countRows("%rowcount%")

Code Block (optional):

def countRows(RowCount):
    import arcpy
    if %RowCount% == 2:
        return "true"
else:
   return "false"

This code is short looks at the output of the Get Count tool (the rows added to the in-memory table; if you add one feature its 1 row, two features 2 rows and so on) for your case set the value to two (2) so that when your user clicks a start and end which creates two features in the in-memory table. (this may be different as your environment/model parameters/etc may have different requirements. This model uses point features and you may be using line features.)

Then set the output of the Calculate Value tool as a precondition to your current model's first tool in which your Feature Set was connected as an input. 

When run, the tool will only work if there is two points selected. Otherwise the tool will provide an informative message saying "The process did not execute because the precondition is false." The false precondition is that the Calculate Value tool's if statement was not met, meaning an input of anything but two selections.

The model will run as "Completed" regardless of whether the user selects the desired amount of inputs or not because the in the Calculate Value tool outputs a Boolean value which is just true or false. There are ways to prompt error messaging in your model. But that for another GeoNet Post. 

AndrewWillingale
Occasional Contributor

Many thanks for this Jake, it's greatly appreciated. I'll try and give this a go in the new year.

Kind regards, Andrew.

0 Kudos