Placing Lines Within Polygons Uniquely
I'll be honest, there might be a function to do this but I couldn't find it and it was only going to take a few minutes so let's take a look. I have a bunch of triangles for and XML file that need to be subdivided into areas that are defined by polygons. I need to make sure that the triangles are kept intact and that there are no duplicates. In my case it didn't need to be an exact science and I wasn't worried about the edges. My solution was to check each triangle against a polygon and if the first point of the triangle was within the polygon it would be flagged, or in this case the layer changed. I just banged it out and I may make changes but for now it does the trick.
print ('line_change_line_in_polygon.py modified 06:25 2023/11/07')# Change layer of line that starts within polygon.'''Author: Dennis Shimer dshimer@gmail.comLicense: cc-by-sa http://creativecommons.org/licenses/by-sa/3.0/'''Ws=PyVrWs()Line=PyVrLine()BoundingLine=PyVrLine()Gui=PyVrGui()CheckLayer=600NewLayer=1001PointsFound=0WsNum=Ws.Aws()PromBox = VrPromBox ('Check lines in Polygon.', 30, 1)PromBox.AddInt ('Layer to check', CheckLayer, 1, 32000)PromBox.AddInt ('Change layer to', NewLayer, 1, 32000)if (PromBox.Display(0) == 0):CheckLayer=PromBox.GetIntByPrompt('Layer to check')NewLayer=PromBox.GetIntByPrompt('Change layer to')BoundingLine.Id()print (CheckLayer,BoundingLine.GetLayer())Gui.ProgInit('Lines',Ws.GetLineCount(WsNum))for EntNum in range ( Ws.GetLineCount(WsNum)):Gui.ProgSet(EntNum)if CheckLayer == Ws.GetLineLayer(WsNum,EntNum):Line.Load (WsNum, EntNum)X,Y,Z=Line.GetPoint(0)if BoundingLine.IsPointInside (X,Y):# print (X,Y,Z)PointsFound=PointsFound+1Line.SetLayer(NewLayer)Line.ReRec(1)# Line.Plot()Gui.ProgReset()print (PointsFound)