Work with Feature Sets

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:

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.

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.

Flowchart for a workflow that creates a feature set from scratch

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.

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.

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

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:

Use an Activity to Access a Feature’s Components

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

Set the Value for a Component

Geocortex Workflow has activities to set the attribute values, geometry, and symbol for a particular 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:

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:

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:

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

  4. For Each (forEach1):

    1. Set the Items input to: =$query1.features

      This makes the For Each activity operate on the features returned by the query.

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

    3. 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

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

  5. Run the workflow in the Sandbox.

    To run a workflow in the Sandbox, click Info in the sidebar, click Run in Sandbox, select the environment, configure the Sandbox settings, and then click Run Workflow. You can press F12 at any time to see the verbose log.

    The subworkflow runs once for each feature, starting with the first feature (). Click OK to close the alert and proceed to the next feature ().

    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:

Workflow Logic

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

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:

  3. Query Layer: Configure the inputs:

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

  5. For Each:

    1. 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.

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

    3. 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.
    4. 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.

    5. 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 Geocortex 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).

    6. 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.

    To run a workflow in the Sandbox, click Info in the sidebar, click Run in Sandbox, select the environment, configure the Sandbox settings, and then click Run Workflow. You can press F12 at any time to see the verbose log.

    The following alert displays:

    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.

© 2019 Latitude Geographics Group Ltd. All Rights Reserved.

Documentation Version 5.12