Android: Attempting to extract the layer or graphic details from the selected rectangle

536
4
06-28-2022 08:36 AM
Dee4
by
New Contributor II

There is a feature on the map that allows you to select a certain area in the existing map using a 'RECTANGLE' or any using other options. We need to show the layer details within the selected area, . I've attached a screenshot in which I've used sketchEditor to mark the area, and now I need to show the available layer data within that area. I'm not sure how to proceed because we need to pass some parameters, such as the screen point, in order to get the layer data. I can get the geometry value from the sketchEditor, but I'm not sure if I can access the layer data from passing that. 

Could anyone mention how to get the graphic details from the selected area?

 

Dee4_0-1656430349977.jpeg

 

0 Kudos
4 Replies
RamaChintapalli
Esri Contributor

Hi,

If the operational layers from which you are trying get data are FeatureLayers, then you can perform a spatial query on its feature table.

You can use this sample as a reference to perform a query on FeatureLayer. The sample is performing a query based on where condition, but you can update the sample to set your rectangle's geometry as query parameter's geometry and then also define a spatial relationship.

 

QueryParameters queryParameters = new QueryParameters();
queryParameters.setGeometry = <YOUR INPUT RECTANGLE GEOMETRY>;
queryParameters.setSpatialRelationship(QueryParameters.SpatialRelationship.INTERSECTS);

 



Thanks
Rama 

0 Kudos
Dee4
by
New Contributor II

Hi Rama,

Thanks for quick response. I'm able to get the SeviceFeature table. Now im facing "java.util.concurrent.ExecutionException: com.esri.arcgisruntime.ArcGISRuntimeException: Invalid call.: Object failed to load, unable to execute task." for below mentioned code. 

This error is occuring when we are trying to get the result from feature table "queryResult.get()" @ line number 10. 

fun getFeatures(featureTables: List<ServiceFeatureTable>){

    val queryParameters = QueryParameters()
    queryParameters.geometry = graphic.geometry
    queryParameters.spatialRelationship = QueryParameters.SpatialRelationship.CONTAINS

    val queryResult = featureTables[0].queryFeaturesAsync(queryParameters)
    queryResult.addDoneListener {
      try {
        val result = queryResult.get()
      } catch (e: Exception) {
        e.printStackTrace()
      }
    }
  }
0 Kudos
RamaChintapalli
Esri Contributor

Hi,

Whats the geometry being passed here. Is it an envelope or polygon, does it have a spatial reference defined? Also which feature service being used - is it an enterprise feature service or ArcGIS Online hosted feature service?

I was able to get the spatial query work with below sample service, only difference is the input geometry and service.

 

 
ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Sync/WildfireSync/FeatureServer/0");


QueryParameters queryParameters = new QueryParameters();
 queryParameters.setGeometry(mapView.getVisibleArea().getExtent());    
queryParameters.setSpatialRelationship(QueryParameters.SpatialRelationship.CONTAINS);

serviceFeatureTable.queryFeaturesAsync(queryParameters);

 

 

0 Kudos
Dee4
by
New Contributor II

Thank You RamaChintapalli.

0 Kudos