Select to view content in your preferred language

Arcade: "all other values" symbology problem

370
2
10-21-2022 01:14 AM
JeffreyPacht
New Contributor

Hello,

I am using ArcGIS Pro 3.0. I am creating a Unique Values symbology using the Date attribute of a set of points. The date is listed under "Descriptio" on the attribute table. I am trying to capture a series of points in a date range from Jan 19 1945 to Feb 23 1945 in sets of 7-day intervals. Each week has its own symbol/color.

Based on this page: https://support.esri.com/en/technical-article/000017958

I used the following Arcade Code:

var revegDate = Date($feature.Descriptio)
if (revegDate >= Date(1945,0,19) && revegDate <= Date(1945,0,25)) {
return "01/19/1945 - 01/25/1945" }
else if (revegDate >= Date(1945,0,26) && revegDate <= Date(1945,1,01)) {
return "01/26/1945 - 02/01/1945" }
else if (revegDate >= Date(1945,1,02) && revegDate <= Date(1945,1,08)) {
return "02/02/1945 - 01/08/1945" }
else if (revegDate >= Date(1945,1,09) && revegDate <= Date(1945,1,15)) {
return "02/09/1945 - 02/15/1945" }
else if (revegDate >= Date(1945,1,16) && revegDate <= Date(1945,1,22)) {
return "02/16/1945 - 02/22/1945" }

The code works correctly except for one hiccup. Any points with a date equal to the first day of each set (1/19/1945, 1/26/1945, 02/03/1945, etc) is being symbolized under <all other values> instead of their correct symbol.

JeffreyPacht_0-1666340409460.png

Any idea what I'm doing wrong?

Thank you.

 

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

My guess: The time of Descriptio is 00:00:00, but Date(year, month, day) has a time according to your time zone (eg. 02:00:00 for CEST, UTC+2)

 

Don't trust the automatic conversion, do it yourself:

var d = Text($feature.Descriptio, "MM/DD/Y")
var s = Split(d, "/")
var revegDate = Date(s[2], s[0] - 1, s[1])

 

PS: If you want to change the periods, you're going to have a hard time. A more flexible approach would be something like this:

var start_date = Date(1945, 0, 19)
var period_length = 7
var period_num = 5

// convert the date
var s = Split($feature.TextField, "/")
var d = Date(s[2], s[0] - 1, s[1])

// calculate and return the period
for(var i = 0; i < period_num; i++) {
    var end_date = DateAdd(start_date, period_length - 1, "days")
    if(d >= start_date && d <= end_date) {
        return Text(start_date, "MM/DD/Y") + " - " + Text(end_date, "MM/DD/Y")
    }
    start_date = DateAdd(start_date, period_length, "days")
}

// date outside chosen periods
return "Other period"

Have a great day!
Johannes
GISGeekpro
New Contributor II

I think the internal needs to go like this:

e.g.

revegDate <= Date(1945, 0, 26) &&

revegDate > Date(1945, 0, 26)

0 Kudos