Identify features

An identify operation is a user-driven operation typically involving a single click on the map and the retrieval of information about any features hit by that clicked point from any layer in the map. This operation has the potential to retrieve a lot of information depending on the identify parameters specified. Use the IdentifyTask to search the layers in both local and online data for features that intersect an input geometry. Once the matching features are returned, you can display their geometries and attributes in your application.

Using the IdentifyTask with online data

To perform Identify operations on online data in your application you will need to pass the URL of an online service or layer. To find the URL, you can use the ArcGIS Services Directory.

Map {
        id: mainMap
        anchors.fill: parent
        focus: true

        ArcGISDynamicMapServiceLayer {
            url: "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"
        }

Define the IdentifyTask component

Add an IdentifyTask component. Set the URL property with the service URL that contains the layers to be used with the IdentifyTask. The onIdentifyTaskStatusChanged signal handler is used for handling successful and unsuccessful results during the execution of the IdentifyTask.

IdentifyTask {
        id: identifyTask
        url: serviceLayerUrl

        onIdentifyTaskStatusChanged: {
            if (identifyTaskStatus === Enums.IdentifyTaskStatusCompleted) {
												// Get and display the results
															...

            } else if (identifyTaskStatus === Enums.IdentifyTaskStatusErrored) {
				           // Handle the error
               ...
            }
        }
    }

Specify the IdentifyParameters inputs

Before using Identify operations you will need to define the operation's input parameters. These parameters will vary depending on the operation. The IdentifyParameters object is used to specify the input for the IdentifyTask. You can customize your Identify operation by specifying Identify parameters such as layer IDs to narrow down the amount of data you see by filtering the layers you are interested in. The layerMode parameter can also be set to search only the top-most or visible layers. By reducing the number of layers Identify works with, you can quickly focus on what is important to you. The geometry property allows you to specify a geometry to perform an Identify on. This enables the flexibility of identify areas such as polygons, envelopes and polylines as well as points. The IdentifyParameters component defines how you want the IdentifyTask to operate. Set the desired properties on IdentifyParameters and then pass it into the constructor of the IdentifyTask. Here are some basic guidelines:

  • Identify operates by intersecting a geometry with the features in one or more layers. Provide the intersection geometry in the geometry property
  • Control the distance (in pixels) from your geometry that the intersection will be performed using the tolerance property.
  • Identify can be performed on any of the layers. You specify the layers, by id, that take part in the identify using the layers property. Alternatively, specify the visible layers, the top most layer or all layers.
// Define the identifyParameters component...
 
IdentifyParameters {
     id: identifyParameters
}

    // Define an onMouseClicked method to handle the Identify action...

    onMouseClicked: {
            
            // Set the parameters...
            identifyParameters.geometry = mouse.mapPoint;
            identifyParameters.mapExtent = mainMap.extent;
            identifyParameters.mapHeight = mainMap.height;
            identifyParameters.mapWidth = mainMap.width;
            identifyParameters.layerMode = Enums.LayerModeVisibleLayers;
            identifyParameters.DPI =  Screen.pixelDensity * 25.4;
            
	           // Now that the params have been set, execute the task...
            identifyTask.execute(identifyParameters);
    }

After declaring the IdentifyParameters component, you can, for example, add an onMouseClicked handler within your Map component to use the IdentifyParameters and set its properties

Process the results

The results of the IdentifyTask are returned in a list of IdentifyResults. Each item in the array represents a feature containing one geometry and one or more attributes with their values. Once you have acquired the IdentifyResult collection all that remains is for you to process the contents.

IdentifyTask {
        id: identifyTask
        url: serviceLayerUrl

        onIdentifyTaskStatusChanged: {
            if (identifyTaskStatus === Enums.IdentifyTaskStatusCompleted) {

                for (var index in identifyResult) {
                    var result = identifyResult[index];
                    fieldsModel.append({"name": result.layerName, "value": result.value.toString()});
                }

            } else if (identifyTaskStatus === Enums.IdentifyTaskStatusErrored) {
                resultText.text = identifyError.message;

            }
        }
    }

Sample code

To view any samples related to searching data, please launch the ArcGIS Runtime QML sample application and explore the interactive samples and their code in the Search section.