Please enable JavaScript to view this site.

Version:

Navigation: » No topics above this level «

Work with Feature Sets

Prev Top Next More

A feature set is a set of records, each of which can have attributes, a geometry, and a symbol. Feature sets are an essential aspect of many workflows. Often, you will need a feature set with exactly those features that are required to fulfill the purpose of your workflow.

In the simplest case, you may be able to get the feature set you need by querying a map service, possibly filtering for features with particular attribute values or within an area of interest. Other times, you will need to create a feature set from features that you assemble or create in the workflow. The features' components can come from a previous query or some other activity, or you can define them from scratch.

Once you have the feature set, you can use it in activities that take features or a feature set as input. You may also want to step through every feature in the feature set and perform some operation on each feature.

This section discusses strategies for getting feature sets, accessing the individual features and their components, and setting the values of the components.

See also...

Esri FeatureSet 3.x 4.x

Work with Geometries

Work with Symbols

Get a Feature Set by Querying a Map Service

To get a feature set by querying a map service, you use the Query Layer activity.

In some cases, you may be able to configure the Query Layer activity to get exactly those features and feature components that you need in your workflow. The following list describes some of the Query Layer inputs that allow you to control which features and components the query returns:

Output Fields: Configure Output Fields to specify exactly which attributes to include in the returned features. This allows you to strip out any attributes that you don't need in your workflow.

Return Geometry, Output Spatial Reference: If you want the features to include geometries, set Return Geometry to true. Set Output Spatial Reference to the well-known ID (WKID) or well-known text (WKT) of the geometries so they can be drawn on a map.

Where: Use the Where input to filter the features based on attribute values.

Geometry, Distance, Units: Use the Geometry input to filter the features based on location. If you are querying a feature service hosted by ArcGIS Online, you can use the Distance and Units inputs to specify a buffer so the query returns the features within the buffer.

You can use Where in combination with Geometry to filter on both attribute values and location.

If you want the feature set to include all the features in the layer, set the Where input to 1=1 and leave the Geometry input blank.

Ids: The object ID(s) to query for.

The Query Layer activity returns the feature set in the results output. For convenience, the Query Layer also has a features output, which returns the features in a collection, and a feature output, which returns the first feature in the feature set. You can use whichever output is easiest in any given context.

Get a Feature Set from a JSON Definition

The Get Feature Set From JSON activity takes the JavaScript Object Notation (JSON) definition of a feature set as input and converts it to a feature set.

If the JSON definition already exists in the workflow, you can refer to it in the Json input. Otherwise, you can enter the JSON definition as a string. See FeatureSet for an example of a feature set's JSON definition.

Get a Feature Set from the Current Feature(s)

A feature set may be retrieved through means outside of the workflow, such as a search or identify operation. In this case, the feature set must be passed to a workflow as an input. The host application must be configured to pass an input to the workflow, and the workflow must also be configured to accept the input. Each type of host application requires unique configuration. Use the following resources as guides:

VertiGIS Studio Web

Host and Run a Workflow that Takes a Run-Time Input

VertiGIS Studio Mobile

Host and Run a Workflow that Takes a Run-Time Input

Geocortex Viewer for HTML5

Use a Hyperlink to Host and Run a Workflow with Inputs

Configure the Context Menu and Run the Workflow

Create a New Feature Set

The Create Feature Set activity allows you to create a new feature set.

The Create Feature Set activity has two inputs: Geometries and Features. Which input you use depends on your workflow. The Geometries input takes one or more geometries and creates a feature set of features that have a geometry but no attributes or symbol.

The Features input takes one or more features and the features in the resulting feature set can have whatever components you want—attributes, geometry, and/or symbol. Where you get the features is up to you. You could use features that already exist in the workflow, modifying them as needed, or you could create new features using the Create Feature activity.

Example - Create a Feature Set from Scratch

This example illustrates one way to create a feature set from scratch. The example workflow creates a single feature using the Create Feature activity, and then creates a feature set out of the feature using the Create Feature Set activity.

create-feature-set-from-scratch

Flowchart for a workflow that creates a feature set from scratch

large-number-01

Create Point - The Create Point activity is used to create a geometry for the feature.

Instead of creating a point, you could use the Geometry Picker form element to get the geometry from the user, or you could use a geometry that already exists in the workflow. For example, the geometry could come from a feature returned by a query made using the Query Layer activity, or from the output of an activity that outputs a geometry, like Buffer Geometry, Project Geometry, or Union Geometries.

large-number-02

Get Symbol From JSON - The Get Symbol From JSON activity is used to define the feature's symbol. You define the symbol using JSON, and the Get Symbol From JSON activity converts the JSON to a Symbol object. To learn how to define a symbol using JSON, see Symbol.

If the workflow already has a feature with the desired symbol, you could use the existing symbol instead of creating a new symbol from JSON. See Access Features or their Components for information on accessing an existing symbol.


large-number-03

Create Feature - The Create Feature activity is used to create the new feature from the attributes, geometry, and symbol specified as inputs:

The attributes are defined directly in the Attributes input using JSON. To learn how to define attributes using JSON, see Feature.

Often the attributes already exist in your workflow. For example, the attributes could come from features returned by a query made using the Query Layer activity.

The Geometry input is set to the output of the Create Point activity: =$point1.point

The Symbol input is set to the output of the Get Symbol From JSON activity: =$symbol1.symbol


large-number-04

Create Feature Set - The Create Feature Set activity is used to create a feature set from the output of the Create Feature activity. The Features input is set to: =$feature1.feature

To create a feature set with multiple features, you could specify a collection of features as input to the Create Feature Set activity, instead of a single feature, for example:

=[$feature1.feature, $feature2.feature, $feature3.feature]

To add more features to the feature set, use the Add Item or Add Items activity. Set the activity's Collection input to =$featureSet1.featureSet.features.


Access Features or their Components

To access a particular feature in a feature set, you use an expression. You can use either an expression or an activity to access the feature's attributes, geometry, or symbol.

Use an Expression to Access a Feature or its Components

When you use an expression to access a feature or component, the term that you use depends on which activity the feature set came from:

Query Layer: The Query Layer activity returns a feature set in the results output. The Query Layer activity also has a features output containing a collection of the features. Both outputs give you access to all the features in the feature set. Using the features output is shorter. In either case, the features are indexed numerically starting at zero: features[0], features[1], features[2], and so on.

Feature: To access a feature, use a term similar to one of the following in an expression:
$query1.results.features[0]
or
$query1.features[0]

Attributes: To access an attribute of a particular feature, use a term similar to one of the following in an expression:
$query1.results.features[0].attributes.{Field Name}
For example: $query1.results.features[0].attributes.STATE_NAME
or
$query1.features[0].attributes.{Field Name}
For example: $query1.features[0].attributes.STATE_NAME

Geometry: See Use an Expression to Access a Feature’s Geometry.

Symbol: See Access a Feature’s Symbol.

Create Feature Set, Get Feature Set From JSON: The Create Feature Set and Get Feature Set From JSON activities return a feature set in the featureSet output. The features are indexed numerically starting at zero: features[0], features[1], features[2], and so on.

Feature: To access a feature, use a term similar to the following in an expression:
$featureSet1.featureSet.features[0]

Attributes: To access an attribute of a particular feature, use a term similar to the following in an expression:
$featureSet1.featureSet.features[0].attributes.{Field Name}
For example: $featureSet1.featureSet.features[0].attributes.STATE_NAME

Geometry: See Use an Expression to Access a Feature’s Geometry.

Symbol: See Access a Feature’s Symbol.

Use an Activity to Access a Feature’s Components

VertiGIS Studio Workflow has activities to access a particular feature's attributes or geometry:

Attributes: The Get Feature Attribute Value activity gets the value of a particular feature attribute.
To configure the Get Feature Attribute Value activity:

1.In the Features input, specify the feature using one of the forms described in Use an Expression to Access a Feature or its Components.
For example, if you got the feature set from a query, set the Features input to an expression similar to: =$query1.features[0]

2.Set the Attribute input to the field name of the attribute whose value you want to get, for example: STATE_NAME
You will be able to access the attribute's value using a term similar to the following:
$attributeValue1.value

Geometry: See Use an Activity to Access a Feature’s Geometry.

Set the Value for a Component

VertiGIS Studio Workflow has activities to set the attribute values, geometry, and symbol for a particular feature:

Attributes: The Set Feature Attribute activity set the value of a particular attribute.
To configure the Set Feature Attribute activity:

1.In the Feature input, specify the feature using one of the forms described in Use an Expression to Access a Feature or its Components.

2.Set the Attribute Name input to the field name of the attribute whose value you want to set, for example: LAST_NAME

3.Set the Attribute Value input to the value you want to assign, for example: Smith

Geometry: See Set the Geometry for a Feature.

Symbol: See Set the Symbol for a Feature.

Step Through the Features Returned by a Query

To access each feature in a feature set one at a time, use the For Each activity. The For Each activity is designed to step through each item in a collection and run the For Each activity's subworkflow for each item.

To configure the For Each activity, you set the Items input to the collection of features, and then create the subworkflow that you want to run for each feature. The term that you use for the Items input depends on which activity you used to create the feature set:

Query Layer: If you got the feature set using the Query Layer activity, set the For Each activity's Items input to an expression similar to the following:

=$query1.features

Create Feature Set, Get Feature Set From JSON: If you created the feature set using the Create Feature Set or Get Feature Set From JSON activity, set the Items input to an expression similar to the following:

=$featureSet1.featureSet.features

In the For Each activity's subworkflow, you can access the current feature using the item output. The first time the subworkflow runs, item is the first feature in the feature set; the second time the subworkflow runs, item is the second feature in the feature set; and so on. This allows the subworkflow to view or modify each feature in the feature set, one feature at a time. For example, you could use activities like Set Feature Attribute or Set Feature Symbol to modify each feature in the feature set, or you could use an activity like Project Geometry to change the spatial reference of each geometry.

See also...

Use the For Each Activity

Example - Step Through the Features Returned by a Query

This example shows you how to use a For Each activity to step through the features returned by a Query Layer activity. The query returns features for three US states—New York, Pennsylvania, and New Jersey, in that order. The For Each subworkflow consists of an Alert activity that displays the state name for the current feature, so you can watch how the For Each activity steps through each feature in the collection.

Workflow Logic

The workflow has the following activities, in the order shown:

Query Layer (query1): Query an ArcGIS layer for US states in a particular region.

For Each (forEach1): Step through each feature, running the subworkflow for each feature, until the end of the collection is reached.
The subworkflow has the following activity:

Alert: Display the current feature's state name so you can watch the For Each activity step through each feature.

To step through each feature returned by a query:

1.Open Workflow Designer.

2.In a new, blank workflow, add the following activities and connect them in the order given:

Query Layer (query1)

For Each (forEach1)

3.Query Layer (query1): Configure the inputs:

Url: https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3
The Url input specifies the URL for a layer of US states.

Where: SUB_REGION='Middle Atlantic'
The Where input filters for states in the Middle Atlantic region—New York, Pennsylvania, and New Jersey.

Output Fields: STATE_NAME
The Output Fields input specifies to return a single field, the state name, in the query results.

4.For Each (forEach1):

Set the Items input to: =$query1.features
This makes the For Each activity operate on the features returned by the query.

Double-click the For Each activity to open its subworkflow.

Add the following activity:

Alert: Set the Text input to a string that includes the value you want to display, for example:
="Accessing feature: " + $forEach1.item.attributes.STATE_NAME

Click Start in the breadcrumbs to return to the main workflow.

5.Run the workflow in the Sandbox.
The subworkflow runs once for each feature, starting with the first feature (inline-number-01). Click OK to close the alert and proceed to the next feature (inline-number-02).
iterate-through-feature-set
Alert in a For Each subworkflow that displays the state name for the current feature
 

6.Press Ctrl+S to save the workflow.

Find a Particular Feature Returned by a Query

To find a particular feature returned by a query, use a For Each activity to step through and examine each feature until you find the feature you want. Then, if you need to do something quick like update the feature, you can do that directly in the For Each subworkflow. If, however, you need the feature to be available later in the workflow, you can use a Create Value activity to pass back the feature or its index to the main workflow. After that, you can exit the For Each activity. This prevents the For Each activity from doing unnecessary processing.

See also...

Use the For Each Activity

Example - Find a Particular Feature Returned by a Query

This example shows you how to use a For Each activity to find a particular feature returned by querying a layer of US states. You will find the feature for California.

To find the California feature, the For Each subworkflow has an If activity that compares the name of the current feature to "California". If the current feature matches, the subworkflow does the following:

It makes the For Each activity's Exit input true so the For Each activity exits when it steps to the next feature.

It stores the California feature so the feature can be used later in the workflow.

Workflow Logic

The workflow has the following activities, in the order shown:

Query Layer (query1): Query an ArcGIS layer for US states in a particular region.

Create Value (value1): Create an intermediate value to control exiting the For Each activity. Set it to false.

For Each (forEach1): Step through each feature, running the subworkflow for each feature, until you find the feature you want or the end of the collection is reached.
The subworkflow has the following activities:

If: Check whether the current feature is the feature you want.
If you found the feature:

Evaluate Expression: Set the intermediate value to true.

Create Value (value2): Store the item so you can use it in the main workflow.

Alert: Display the state name of the current feature so you can verify that the workflow found the correct feature.

To find a particular feature returned by a query:

1.Open Workflow Designer.

2.In a new, blank workflow, add the following activities and connect them in the order given:

Query Layer (query1)

Create Value (value1)

For Each (forEach1)

Alert

3.Query Layer: Configure the inputs:

Url: https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3
The Url input specifies the URL for a layer of US states.

Where: 1=1
This returns all the features.

Output Fields: STATE_NAME
The Output Fields input specifies to return a single field, the state name, in the query results.

4.Create Value: Set the Expression input to: =false

5.For Each:

Configure the inputs:

Items: =$query1.features
This makes the For Each activity operate on the features returned by the query.

Exit: =$value1.result
This makes the Exit input depend on the intermediate value, so when the intermediate value becomes true, Exit also becomes true.

Double-click the For Each activity to open its subworkflow.

Add the following activities and connect them in the order given:

If

Evaluate Expression: Connect this activity to the If activity's True branch.

Create Value (value2): Connect this activity to the Evaluate Expression activity.

If: Set the Condition input to: =$forEach1.item.attributes.STATE_NAME == "California"
This compares (==) the current feature's state name ($forEach1.item.attributes.STATE_NAME) to the state you are looking for ("California").
For information about the == operator, see Comparison operators.

Evaluate Expression: Set the Expression input to: =$value1.result = true
This sets the intermediate value to true, which makes the Exit input true, so the For Each activity will exit at the beginning of the next loop.
In the Expression input =$value1.result = true, the first "=" signals to VertiGIS Studio Workflow that what follows is an expression. In this case, the expression is $value1.result = true. The second "=" assigns the right side of the expression (true) to the left side of the expression ($value1.result).

Create Value (value2): Set the Expression input to: =$forEach1.item
This allows you to pass back the feature to the main workflow. You will access the feature using the term $value2.result.

6.Alert: Set the Text input to a string that includes the value you want to display, for example: ="Found the feature for " + $query1.features[$value2.result].attributes.STATE_NAME

7.Run the workflow in the Sandbox.
The following alert displays:
find-a-particular-feature
Alert in the main workflow after locating the California feature in query results
 

8.Press Ctrl+S to save the workflow.

Get the Index for a Particular Feature Returned by a Query

You can use the For Each activity's pass output to get the index of a feature returned by a query. The pass output counts how many times the For Each activity has looped, starting at 0 for the first feature, 1 for the second feature, 2 for the third feature, and so on. Because the collection of features returned by the Query Layer activity is indexed starting at zero, the value of pass is the also the index of the feature.

The pass output will be undefined when you return to the main workflow, so you will not be able to access it. To pass it back to the main workflow, add a Create Value activity and set its Expression input to an expression similar to =$forEach1.pass. You will be able to access the index in the main workflow using an expression similar to $value2.result.

© 2024 VertiGIS North America Ltd. All Rights Reserved. | Privacy Center | Imprint
Documentation Version 5.41 (dfe743b0)