Get distinct values from AGS
Not sure where to ask this, it's not really related to any forum.
I found this old blog post: http://blog.geocortex.com/2008/09/11/bending-the-rules/ and was wondering if a similar approach is possible with the ArcGIS Server REST api. The first approach should work I guess, but would probably still require more than one query. I tried the 2nd approach (http://myserver/arcgis/rest/services/myservice/mapserver/0/query) but only get 'unable to perform query'.
Any ideas?
-
Hi Berend,
I was sad when that trick stopped working in queries, as it was rather useful. I haven't found any efficient method of doing this with most versions of AGS, but with 10.1 there are a few options available. First, if the map service is enabled for dynamic layers, a query-sourced dynamic layer should do pretty much whatever you want it to do, including return distinct values, since it uses a SQL query that you define in the request. This is likely the most standard and most efficient way of doing things. See documentation at http://servicesbeta2.esri.com/arcgis/sdk/rest/dataSource.html#queryTable.
You may find yourself unable to make a service dynamic, even when using 10.1. Perhaps you are not able to do this as per corporate policy, or perhaps the AGS service is not under your control. All is not completely lost, since as usual there are ways of bending the rules. There may be more clever ways of going about this, but AGS 10.1 has a new operation on a layer called GenerateRenderer. You can request a unique value renderer from the layer, specifying the name of the field you'd like distinct values for. Behind the scenes, AGS will get distinct values and give you a renderer back, which will include a single class for each distinct value. It's less efficient than a query table as you need to parse out the values from all of the classes in the renderer, but still much much faster than issuing multiple queries to AGS. The long URL below is an example of retrieving all of the distinct state names in a counties layer in AGS:
John
0 -
Hi John,
That's some useful information. I also found out that in 10.0 it is possible to publish a layer based on a view or sql statement (ArcMap's 'query layer'). Of course you still need to have control over AGS, but it's an easy way to get distinct values.
0
Du måste logga in om du vill lämna en kommentar.
Kommentarer
2 kommentarer