How to optimize polygon feature selection?

839
4
Jump to solution
05-30-2019 12:16 PM
JohnMoore1
New Contributor II

Is there anyway to optimize the following feature selection code?  Currently, there's about a second delay between when the user taps the screen in the iPad simulator and when the polygon feature is highlighted after being selected.  I can't give an exact count, but there are a LOT of polygons in the "Polygons Layer" feature layer.  Thanks for any help!

func handleSelectionByTapAtScreenPoint(screenPoint: CGPoint) {

      // Select the feature in the Polygons Layer that was tapped.

      let layers = self.mapView.map?.operationalLayers as? [AGSLayer]

      for layer in layers! {

            if let featureLayer = layer as? AGSFeatureLayer, featureLayer.name == "Polygons Layer" {

                  self.mapView.identifyLayer(featureLayer, screenPoint: screenPoint, tolerance: 1, returnPopupsOnly: false, maximumResults: 5) { (identifyLayerResult: AGSIdentifyLayerResult) in

                        for geoElement in identifyLayerResult.geoElements {

                              if let feature = geoElement as? AGSFeature {

                                    // Select the feature

                                    featureLayer.select(feature)

                              }

                        }

                  }

            }

      }

}  

0 Kudos
1 Solution

Accepted Solutions
DiveshGoyal
Esri Regular Contributor
 I also noticed that the network progress indicator lights up whenever a feature is selected.  Does an identifyLayer call incur a network delay for some reason in order to determine which feature is identified?

Yes. Typically, the features you see on the map are fetched in a way to optimize their display. When you identify a feature, you expect the result to contain the full data of the feature (for eg, all the attributes, the full resolution of the geometry, etc). This needs to be fetched asynchronously from the backing data source. If your layer is connecting to the service, that means we have to make a network request to get that data from the service. This can take time. 

However, if your layer uses offline data from disk (for example a mobile map package or a mobile geodatabase), then we fetch the data from disk, which is typically pretty fast, but still requires a lookup.
Additionally,  we sometimes need to perform spatial queries to find the feature you tapped on that. That can take some time too. All of this adds up.

After getting the results if you choose to select the features, that requires us to update the display and add a selection effect. If your polygon contains a large number of vertices (typically in the order of thousands), it can take a little bit of time to render the selection on the GPU. Can you check how many vertices the selected features have in your data? One way to improve performance would be to pre-process the data and generalize the features to reduce vertices.

View solution in original post

0 Kudos
4 Replies
JohnMoore1
New Contributor II

On a side note, I tried experimenting with static and dynamic rendering mode for the polygon feature layer, but that didn't seem to affect selection performance.  I also noticed that the network progress indicator lights up whenever a feature is selected.  Does an identifyLayer call incur a network delay for some reason in order to determine which feature is identified?

Edit:

I just found this excerpt from the help docs which answered my question:  "Identify methods are asynchronous, so that the UI thread of your application is not blocked waiting for results. This is especially important when working with data which resides on a server, as results do not return immediately."

 

Is it possible to use identifyLayer on cached data to avoid this network delay?  What is the best way to go about caching things?  Any help pointing me in the right direction would be appreciated.  Thanks!

0 Kudos
JohnMoore1
New Contributor II

I tried testing the sample data collection "Trees of Portland" app.  I downloaded part of the map and worked offline.  It still took over a second for features to highlight after selecting them.  Is there a way to improve selection performance in general or is this a limitation of the API?

0 Kudos
DiveshGoyal
Esri Regular Contributor
 I also noticed that the network progress indicator lights up whenever a feature is selected.  Does an identifyLayer call incur a network delay for some reason in order to determine which feature is identified?

Yes. Typically, the features you see on the map are fetched in a way to optimize their display. When you identify a feature, you expect the result to contain the full data of the feature (for eg, all the attributes, the full resolution of the geometry, etc). This needs to be fetched asynchronously from the backing data source. If your layer is connecting to the service, that means we have to make a network request to get that data from the service. This can take time. 

However, if your layer uses offline data from disk (for example a mobile map package or a mobile geodatabase), then we fetch the data from disk, which is typically pretty fast, but still requires a lookup.
Additionally,  we sometimes need to perform spatial queries to find the feature you tapped on that. That can take some time too. All of this adds up.

After getting the results if you choose to select the features, that requires us to update the display and add a selection effect. If your polygon contains a large number of vertices (typically in the order of thousands), it can take a little bit of time to render the selection on the GPU. Can you check how many vertices the selected features have in your data? One way to improve performance would be to pre-process the data and generalize the features to reduce vertices.

0 Kudos
JohnMoore1
New Contributor II

Thanks, Divesh.  Could you explain what you mean by "pre-process" the data?

0 Kudos