The Proper() Arcade function is a handy way to format street names that are stored in all caps. But it doesn't deal with ordinals correctly; e.g., returns "16Th" rather than "16th". There are a few different ways to handle this in Python but I don't know how to do it with Arcade. Any ideas? Thanks!
Solved! Go to Solution.
Ah! I figured it out. When you copied my expression into the playground, you unwittingly, but correctly, added braces around the for loop. I failed to notice previously that every label was showing only the last word of the name; I was only paying attention to the Mac names. After adding the braces, many more street names magically popped into the map! Thanks!
For posterity, here's the corrected expression:
if (!IsEmpty($feature.STREET)) {
var words = split(upper($feature.STREET), " ")
var Mac = ["MACCUMBER", "MACKAY", "MACKENZIE", "MACMILLAN", "MACRAE"]
var dir = proper(DomainName($feature, 'DIR'))
var street = ""
var type = proper(DomainName($feature, 'TYPE'))
for (var i in words) {
var isMac = indexof(Mac, words[i]) > -1
if (left(words[i], 2) == "MC") {
street += upper(words[i][0]) + lower(words[i][1]) + upper(words[i][2]) + lower(right(words[i], count(words[i]) - 3)) + " ";
} else if (isMac) {
street += upper(words[i][0]) + lower(words[i][1]) + lower(words[i][2]) + upper(words[i][3]) + lower(right(words[i], count(words[i]) - 4)) + " ";
} else {
street += iif(IsNan(number(words[i][0])), proper(words[i]), lower(words[i])) + " ";
}
}
return concatenate([dir, street, type]," ");
} else {
return "";
}
We have hyphenated street names (for example "SMITH-ENKE"). Thank you, @CiaraRowland-Simms and @JeffThomasILM, your scripts have helped me a lot! I've worked out handling the hyphenated streets. I hope this helps out others.
var dir = $feature.PRD + " "
var type = Proper($feature.STS)
var post = " " + $feature.POD
var stn = $feature.STN
if (!IsEmpty(stn)) {
var words = Split(stn, " ")
var hyphen = Split(stn, "-")
var street = ""
if (hyphen[0] != stn) {
street += Proper(hyphen[0]) + "-" + Proper(hyphen[1]) + " ";
return concatenate([dir, street, type, post])
} else {
for (var i in words)
if (Left(words[i], 2) == "MC") {
street += upper(words[i][0]) + lower(words[i][1]) + upper(words[i][2]) + lower(right(words[i], count(words[i]) - 3)) + " ";
} else {
street += iif(IsNan(number(words[i][0])), proper(words[i]), lower(words[i])) + " ";
}
return concatenate([dir, street, type, post])
}
} else { return "";
}