5

I have prepared and published with ArcMap 10.1 to my ArcGIS Server a Query Layer to access some information in my database. My output map represents the European Union states and using annotations, the number of cities and villages each country has.

Now, I would like to go a step further and try to specify some parameters in the WHERE clause of the SQL query that defines my query layer. Therefore the user in my web application can select from a drop-down list box simple parameters like filtering just by "Cities" or "Villages" or by population number.

I just would like to know if it is possible to configure ArcGIS to expect some input parameters coming from the web and execute the SQL query with these parameters once they have been received. Is there a way of injecting those parameters back to the ArcGIS Server and make it calculate the data I need?

Please, could you provide any ideas or guidelines about how this would be done?

1
  • ArcGIS pro let's you setup dynamic query layer parameters which can be served up as services. At time of writing the rest API supports these and also in the map viewer.
    – jakc
    Commented Jun 19, 2017 at 12:17

3 Answers 3

3

Absolutely! ArcGIS Server was made for these sorts of tasks. Check out the Query task in the JavaScript API here:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/query_gpresult.html

1
  • a Query task won't change what's displayed in the map, only what is returned in a query result set
    – tomfumb
    Commented Nov 20, 2012 at 21:44
3

This is exactly what I'm currently doing in my ArcGIS Server 10.1 / Oracel DB application. You need to use layer definitions, which enable you to create an SQL query for each layer within a map service. Your original SQL does not get substituted, but rather it is treated like a view, and your layer definitions are applied as a where clause to that view.

You need to know the IDs of the layers within your service to provide as the array index. These can be retrieved using the layer's LayerInfos

For some reason I can't link directly to the API page, so go to this page and click Layers -> ArcGISDynamicMapServiceLayer -> setLayerDefinitions

Example from the API:

Code snippets:
The layerDefinitions argument is an array of layer definition expressions such as in the code snippet below.

var layerDefinitions = [];
layerDefinitions[0] = "POPULATION > 5000000";
layerDefinitions[5] = "AREA > 100000";
dynamicMapServiceLayer.setLayerDefinitions(layerDefinitions);

You can also change how certain features are rendered in 10.1 with setLayerDrawingOptions

3
  • Yes, I was thinking in something like this. But still I have some questions: does this "WHERE" clause accept complex syntax? I mean, "AREA>10000" is a quite simple clause, but suppose my table on the REST service is the product of a JOIN of two tables and I need parameters of both tables. Can I access parameters with a syntax like "A.param1" or "B.param1"? And moreover, does this WHERE in the API accept "SUBSTRING", "LEN" or "REPLACE" functions? Subqueries? AND and OR? Sorry for asking so many things and thanks for your tips! :-)
    – maucacau
    Commented Nov 21, 2012 at 16:31
  • @maucacau I'm afraid I can't give great answers but I'll do my best. If your join is in the database (e.g. the Query Layer query has joins, or your Query Layer is based on a db view which has joins) you simply treat the result as a single table, in which case A.param1 and B.param1 would need to have unique field names. I don't know what happens if the join is defined in the MXD / ArcMap. I believe the SQL syntax is whatever your underlying db supports, which should include common functions. Next comment...
    – tomfumb
    Commented Nov 21, 2012 at 18:06
  • 1
    @maucacau ... you can test the layer definitions approach through your REST interface, e.g. http://<server-name>:6080/arcgis/rest/services/<service-name>/MapServer/export The Layer Definitions syntax is something like 0:TITLE LIKE '%Something%' AND SOMEDATE > '05-Nov-12';1:TITLE LIKE '%Something%' AND SOMEDATE > '05-Nov-12' where 0 and 1 represent layer IDs. The date format in my example is Oracle-friendly
    – tomfumb
    Commented Nov 21, 2012 at 18:09
1

Here's an example I posted the other day of selecting from a drop down and zooming to selected feature using the javascript api.

How to zoom to feature when clicking on drop-down list box item with ArcGIS JS API?

Doug at http://spatialexception.org

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.