Attribute Rule: Generate a point in a new feature class

739
9
04-18-2025 09:58 AM
ZachBodenner
MVP Regular Contributor

Hi - it was brought to my attention that my post didn't go through correctly yesterday, so here's my second creack:

I want to write an attribute rule that will place a point in feature class B at the exact same location as one that is created in feature class A. I think this is fairly straightforward, but I must be missing something because I get an error that is simple 'Invalid function arguments.'  No further details. The expression itself evaluates fine.

var pf = Geometry($feature)
var t = $feature.AssetType



return {

    edit: [{

        "className": "epgdb.Parks.RecPts",
        "adds": [{
            "attributes": {
             "type": t
                        },
             geometry: pf
        }]
    }]
}

 

I'll flesh this out a little later, but I kind of just want to get it started. Any ideas for what is eluding me?

Happy mapping,
- Zach
0 Kudos
9 Replies
ChristopherCounsell
MVP Frequent Contributor

Was this meant to be a question instead of a blog post?

0 Kudos
ZachBodenner
MVP Regular Contributor

Good question! I guess I'm a little unclear of how we're expected to use this Arcade community. It seems like it should be a place for all things Arcade, but maybe not? Should all questions still be in some other product forum? I'd be happy to move the post if this isn't where it should go.

Happy mapping,
- Zach
0 Kudos
BlakeTerhune
MVP Frequent Contributor

There is a question section in the ArcGIS Arcade user group 😉

ArcGIS Arcade Questions - Esri Community

0 Kudos
AlfredBaldenweck
MVP Regular Contributor

Not sure what the issue is.

I copy-pasted your code directly into a test pair of points and it worked great (I did change the fields and the featureclass value, of course).

Caveat is that I tested in a file geodatabase, which of course raises the question of if you still have trouble if you test in one as well? (Also if that table actually exists/ you have edit permissions there?)

adds.gif

0 Kudos
JesseCloutier
Esri Community Manager

Sharing in case it's needed — MVPs do have the necessary permissions to move posts from one board to another: How to move a post. Our team is also happy to help if requested. @ZachBodenner, if you're intending this to be a question post rather than an informative blog article feel free to move this or let us know if you'd prefer we assist. 

Jesse Cloutier
Community Manager, Engagement & Content
0 Kudos
ZachBodenner
MVP Regular Contributor

Okay thanks everyone for replying to this and to helping me figure out how the community pages are set up. Anyway this definitely belongs in the Questions, and I had a chance to return to it. I don't know what I was doing wrong before, but I got the basic set up to work, generating a point in feature class B. I want to expand on that now and I'm looking for just a bit more guidance.

Here's the background and the attribute rule as it stands right now: I have a layer of park assets managed by Parks Maintenance staff, and a layer of points representing recreation opportunities managed by Parks Recreation staff that will be used in a public facing application. Sometimes but not always, assets are also recreation points (think Tennis Courts). A challenge I have right now is that the Assets call those features "Tennis Court" and the Recreation Points call those "Tennis". What I want to do is alleviate the need for these two groups to communicate when new points are added by running this auto-generate-point rule.

var pf = Geometry($feature)
var t = $feature.AssetType
var a = $feature.AssetID
return {
    edit: [{

        "className": "RecreationPoints_Backup",
        "adds": [{
            "attributes": {
             "RecType": t,
             "Name": a
                        },
             geometry: pf
        }]
    }]
}

If I leave this as is, Tennis Court would be written from Assets into Recreation which would then not be symbolized or display correctly because of the nomenclature mismatch. So my question is this: 

How do I use a dictionary of values present in the Parks Assets to then write a similar but not identical value into the Recreation points? It would be something like

var dict = {
    "Tennis Court": "Tennis", etc etc etc}

 but I am really unfamiliar with this function and how I would go about making sure the write-to feature class gets the correct value.

Happy mapping,
- Zach
0 Kudos
AlfredBaldenweck
MVP Regular Contributor

Well, I'm flummoxed because it is REALLY not liking me when I try to do this.

Should be a very straightforward process but it's giving me all sorts of errors about needing a string for the field, even though I'm feeding it a value from a text field and wrapping it in Text() to be certain.

After a lot of trial and error, it looks like the key is to use "DefaultValue()" (get() but for Arcade) or else it gets mad that you haven't accounted for literally every possible combination in your dictionary.

var pf = Geometry($feature)
var t = Text($feature.AssetType)
var a = $feature.AssetID

var typeDict ={"Tennis Court": "Tennis", "Swimming Pool" :"Pool"}

var neo = DefaultValue(typeDict, t, "")

return {
    edit: [{

        "className": "RecreationPoints_Backup",
        "adds": [{
            "attributes": {
             "RecType": neo,
             "Name": a
                        },
             geometry: pf
        }]
    }]
}

 

If you aren't already, I'd probably make sure they're in some kind of relationship. I set my rule to run by Inserts and Updates and I ended up with a lot of duplicates, so I should probably make either it just on Inserts OR use a relationship to do some validation to see if it already exists in the related table.

ZachBodenner
MVP Regular Contributor

Alfred, you're a rock star for keeping looking into this. That's a really good point about getting a bunch of duplicates - I think running it only on insert is the only thing that makes sense. 

The other thing I've learned since I last posted is that it seems like basically the whole point of a dictionary is to get the value out of?

 

var pf = Geometry($feature)
var t = $feature.AssetType
//var t = "Tennis Court"
var a = $feature.AssetID

var typeDict = {
    'Tennis Court': 'Tennis',
    'Basketball Court': 'Basketball',

    // etc
}
// Check to see if the dictionary (assetTypeDict) has the key (t). If it doesn't, end the expression now.
if (!HasKey(typeDict , t)) {return}

// The value populated into RecType is the 
var mappedType = typeDict [t]

return {
    edit: [{

        "className": "RecreationPoints_Backup",
        "adds": [{
            "attributes": {
             "RecType": typeDict [t],
             "Name": a
                        },
             geometry: pf
        }]
    }]
}

 

I guess HasKey seems like it's built for that, so I tried that and it works pretty well provided I just end the expression if there isn't an appropriate match (which is what I want; if the maintenance staff create a storage shed, for example, I don't need a recreational point for that).

Happy mapping,
- Zach
0 Kudos
AlfredBaldenweck
MVP Regular Contributor

Oh yeah, HasKey() would be good to escape the whole operation

0 Kudos