Select to view content in your preferred language

Update Line Z Values

185
3
Jump to solution
07-12-2024 05:40 AM
Justin_CLT
New Contributor

I am using the Utility Network and need a rule to change the Z value of each vertex in a line depending on the lifecycle status. I already wrote a rule for devices and it is working, but nothing I've tried for the lines is working. I am including the expression used for point features (devices). Could someone help with how to adapt this for line features?

 

// This rule updates the Z value of features based on the lifecycle status

 

var lcs = $feature["lifecyclestatus"];

 

// Create a copy of the feature's geometry

var newGeom = Geometry($feature);

var newZ;

 

// Update the Z value based on lifecycle status

// Domain values: proposed = 1, in service = 8, out of service = 256, abandoned = 32

if (lcs == 1) {

    newZ = 1;

} else if (lcs == 8 {

    newZ = 0;

} else if (lcs == 256) {

    newZ = -1;

} else if (lcs == 32) {

    newZ = -2;

} else {

    newZ = 0;

}

 

// Create a new geometry with updated Z value

var updatedGeom = Point({

    "x": newGeom.x,

    "y": newGeom.y,

    "z": newZ,

    "spatialReference": newGeom.spatialReference

});

 

// Return the updated geometry

return updatedGeom;

0 Kudos
1 Solution

Accepted Solutions
Justin_CLT
New Contributor

I got it to work for lines using the following expression:

 

// This rule updates the Z value of linear features based on the lifecycle status
var lcs = $feature["lifecyclestatus"];

// Create a copy of the feature's geometry
var newGeom = Geometry($feature);
var newPaths = [];

// Update the Z value based on lifecycle status
// Domain values: proposed = 1, in service = 8, out of service = 256, abandoned = 32
var newZ;
if (lcs == 1) {
newZ = 5;
} else if (lcs == 8 {
newZ = 0;
} else if (lcs == 256) {
newZ = -5;
} else if (lcs == 32) {
newZ = -10;
} else {
newZ = 0;
}

// Iterate through each part of the polyline
for (var i = 0; i < Count(newGeom.paths); i++) {
var path = newGeom.paths[i];
var newPath = [];
// Iterate through each vertex in the part
for (var v = 0; v < Count(path); v++) {
var point = path[v];
// Create a new point with updated Z value and original X and Y coordinates
var newPoint = [point.x, point.y, newZ];
// Add the new point to the new path
Push(newPath, newPoint);
}
// Add the new path to the new paths array
Push(newPaths, newPath);
}

// Create a new polyline with updated Z values
var updatedGeom = Polyline({
"paths": newPaths,
"spatialReference": newGeom.spatialReference
});

// Return the updated geometry
return updatedGeom;

View solution in original post

0 Kudos
3 Replies
MikeMillerGIS
Esri Frequent Contributor

Geometry is immutable, so convert to dictionary

var p = Polyline(
  {
    paths: [
      [
        [-97.06138, 32.837, 0],
        [-97.06133, 32.836, 0],
        [-97.06124, 32.834, 0],
        [-97.06127, 32.832, 0]
      ]
    ],
    hasZ: true,
    spatialReference: { wkid: 3857 }
  }
);
console(p);

var p_z = Dictionary(p)
for(var i in p_z['paths']){
  for(var j in p_z['paths'][i]){

    p_z['paths'][i][j][2] = 50
  }
}
return Polyline(p_z)
0 Kudos
Justin_CLT
New Contributor

I got it to work for lines using the following expression:

 

// This rule updates the Z value of linear features based on the lifecycle status
var lcs = $feature["lifecyclestatus"];

// Create a copy of the feature's geometry
var newGeom = Geometry($feature);
var newPaths = [];

// Update the Z value based on lifecycle status
// Domain values: proposed = 1, in service = 8, out of service = 256, abandoned = 32
var newZ;
if (lcs == 1) {
newZ = 5;
} else if (lcs == 8 {
newZ = 0;
} else if (lcs == 256) {
newZ = -5;
} else if (lcs == 32) {
newZ = -10;
} else {
newZ = 0;
}

// Iterate through each part of the polyline
for (var i = 0; i < Count(newGeom.paths); i++) {
var path = newGeom.paths[i];
var newPath = [];
// Iterate through each vertex in the part
for (var v = 0; v < Count(path); v++) {
var point = path[v];
// Create a new point with updated Z value and original X and Y coordinates
var newPoint = [point.x, point.y, newZ];
// Add the new point to the new path
Push(newPath, newPoint);
}
// Add the new path to the new paths array
Push(newPaths, newPath);
}

// Create a new polyline with updated Z values
var updatedGeom = Polyline({
"paths": newPaths,
"spatialReference": newGeom.spatialReference
});

// Return the updated geometry
return updatedGeom;

0 Kudos
Bud
by
Honored Contributor
0 Kudos