Select to view content in your preferred language

Calculate length of line intersecting polygon

152
1
Jump to solution
a week ago
Labels (1)
JChilders
New Contributor

Hey y'all,

I am trying to calculate the length of intersecting trail that runs through a feature using arcade so that a popup can be calculated on the fly. The value I'm returning seems incorrect and I'm struggling to fix it. For example, a feature that has ~1.1 miles of trail intersecting returns a value of 3.3 miles. The code may be returning the entire length of the trail, regardless of how much intersects the feature. If this is the case, how can I calculate the length of the trail that actually intersects the feature?

// Access the Trails layer by name
var trailsLayer = FeatureSetByName($map, "Trails");

// Find intersecting trails within the selected feature
var intersectingTrails = Intersects(trailsLayer, $feature);

//Calculate length of intersecting trails
var totalLength = Length(intersectingTrails, "miles")

// Return the total length in the desired units (e.g., meters or miles)
if (totalLength == 0) {
    return "There are no public trails on this property.";
} else {
    return Round(totalLength, 2) + " miles";
}

 Thanks in advance for your help!

0 Kudos
1 Solution

Accepted Solutions
JChilders
New Contributor

Changing Length() to LengthGeodetic() solved the issue. My guess is that the two datasets are in different coordinate systems and that was causing the error. 

View solution in original post

0 Kudos
1 Reply
JChilders
New Contributor

Changing Length() to LengthGeodetic() solved the issue. My guess is that the two datasets are in different coordinate systems and that was causing the error. 

0 Kudos