Can't go into detail about what these features actually are but I will just refer to them as the green line and the black line. The black lines are not able to ever overlap the blue polygons. Black lines have a specific orientation depending on which side the closest green line is.
What I'm trying to do is create a script which would be able to determine if the closest green line is either right or left to the black line, then determine if the black line is oriented correctly or not based on the rules I drew out within the attached image. If it isn't then it would flip the black line.
I've used the FeatureVerticesToPoints_management tool and SplitLine_management tool to split both the polylines into individual parts and retrieve midpoint X and Y coordinates as well as individual vertex X and Y coordinates of both lines.
I've been using the formula (Bx - Ax) * (Cy - Ay) - (By - Ay) * (Cx - Ax) where A and B are line vertices of the green line and C is the midpoint vertex of the black line. This has created a positive or negative value signifying which side point C is on compared to the line but I do not know how to setup rules for how the black line should be orientated afterwards. I believe the answer lies within checking the black line's azimuth.
My original idea was that using that formula I could determine which side the black line was on, then check if the azimuth of the black line is within 180deg of the the azimuth of the green line, and if it wasn't, it would flip the black line. But since the green line can be orientated in it's opposite direction, and be acceptable, the 180deg rule turns into a 360deg rule and the black line can then go any direction it wants.
I've been calculating the azimuth of each line using:
def CalculaAzimuth(linea): if (hasattr(linea,'type') and linea.type == 'polyline'): xf = linea.firstPoint.X yf = linea.firstPoint.Y xl = linea.lastPoint.X yl = linea.lastPoint.Y dX = xl - xf dY = yl - yf PI = math.pi Azimuth = 0 #Default case, dX = 0 and dY >= 0 if dX > 0: Azimuth = 90 - math.atan( dY / dX ) * 180 / PI elif dX < 0: Azimuth = 270 - math.atan( dY / dX )* 180 / PI elif dY < 0: Azimuth = 180 return Azimuth else: return False