Hi,
I am having trouble with the arcade script below being used in an attribute rule that is designed to adjust the building footprints using the code below. It validates, but when it runs, the vertices do not change and I am not sure how to return the modified geometry.
The script below primarily works with rectilinear polygons, and it will be modified later to check and update each segment so that all segments that it enforces collinear and parallel lines.
function GetThirdVertex(NPoint, a, m, d){
var np = Dictionary( NPoint )
//console( np )
// Solve for possible x2 and y2 coordinates
var deltaX = d / sqrt(1 + pow(m,2))
var deltaY = m * deltaX
// Compute the two possible vertices
if( a > 0 && a < 180 ){
np.x = np.x + deltaX
np.y = np.y + deltaY
}
else{
np.x = np.x - deltaX
np.y = np.y - deltaY
}
//console( np )
// Return an array containing the two possible vertices
return Point( np )
}
// Function to get unique slopes in the array of points
function ValidateSlopes( InputArray ){
var Slopes = []
for( var i=0; i<Count(InputArray)-1; i++ ){
var A = InputArray[i]
var B = InputArray[i+1]
var m = Round((A.x-B.x)/(A.y-B.y),2)
Push( Slopes, m )
}
var ConvertSlopes = {}
if( Count( Slopes ) % 2==0 ){
var A = Null; var B = Null
for( var i=0; i < Count(Slopes) - 1; i++ ){
if( IsEmpty( A ) && IsEmpty( B ) ){ A = Slopes[i]; B=Slopes[i+1] }
else{
if( A == Slopes[i] && B != Slopes[i+1] ){ ConvertSlopes[ Text( Slopes[i+1] ) ] = B }
else if( A != Slopes[i] && B == Slopes[i+1] ){ ConvertSlopes[ Text( Slopes[i] ) ] = A }
}
}
}
return ConvertSlopes
}
function Slope(A,B){ return Round( (A.x-B.x)/(A.y-B.y), 2 ) }
var Geo = Geometry( $feature )
var SR = Geo.spatialReference
var NewRings = []
var Rings = Geo.Rings
for( var R in Rings ){
var Ring = Array(Rings[ R ])
var VSlopes = ValidateSlopes(Ring)
var NewRing = [Ring[0],Ring[0]]
for (var i = 0; i < Count(Ring) - 1; i++) {
var p1 = Ring[i]
var m = Slope( Ring[i], Ring[i+1] )
if( HasKey( VSlopes, Text(m) ) ){ m = Text(m); m = VSlopes[m] }
var A = Angle( Ring[0],Ring[1] )
var d = Round( Distance( Ring[i],Ring[i+1] ), 1 )
var NewPnt = GetThirdVertex( p1, A, m, d )
Insert( NewRing , i+1, NewPnt )
}
Push( NewRings , NewRing )
}
Rings = NewRings
// Output adjusted coordinates
var NewGeom = {
'rings': Rings,
'hasM': False,
'hasZ': False,
'spatialReference': SR
}
return Geometry( NewGeom )
I have tried several things to modify the existing geometry but still no luck. I did it before but now I cannot seem to remember how exactly I did it.