Select to view content in your preferred language

Arcade Expression for Distance Calculation

1141
2
Jump to solution
09-14-2023 01:55 AM
HarishKV
Regular Contributor
i have two layers one is High Tide Line and another one is Land Parcel. Land parcel is a polygon feature class and High tide line is a line feature class. I want to add the straight line distance at nearest vertex of the High Tide line layer to the centroid of the land parcel layer feature i am creating. I had written a Arcade Script and its not working for me. Can anyone help?. Thanks in Advance.
 
var landParcelLayer = FeatureSetByName($map, "Land Parcel"); // Replace with the actual name of your Land Parcel layer
var highTideLayer = FeatureSetByName($map, "High Tide Line HTL"); // Replace with the actual name of your High Tide Line layer
var attributeName = 'Dist_HTL'; // Replace with the desired attribute name

var editingFeature = $feature;
var landParcelGeometry = Geometry(editingFeature);

var closestDistance = 999999999; // Set a large initial value

for (var vertex in highTideLayer) {
    var vertexGeometry = Geometry(vertex);
    var distance = Distance(vertexGeometry, Centroid(landParcelGeometry));
    if (distance < closestDistance) {
        closestDistance = distance;
    }
}

if (closestDistance < 999999999) {
    editingFeature[attributeName] = closestDistance;
    return editingFeature;
} else {
    return 'No Nearby High Tide Line Features';
}
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
HarishKV
Regular Contributor

Hi Ken,

Thanks for connecting. I had revised script and solved the issue. Modified Script as follows : 

var htl_lyr = FeatureSetByName($map, 'High Tide Line');
var editingFeature = $feature;
var editingGeometry = Centroid(editingFeature);
var closestDistance = 999999999; // Set a large initial value

for (var htl_feature in htl_lyr) {
    var dist = Distance(htl_feature, editingFeature, 'meter');
    if (dist < closestDistance) {
        closestDistance = dist;
    }
}

var roundedDistance = Round(closestDistance, 2); // Round to 2 decimal places

roundedDistance; // This will return the rounded closest distance in meters

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

Are you trying to calculate the value for the field 'Dist_HTL'? If so, is it a numeric field or text field?

HarishKV
Regular Contributor

Hi Ken,

Thanks for connecting. I had revised script and solved the issue. Modified Script as follows : 

var htl_lyr = FeatureSetByName($map, 'High Tide Line');
var editingFeature = $feature;
var editingGeometry = Centroid(editingFeature);
var closestDistance = 999999999; // Set a large initial value

for (var htl_feature in htl_lyr) {
    var dist = Distance(htl_feature, editingFeature, 'meter');
    if (dist < closestDistance) {
        closestDistance = dist;
    }
}

var roundedDistance = Round(closestDistance, 2); // Round to 2 decimal places

roundedDistance; // This will return the rounded closest distance in meters
0 Kudos