Select to view content in your preferred language

Attribute Query - return Groups?

2419
8
10-07-2010 10:06 AM
ducksunlimited
Deactivated User
Dear All,

I used ESRI attribute query sample and returned all the values (commercial, commercial, agricultural, agricultural, etc) for that field. But I want only the groups (commericial, agricultural, etc) returned. How to construct the query so I can achieve this. thanks for the help,

Russel
0 Kudos
8 Replies
JenniferNery
Esri Regular Contributor
You can set your query's OutFields property so that it will return only the fields that you want it to return.
            query.OutFields.AddRange(new string[] { "FIELD_NAME" });
0 Kudos
ducksunlimited
Deactivated User
You can set your query's OutFields property so that it will return only the fields that you want it to return.
            query.OutFields.AddRange(new string[] { "FIELD_NAME" });


thanks for your reply!

I want to return only catogories for a field. For instance, I have a "LanUseType" field with values like commercial, agriculatural, wetlands, etc. How can I group by features using "LandUseType"? Help would be appreciated.

Russel
0 Kudos
BrianPangtay
Regular Contributor
ESRI attribute queries are based on SQL queries. Since the ESRI API only allows one to specify the WHERE clause of a SQL query, I don't think one can perform a group query in this manner.

Using transaction SQL,

If you want grouping to perform calculations, then one would need a GROUP BY clause in the SQL query.

If you only want the unique values for a given field, then one would need a DISTINCT keyword in the SQL query.
0 Kudos
JenniferNery
Esri Regular Contributor
Do you mean this?

In this feature service http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer...

ftype is CodedValueDomain, each number represent a category that can be one of the following values (Hydro-Meteorlogical, Public Health, ... Vehicle)

If I want to see only features that are "Vehicle", my query's Where is "ftype = 10801"
0 Kudos
ducksunlimited
Deactivated User
Do you mean this?

In this feature service http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer...

ftype is CodedValueDomain, each number represent a category that can be one of the following values (Hydro-Meteorlogical, Public Health, ... Vehicle)

If I want to see only features that are "Vehicle", my query's Where is "ftype = 10801"



Thanks for the reply. I would like to return each group (like Hydro-Meteorlogical, Vehicle, etc) as a row in a datagrid, so users can select a row and zoom to that group (multiple polygons). Can I construt the Query.Where clause to do this? Thanks,
0 Kudos
JenniferNery
Esri Regular Contributor
I think what you can do is first know the groups, which you can do by:

  foreach (Field field in fl.LayerInfo.Fields)
   {
    if (field.Domain is CodedValueDomain)
    {
     CodedValueDomain domain = field.Domain as CodedValueDomain;
     foreach (var item in domain.CodedValues)
     {
//item.Key is an object this is what you need in your query

     }
    }
   }


If your FeatureLayer was HomelandSecurity as in my previous post, you can see that ftype is CodedValueDomain and you can perform your query where "ftype = 10801".
0 Kudos
ducksunlimited
Deactivated User
I think what you can do is first know the groups, which you can do by:

  foreach (Field field in fl.LayerInfo.Fields)
   {
    if (field.Domain is CodedValueDomain)
    {
     CodedValueDomain domain = field.Domain as CodedValueDomain;
     foreach (var item in domain.CodedValues)
     {
//item.Key is an object this is what you need in your query

     }
    }
   }


If your FeatureLayer was HomelandSecurity as in my previous post, you can see that ftype is CodedValueDomain and you can perform your query where "ftype = 10801".


Thanks for the help. I see this will work.

But CodedDomain is only supported in 2.0 not 1.2 right?
0 Kudos
JenniferNery
Esri Regular Contributor
Yes you're right CodedValueDomain is new to 2.0.
0 Kudos