Hi All,
Think I'm just completely overlooking something here. I'm attempting to get the closest street to a point for an address and gathering the individual components of the name for the address point.
Here's what I'm attempting to use for the code. It was telling me that I needed another curly brace, checked them all, they all matched up. Now it says that the else is a reserved word on the second else on line 37. Any help is appreciated.
Lorinda
var fsn = $feature.FullStreetName;
var streetLayer = FeatureSetByName($datastore, "server.dbo.StreetCenterline");
var pre = $feature.PreDirection;
var sn = $feature.StreetName;
var st = $feature.StreetType;
var post = $feature.PostDirection;
var searchDistance = 150;
var streetIntersect = Intersects(streetLayer, Buffer($feature, searchDistance, "feet"));
var cnt = Count(streetIntersect);
var minDistance = Infinity;
if (cnt > 0) {
for (var street in streetIntersect) {
var dist = Distance(street, $feature, "feet");
if (dist < minDistance) {
var stparse = {
attributes: {
pre: ["streetLayer.PreDirection"],
sn: ["streetLayer.StreetName"],
st: ["streetLayer.StreetType"],
post: ["streetLayer.PostDirection"],
fsn: ["streetLayer.FullStreetName"],
minDistance: dist
}
}
} else {
var stparse = {
attributes: {
pre: "",
sn: "",
st: "",
post: "",
fsn: ""
}
}
}
} else {
// pass no features found within search distance, name remains null
var stparse = {
attributes: {
pre: "",
sn: "",
st: "",
post: "",
fsn: ""
}
}
}
}
return stparse;
You didn't close out the for loop before the else on line 37
Try this:
var fsn = $feature.FullStreetName;
var streetLayer = FeatureSetByName($datastore, "server.dbo.StreetCenterline");
var pre = $feature.PreDirection;
var sn = $feature.StreetName;
var st = $feature.StreetType;
var post = $feature.PostDirection;
var searchDistance = 150;
var streetIntersect = Intersects(streetLayer, Buffer($feature, searchDistance, "feet"));
var cnt = Count(streetIntersect);
var minDistance = Infinity;
if (cnt > 0) {
for (var street in streetIntersect) {
var dist = Distance(street, $feature, "feet");
if (dist < minDistance) {
var stparse = {
attributes: {
pre: ["streetLayer.PreDirection"],
sn: ["streetLayer.StreetName"],
st: ["streetLayer.StreetType"],
post: ["streetLayer.PostDirection"],
fsn: ["streetLayer.FullStreetName"],
minDistance: dist
}
}
} else {
var stparse = {
attributes: {
pre: "",
sn: "",
st: "",
post: "",
fsn: ""
}
}
}
}
} else {
// pass no features found within search distance, name remains null
var stparse = {
attributes: {
pre: "",
sn: "",
st: "",
post: "",
fsn: ""
}
}
}
return stparse;
That allowed it to valid, however, now it is complaining about "Undefined keyword is used in the dictionary return script. [attributes]" when I try to insert a new record. I've checked my column names from the StreetCenterline feature class - they are all spelled correctly. I did remove the 'minDistance: dist' line as that is not in the feature class that I'm adding data to.
I have tested the base part of this script with just one column being filled in and it worked. It seems to be the use of 'attributes: {list....} that is tripping me up. I am using the same column names in both my address point and street centerline feature classes. Would I be needing the "result" term in there at all?
Thanks,
Lorinda
Sorry, I did not read that post correctly and typed too soon.
I recently had the same problem. Arcade doesn't super like nested dictionaries the way we would do them in Python.
var dDict ={}
var t = "red"
var s = "apple"
var u = "delicious"
dDict[t] = {s : u}
return dDict
//Yields : {"red": {s:"delicious"}}
BUT this works instead.
var dDict ={}
var t = "red"
var s = "apple"
var u = "delicious"
dDict[t] = Dictionary(s, u)
return dDict
//Yields : {"red": {"apple":"delicious"}}
Try manually constructing the dictionary like that and see what you get.