Web map filtering by current date?

14870
14
07-01-2013 04:44 AM
ToniSevenius
New Contributor
Hi!

I have published a feature service and a web map to ArcGIS Online that shows some point features. Every feature has a date attribute that I would like to use for filtering. The filter is easy to set for a certain date but is it possible to set the filters value for current date? So that the filters value would be dynamic.

If this is not currently possible, it is a feature that should be implemented.

Any way that I can get around this problem? The point is that I have a lot of data in one feature service but I would like to see only those that are dated for current date.
Tags (2)
14 Replies
JamesCrandall
MVP Frequent Contributor
Hi!

I have published a feature service and a web map to ArcGIS Online that shows some point features. Every feature has a date attribute that I would like to use for filtering. The filter is easy to set for a certain date but is it possible to set the filters value for current date? So that the filters value would be dynamic.

If this is not currently possible, it is a feature that should be implemented.

Any way that I can get around this problem? The point is that I have a lot of data in one feature service but I would like to see only those that are dated for current date.


Maybe setup a definition query on the feature class (in ArcMap) before you publish it?  It should honor the filter you apply to the field, but of course this will require a process to re-publish the map to contain the updates.

Edit: you can use the CURRENT_DATE keyword in the definition query.  It would look something like this using the query builder:


[INDENT]"my_date_field" = CURRENT_DATE[/INDENT]


Then you would just need to setup a scheduled task to publish the map service to get it automated.
0 Kudos
JamesCrandall
MVP Frequent Contributor
Per my last post: I am not so sure that the Definition Query suggestion I made will work.  Maybe I missed something along the way, but I published a map service with a definition query setup and it did not get honored after being published to ArcGIS Online portal (corporate account).

Sorry for any confusion I may have caused and will do some additional testing to see if this is a viable approach.

Edit: the documentation suggests that, yes, you can apply a def query before publishing the map service.


http://resources.arcgis.com/en/help/main/10.1/index.html#//0154000004qs000000


I just must be missing something simple to get it applied.

Edit (3:21pm): I just noticed my def query did actually get applied after some time had passed.  I bet it has to do with the cache/clear cache or some such thing.  So.....  My OP suggestion just may be a viable approach --- I actually plan to implement a similar design where the .mxd's data source is updated, the def query set and .mxd published.
0 Kudos
NilsBabel
Occasional Contributor II

Any luck with this?  I'm trying to do something similar with a feature service.  I want to filter on current date.  The feature service is editable and syncable so it can be used in Collector.  As you noted you can't filter on current date in the web map layer properties.  I've tried setting a definition query in ArcMap when I publish the service as James Crandall suggested.  The service observes the definition query when it is published but it seems that it is ignored as the current date changes or any edits are made.  Did you find a work around?  Did a definition query in ArcMap work for you?

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Post here just in case anyone who may need it:

Try ArcGIS Online Assistant

You can see the JSON data of your web map, and you can change the layer definition and save back.

In the layer definition, define your own expression and save.

"layerDefinition": {

.....

     "definitionExpression": "CreationDate >=DATEADD(day,-1,convert(date,GETDATE()))"

......

}

USING THIS TOOL AT YOUR OWN RISK, AS IT COULD CORRUPT YOUR CONTENT. so I strongly suggest make a copy before you change anything.

0 Kudos
Andre
by
New Contributor II

Hi Simo,

I'm not familiar with JSON.  Where exactly do you put this Definition Expression?  Could you provide an example?

Where would I insert that expression in the following JSON:

{

  "layers": [
     {
       "0": {
            "id": 0,
            "layerDefinition": {
  

                 "drawingInfo": {
                       "renderer": {
                              "type": "simple",
                              "label": "",
                              "description": "",
                              "symbol": {
                              "angle": 0,
                              "xoffset": 0,
                              "yoffset": 12,
                              "type": "esriPMS",
                              "url": "737ec596-f3ab-4-b8f4-9c952cc048d6",
                              "imageData": "iVBORw0KGgoAAAANSUhEUgAAACYAAAAzCAYAAAD7JnqGAAAetc",
                               "contentType": "image/png",
                               "width": 27.999999999999996,
                               "height": 38
                           
}
                      
}
                   
}
               
}
           
}
,

Also, to take this idea of using arcgis online assistant one step further is there a way to query a date range to get a similar result?

Thanks for the help.

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Hi Andre,

something like the following will do the trick.

JSON is javascript, and the value for layerDefinition is a Javascript object.

To answer your last question, I am pretty sure you can query a date range. all you need to do is find out the MS SQL Server syntax for it. Something like "Date >= '2015/12/01' and Date <= '2015/12/08'" should work

{

  "layers": [

     {

       "0": {

            "id": 0,

            "layerDefinition": {

                       "definitionExpression": "CreationDate >=DATEADD(day,-1,convert(date,GETDATE()))"

                 "drawingInfo": {

                       "renderer": {

                            }

                       }

                    }

                }

            },

SimonJackson
Occasional Contributor III

Having trouble getting this to work with POrtal for ArcGIS.

My layer is from a hosted service via the ArcGIS Data Store.

The following does not seem to work on a datetime field called received.

Any ideas?

        "definitionExpression": "received >=DATEADD(day,-1,convert(date,GETDATE()))"

Have used this approach in the past fine on ArcGIS Online.

EDIT::

Realised the ArcGIS Data Store has postgresql under the hood, so tried this:

   "definitionExpression": "received >= NOW()-'1 day'::INTERVAL"

But still no luck.

NaomiBegg2
Occasional Contributor III

Has anyone found a better way of doing this yet?

I tried the editing the JSON in ArcGIS Online Assistant using the script that simo xu however this was not successful.

0 Kudos
NaomiBegg2
Occasional Contributor III

I've just found this!!

You can filter dates using In the last.