writeShapePoints(mcMesh, fullGrpName, nodeChains, outputDirectory, offsetX, offsetY)
-def fitShapePointsToMesh(freeBorderShapefile, shapefileToAdjust, splitFreeBorder=True):
+def fitShapePointsToMesh(freeBorderShapefile, shapefileToAdjust, splitFreeBorder=True, splitShapeAdjusted=True):
"""
shapeFileToAdjust must be a closed line or polygon crossing freeBorderShapefile in 2 points.
- Find in shapeFileToAdjust and in freeBorderShapefile the two closest corresponding points and move the points in shapeFileToAdjust to correspond to the points found in freeBorderShapefile. Split shapeFileToAdjust in two parts (inside or outside freeBorder). If requested, split freeBorderShapefile in two parts.
+ Find in shapeFileToAdjust and in freeBorderShapefile the two closest corresponding points and move the points in shapeFileToAdjust to correspond to the points found in freeBorderShapefile. Split shapeFileToAdjust in two parts (inside or outside freeBorder). If requested, split freeBorderShapefile in two parts. Same for shapeFileToAdjust.
parameters:
freeBorderShapefile: a set of free border lines, as generated by the functions freeBordersGroup and exploreEdgeGroups.
shapefileToAdjust: a closed line or polygon, supposed to be drawn in qgis to pass as close as possible to the points to be connected, on the free border.
splitFreeBorder: boolean default True
+ splitShapeAdjusted: boolean default True
"""
print(" === fitShapePointsToMesh", freeBorderShapefile, shapefileToAdjust)
shapes = sf.shapes()
sfta = sf.shape(0)
pdist =[]
+ x0 = -1.e30
+ y0 = -1.e30
for i,p in enumerate(sfta.points):
+ d = math.sqrt((x0-p[0])*(x0-p[0]) + (y0-p[1])*(y0-p[1]))
+ x0 = p[0]
+ y0 = p[1]
+ if d < 1.e-5:
+ continue # do not take into account superposed points in shape to adjust
dmin = 1.e30
jmin = -1
for j,pfb in enumerate(fbs.points):
else:
ifb1 = pdist[1][1]
ifb2 = pdist[0][1]
+ print("i1, i2, len(sfta.points)", i1, i2, len(sfta.points))
+ print("ifb1, ifb2, len(fbs.points)", ifb1, ifb2, len(fbs.points))
# --- write the adusted shapefile: free border closest points replaced with corresponding points
# on the free border. two polylines, one inside the domain, one outside
w.shapeType = 3
w.field('name', 'C')
- chaincoords = []
- chaincoords.append(fbs.points[ifb1])
- for i in range(i1+1, i2):
- chaincoords.append(sfta.points[i])
- chaincoords.append(fbs.points[ifb2])
- w.line([chaincoords])
- w.record(chainName + '_0')
-
- chaincoords = []
- chaincoords.append(fbs.points[ifb2])
- if i2+1 < len(sfta.points):
- for i in range(i2+1, len(sfta.points)):
+ if splitShapeAdjusted:
+ chaincoords = []
+ chaincoords.append(fbs.points[ifb1])
+ for i in range(i1+1, i2):
+ chaincoords.append(sfta.points[i])
+ chaincoords.append(fbs.points[ifb2])
+ w.line([chaincoords])
+ w.record(chainName + '_0')
+
+ chaincoords = []
+ chaincoords.append(fbs.points[ifb2])
+ if i2+1 < len(sfta.points):
+ for i in range(i2+1, len(sfta.points)):
+ chaincoords.append(sfta.points[i])
+ for i in range(i1):
chaincoords.append(sfta.points[i])
- for i in range(i1):
- chaincoords.append(sfta.points[i])
- chaincoords.append(fbs.points[ifb1])
- w.line([chaincoords])
- w.record(chainName + '_1')
+ chaincoords.append(fbs.points[ifb1])
+ w.line([chaincoords])
+ w.record(chainName + '_1')
+ else:
+ chaincoords = []
+ chaincoords.append(fbs.points[ifb1])
+ for i in range(i1+1, i2):
+ chaincoords.append(sfta.points[i])
+ chaincoords.append(fbs.points[ifb2])
+ if i2+1 < len(sfta.points):
+ for i in range(i2+1, len(sfta.points)):
+ chaincoords.append(sfta.points[i])
+ for i in range(i1):
+ chaincoords.append(sfta.points[i])
+ w.line([chaincoords])
+ w.record(chainName)
+
w.close()
if splitFreeBorder: