Arcade Expressions for Attribute Rule to find angle of a polyline

733
2
Jump to solution
04-14-2021 02:39 PM
Labels (1)
AnnaPeters
New Contributor III

Hello,

 

I am trying to make an Attribute Rule in ArcGIS Pro to auto populate a Rotation field for a sanitary flow direction point intersecting with a sanitary main feature class. This way with using the rotation field I can set the symbology rotation to reflect which was the sanitary main is flowing. With the arcade expression below, I keep coming up with the error Arcade Error: Unexpected Null. Any idea on what I am doing wrong? The error is attached and the code is below. 

 

// Find the first intersecting line from the intersecting class
var lineClass = FeatureSetByName($datastore, "ssGravityMain", ["objectid"], true)
var line = First(Intersects(lineClass, $feature))

// If no feature was found, return the original value
if (line == null)
{
return $feature.ROTATION
}
// Buffer the point by a small amount to extract the segment
var search = Extent(Buffer($feature, .01, "feet"))
var segment = Clip(line, search)["paths"][0]

// Get angle of line using the start and end vertex
if(isempty($feature.ROTATION)) return Angle(segment[0], segment[-1])

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Regular Contributor

Looks like it should work...

The error is thrown at line 12, which is one of those (can't tell from your code):

var search = Extent(Buffer($feature, .01, "feet"))
var segment = Clip(line, search)["paths"][0]

Try these (separate or in combination):

var search = Extent(Buffer($feature, 0.1, "feet"))  // bigger buffer
var clip_geometry = Clip(Geometry(line), search)  // use Geometry(line)
// test if the clip was successfull and return null (or a specific failure value) if not
// this won't solve the underlying problem, but will stop the error
if(clip_geometry == null) {
  return null  // return -9999
}
var segment = clip_geometry.paths[0]  // .paths instead of ["paths"]

 Also:

// Instead of doing the IsEmpty check before returning, do it at the start of the script, so you can return early.
if(!IsEmpty($feature.ROTATION)) {
  return $feature.ROTATION
}
var lineClass = ...
// ...
return Angle(segment[0], segment[-1])

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Regular Contributor

Looks like it should work...

The error is thrown at line 12, which is one of those (can't tell from your code):

var search = Extent(Buffer($feature, .01, "feet"))
var segment = Clip(line, search)["paths"][0]

Try these (separate or in combination):

var search = Extent(Buffer($feature, 0.1, "feet"))  // bigger buffer
var clip_geometry = Clip(Geometry(line), search)  // use Geometry(line)
// test if the clip was successfull and return null (or a specific failure value) if not
// this won't solve the underlying problem, but will stop the error
if(clip_geometry == null) {
  return null  // return -9999
}
var segment = clip_geometry.paths[0]  // .paths instead of ["paths"]

 Also:

// Instead of doing the IsEmpty check before returning, do it at the start of the script, so you can return early.
if(!IsEmpty($feature.ROTATION)) {
  return $feature.ROTATION
}
var lineClass = ...
// ...
return Angle(segment[0], segment[-1])

 


Have a great day!
Johannes
AnnaPeters
New Contributor III

This worked perfectly! Either way worked for me. Thanks for all of your help. 

 

Anna

0 Kudos