Getting CodedValueDomain from QueryTask result.

3073
5
07-07-2015 01:47 AM
SalihYalcin
New Contributor III

Hello everyone,

I am developing an app that uses QueryTask feature of Esri Android SDK. Evertyhing is perfect except one thing. QueryTask results return Attribute Values and I am displaying this values at Popup. Let me explain deeply. Results have district field. I use district_name with coded value. For example; When value 1 district name display Green, when value 2 district name display Blue. At the SDK side, I am able to show district name =1 or district name=2. I want to show real district name with CodedValueDomain.

I showed like left popup my attributes but I want to show like right popup. I dont know how to access codedValueDomains. I've read API documentation, samples etc.

test.png

Here is my code approach;

private class AsyncQueryTask extends AsyncTask<String, Void, FeatureResult> {

@Override
protected void onPreExecute() {
progress = new ProgressDialog(MainActivity.this);
progress = ProgressDialog.show(MainActivity.this, "",
"Please wait....query task is executing");
}
/**
* First member in string array is the query URL; second member is the
* where clause.
*/
@Override
protected FeatureResult doInBackground(String... queryArray) {
if (queryArray == null || queryArray.length <= 1)
return null;
String url = "http://company.gov.tr/arcgis/rest/services/GIS/Parcel/MapServer/1"
QueryParameters qParameters = new QueryParameters();
String whereClause = queryArray[1];
SpatialReference sr = SpatialReference.create(102100);
qParameters.setGeometry(mMapView.getExtent());
qParameters.setOutSpatialReference(sr);
qParameters.setReturnGeometry(true);
qParameters.setWhere(whereClause);
QueryTask qTask = new QueryTask(url);
try {
FeatureResult results = qTask.execute(qParameters);
return results;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(FeatureResult results) {
String message = "No result comes back";
if (results != null) {
int size = (int) results.featureCount();
for (Object element : results) {
progress.incrementProgressBy(size / 100);
if (element instanceof Feature) {
Feature feature = (Feature) element;
// turn feature into graphic
Graphic graphic = new Graphic(feature.getGeometry(),
feature.getSymbol(), feature.getAttributes());
// add graphic to layer
graphicsLayer.addGraphic(graphic);
}
}
// update message with results
message = String.valueOf(results.featureCount())
+ " results have returned from query.";
}
progress.dismiss();
Toast toast = Toast.makeText(MainActivity.this, message,
Toast.LENGTH_LONG);
toast.show();
boolQuery = false;
}
}

Dan O'Neill

Will Crick

0 Kudos
5 Replies
WillCrick
Occasional Contributor

Hi Salih,

Can you post the code you are using to display the popup? If you are using our Popup and PopupContainer, this should be done for you. But if you are displaying your own type of popup, then you will have to access the CodedValueDomain object.

The CodedValueDomain object has a method called getCodedValues()  which gives you back the mapping between the Code (the value in the attribute) and the Name (the string you want to show to the user) as a Map.

CodedValueDomains are accessible when you are using FeatureLayers or ArcGISMapServiceLayers (as they load the service metadata associated with the layer so you can access it as a developer). You might want to consider using a FeatureLayer in SelectionMode to show these features from a query, then you can access the Domains and other properties to help you build the UI that you need.

I hope that helps.

Will

0 Kudos
SalihYalcin
New Contributor III

Hi Will,

Thank you for your respond. Your soultion looks great but unfortunately I'm not using your approach to get domain names. You can say why ? Let me explain. I make QueryTask from featureLayer and take results send them another activity and I am creating graphic from FeatureResult and add graphic to GraphicsLayer. My whole aim is get domain values from this GraphicsLayer.  ( I've added code block my question at above)

As I can see your post I'm not able to get domain names from graphics.

Thanks

0 Kudos
WillCrick
Occasional Contributor

Yes, sorry, domains are not supported for graphics, to use domains you need to be using a feature layer.

You could try using a FeatureLayer with a FeatureSet made from your graphics. If you use the same layer definition string as your feature layer then the domains will be available to you. Look at this constructor:

https://developers.arcgis.com/android/api-reference/reference/com/esri/android/map/ags/ArcGISFeature...

0 Kudos
SalihYalcin
New Contributor III

Hello Will,

I can ask one question for this issue. I make QueryTask and QueryTask's onPostExecute result is FeatureResult. FeatureResult have getFields method and this getFields method have getDomains. I'm wondering why this process return null value. I think this process should not be difficult like this

I want to access domains with method below;

@Override
protected void onPostExecute(FeatureResult results) {

  results.getFields().get(0).getDomain //----> This line return null value..

}

0 Kudos
WillCrick
Occasional Contributor

Hi,

When you use the QueryTask the resulting json does not include the full layer definition (which includes information about domains). The same Field object is reused in a number of places, including for ArcGISFeatureLayer.getFields() and GeodatabaseFeatureServiceTable.getFields(). For these two cases, we have the layer defiinition and can return you the domain information. When dealing with the results from a QueryTask, we do not have this information.

If you use the ArcGISFeatureLayer.queryFeatures() or GeodatabaseFeatureServiceTable.queryFeatures() method, then you will get domain information and this will work.

Will

0 Kudos