It was a little bit more complicate than that, but not much. This is a start. It produces clockwise rings (lines) for each road in [OneWays] joined with its connectors in [Connectors]. OPTIONS CoordSys("OneWays" AS COMPONENT) ; SELECT [road_index], --[Joined], CASE WHEN IsRing([Branch]) THEN ReverseLine(ConvertToLine( Normalize(ConvertToArea([Branch])) -- Normalize() -> area directed anticlockwise )) ELSE NULL -- check data END AS [Clockwise ring] FROM (SELECT [road_index], Normalize(AllBranches([ID])) AS [Joined] -- Normalize() is required to join contiguous branches -- It does not preserve or enforce line direction -- Here we don't mind since we are about to correct it FROM (SELECT [ID], [road_index] FROM [OneWays] UNION SELECT [ID], [road_index] FROM [Connectors] ) GROUP BY [road_index] ) SPLIT BY Branches([Joined]) AS [Branch] -- To subdivide any self-intersecting joined lines -- into separate rings -- (There is just one in the example data -- where a road crosses a line in Roads having atr = 512) ; From here there are at least two ways to go. You can either join each line in [OneWays] and [Connectors] to its containing [Clockwise ring] in the result, split the [Clockwise ring] with the ends of the contained line using IntersectLine() (there's a slightly tricky aspect to that) then check whether their ends match, reversing the contained line if necessary. (IntersectLine() does not disrupt line direction.) That's OK though fiddly. Or, perhaps, you could just Explode each [Clockwise ring] then use each segment as it is (restoring attributes, perhaps via centroids, then sorting back into the two drawings). That looks simpler but could be more fiddly overall. Attachments: Draw clockwise rings.txt
|