Select to view content in your preferred language

Creating a centroid Point Feature from a Polygon with attribute rules

184
2
Jump to solution
02-14-2025 01:09 AM
PatrickLösel
Occasional Contributor

Hello,
I am just starting my first attempts with attribute rules and I am still quite inexperienced with ArcGIS Arcade. I came across the following blog post and tried to recreate it for the automatic creation of a point feature when creating an area feature. However, when checking with the Verify button, I always get the message that there are bracket errors. However, when I try to reproduce my input in Notepad++, I don't understand where the bracket error is specifically.

var pointfeature = Centroid($Feature)

return {
        "edit": [
        {
        "className" : "point"
        "adds": [

            {
            "attributes":
                {"polygon_ID" : $feature.GlobalID
                },
            
            "geometry" : pointfeature
            }

                ]
        }
        ]
}

 

1 Solution

Accepted Solutions
HaydenWelch
MVP Regular Contributor

Edit: To avoid this in the future (I make these mistakes all the time) you can paste your arcade script into an editor like VSCode and set the language to JavaScript. It'll find syntax errors for you and even give you quick fix options!

 

You just missed a comma in your edits dictionary:

 

var pointfeature = Centroid($Feature)

return {
        "edit": [
            {
                "className" : "point", //Missed a comma here
                "adds": [

                    {
                        "attributes":
                        {
                            "polygon_ID" : $feature.GlobalID
                        },
                        "geometry" : pointfeature
                    }
                ]
            }
        ]
    }

 

 

View solution in original post

2 Replies
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Hi @PatrickLösel,

So the geometry needs to be a point feature, which you can look up in the documentation here. In terms of the code, it might be that there is an inherent syntax issue with part of the code reading as text and not script.

Try writing the code using the point feature that is mentioned and see if that does the trick.

HaydenWelch
MVP Regular Contributor

Edit: To avoid this in the future (I make these mistakes all the time) you can paste your arcade script into an editor like VSCode and set the language to JavaScript. It'll find syntax errors for you and even give you quick fix options!

 

You just missed a comma in your edits dictionary:

 

var pointfeature = Centroid($Feature)

return {
        "edit": [
            {
                "className" : "point", //Missed a comma here
                "adds": [

                    {
                        "attributes":
                        {
                            "polygon_ID" : $feature.GlobalID
                        },
                        "geometry" : pointfeature
                    }
                ]
            }
        ]
    }