Referencing the number of occurrences for geographic adornment

I have a data set which has entities that (among other things) have a location. I am interested in counting the number of occurrences per location and put them on a map that I have created using a geographic adornment. To that end I created one note for each location and put the latitude and longitude into each of them. They nicely display on the map.

What I now want to do is to put the number of occurrences into the note on the geographic adornment?

I know I can do that via a display expression using some code magic, but In that last part I do not know how to proceed. Say my notes are in a container names “Notes” and the variable that gives the location is in “City”. How would I count the number of occurrences for each location when each note on the geographic adornment is named after a location?

I think that I should best do this via a rule which first calculates that count and puts it into a Display Attribute in each note. Then I could easily reference that for the display expression.

Any ideas how to proceed? I’d be most grateful for any pointers!

Let’s suppose that we will regard all notes with the same value of $City as being in the same place. That’s an awkward assumption — for Los Angeles or Ciudad de Mexico — that covers a lot of ground. But never mind.

We could get the count of all notes in Chicago fairly easily.

count_if(children(/Notes),$City=="Chicago")

We could get a count of all the notes in this same city as this note in a similar way:

count_if(children(/Notes),$City==$City(that))

(Inside a count_if(), this is the note we are proposing to count and that is the note formerly bound to this.)

You can do this in a DisplayExpression for a small document, but if you have lots of notes, this becomes a lot of work since each note is compared to every other note. So, in the long run, you probably want to do the work in an edict and save the count in an attribute, and just display that attribute in the DisplayExpression.

Many thanks for the help, but I don’t get it to work.
If I have a note on the geographic adornment that has the name of “Hannover” and I have three entities among the 156 notes in the container Notes which have $City as “Hannover”, the following should - I think - give me that number:

The number of entities in ^value($Name)^ is ^value(count_if(children(/Notes), $City=="Hannover"))^.

But in Preview I get “The number of entities in Hannover is .”, so it doesn’t even give me a result, hence something must be quite wrong. Note that the note in which I write this (in $Text) does not have a $City displayed attribute, but that I want to refer to $City in the notes in the container Notes. Could that be the reason? Slightly puzzled… Thanks for any help!

Sorry – count_if is coming in the future, but it’s not released. You’ll need to use

collect_if(children(/Notes),$City=="Hannover").count

for now.

Ah - that explains why I couldn’t find it on aTbRef!
Now I get

The number of entities in Hannover is 0.

So something is still missing; I can construct an agent collecting what I want:

inside(Notes) & $City == "Hannover";

(it correctly gives me the three entities) so I need to find out where the error lies. Any ideas for help appreciated!

I managed to solve the problem by using sum_if:

The number of entities in ^value($Name)^ is ^value(sum_if(children(/Notes), $City=="Hannover", 1))^.

No idea why collect_if and .count didn’t do it for me, but happy to have a solution - thanks for your help!

Oh – my fault. Collect_if needs three arguments — the notes to be considered, the test to be applied, and (slapping head) the thing you want to collect.

collect_if(children(/Notes),$City=="Hannover",$Path).count

But sum_if is better anyway.

1 Like