Select to view content in your preferred language

Use Attribute Rules to create a buffer around a line in Pro

2154
8
01-19-2023 12:31 AM
AndrewReynoldsDevon
Regular Contributor

I need to use attribute rules to create a buffer around a line when a new feature is created.

I need some code that allows me to specify the size of the buffer too in either an area or % terms

0 Kudos
8 Replies
JohannesLindner
MVP Frequent Contributor

The most basic form:

// Calculation attribute rule on the line fc
// field: empty
// triggers: insert
// exclude from application evaluation

var buffer_polygon = Buffer($feature, 10, "meters")
return {
    edit: [{
        className: "NameOfThePolygonFC",
        adds: [{geometry: buffer_polygon}]
    }]
}

 

This makes use of the Attribute rule dictionary keywords—ArcGIS Pro | Documentation to edit another feature class.

 

specify the size of the buffer too in either an area or % terms

The "normal" way to define a buffer is by buffer distance ("10 meters on either side of this feature"). What do you mean with "area" and "percent"?


Have a great day!
Johannes
0 Kudos
AndrewReynoldsDevon
Regular Contributor

Hi,

I'm going to create a 5m buffer around the line feature so have updated the code below to change from polygon to line in 3 places in that correct?

When I've created attribute rules before I've specified a field but what would I select on this occasionbuffer.JPG

 

 

var buffer_line = Buffer($feature, 5, "meters")
return {
    edit: [{
        className: "NameOfTheLineFC",
        adds: [{geometry: buffer_line}]
    }]
}

 

 

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

The buffer is a polygon, so you have to write it into a polygon feature class (Line 4).

Leave the field empty.

Just so we talk about the same thing: The rule will take your new line, create a 5 meter buffer around it and write that buffer into a polygon feature class. So you will have the line feature class with the line features and a polygon feature class with the buffers. Is that what you're trying to do?


Have a great day!
Johannes
0 Kudos
AndrewReynoldsDevon
Regular Contributor

I selected the shape field with the code below & I get an error after I create a feature

buffer error.JPG

var buffer_line = Buffer($feature, 5, "meters")
return {
    edit: [{
        className: "HWDataCollectionLines",
        adds: [{geometry: buffer_line}]
    }]
}
0 Kudos
JohannesLindner
MVP Frequent Contributor

Yes, that is expected. You told the rule that you want to calculate the feature's geometry, but then you did not return a geometry. Leave the field empty.


Have a great day!
Johannes
0 Kudos
AndrewReynoldsDevon
Regular Contributor

can't save.JPGI tried to create a rule without selecting the field but it wouldn't save the rule so I selected 'Shape'

The code below is a copy of your original - I've changed the distance to 5m & have set the polygon fc to Highways.HIGHWAYMGR.HWDataCollectionPol  & HWDataCollectionPoly which is an existing Polygon FC. but the application won't save the new rule?

 

 

 

 

 

var buffer_polygon = Buffer($feature, 5, "meters")
return {
    edit: [{
        className: "Highways.HIGHWAYMGR.HWDataCollectionPoly",
        adds: [{geometry: buffer_polygon}]
    }]
}

 

 

 

 

 

buffer wizard.JPG

0 Kudos
JohannesLindner
MVP Frequent Contributor

If you hover over the red square on the left, it will tell you what's wrong.

In this case, it will probably tell you that you have to check the "Exclude from application evaluation" checkbox.


Have a great day!
Johannes
0 Kudos
AndrewReynoldsDevon
Regular Contributor

See the error below - there is no field selected so it won't let me save it. 

I was reading this article & they just use a field called 'Field' to create a buffered polygon so if I have to choose a field does it matter which from the list above? There are 6 current fields to choose from

https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/advanced-gdb-attribute-rules-ed...

red error.JPG

Going back to the % buffer - the line feature is being created with polygon's underneath so I need to 'buffer the line to establish which polygon say 80% falls within' is that possible using attribute rules & if so what would the code look like?

 

0 Kudos