writeShapePoints(mcMesh, fullGrpName, nodeChains, outputDirectory, offsetX, offsetY)
-def fitShapePointsToMesh(freeBorderShapefile, shapefileToAdjust):
+def fitShapePointsToMesh(freeBorderShapefile, shapefileToAdjust, splitFreeBorder=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.
+ 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
+ """
print(" === fitShapePointsToMesh", freeBorderShapefile, shapefileToAdjust)
# --- find domain freeBorder: bounding box englobing all others
+ # TODO: This may not be always the case, when there is not a single domain with holes, but several non connected domains.
fb = shapefile.Reader(freeBorderShapefile)
fbShapes = fb.shapes()
if (bb[0] < maxbbox[0] and bb[1] < maxbbox[1] and bb[2] > maxbbox[2] and bb[3] > maxbbox[3]):
maxbbox = bb
outerBboxIndex = i
- fbs = fbShapes[outerBboxIndex]
+ fbs = fbShapes[outerBboxIndex] # the domain free border shape
# --- find the intersections of the shapefile to adjust and the domain free border:
# the closests points (two pairs of points)
w.record(chainName + '_1')
w.close()
- # write the free border splited in two polylines (cut by the adjusted shapefile)
+ if splitFreeBorder:
+ # write the free border split in two polylines (cut by the adjusted shapefile)
- a = os.path.splitext(freeBorderShapefile)
- freeBorderSplit = a[0] + '_split' + a[1]
- chainName = os.path.basename(a[0])
+ a = os.path.splitext(freeBorderShapefile)
+ freeBorderSplit = a[0] + '_split' + a[1]
+ chainName = os.path.basename(a[0])
- w = shapefile.Writer(freeBorderSplit)
- w.shapeType = 3
- w.field('name', 'C')
+ w = shapefile.Writer(freeBorderSplit)
+ w.shapeType = 3
+ w.field('name', 'C')
- if (ifb1 > ifb2):
- i = ifb1; ifb1 = ifb2; ifb2 = i
+ if (ifb1 > ifb2):
+ i = ifb1; ifb1 = ifb2; ifb2 = i
- chaincoords = []
- for i in range(ifb1, ifb2+1):
- chaincoords.append(fbs.points[i])
- w.line([chaincoords])
- w.record(chainName + '_0')
+ chaincoords = []
+ for i in range(ifb1, ifb2+1):
+ chaincoords.append(fbs.points[i])
+ w.line([chaincoords])
+ w.record(chainName + '_0')
- chaincoords = []
- for i in range(ifb2, len(fbs.points)):
- chaincoords.append(fbs.points[i])
- for i in range(ifb1+1):
- chaincoords.append(fbs.points[i])
- w.line([chaincoords])
- w.record(chainName + '_1')
- w.close()
+ chaincoords = []
+ for i in range(ifb2, len(fbs.points)):
+ chaincoords.append(fbs.points[i])
+ for i in range(ifb1+1):
+ chaincoords.append(fbs.points[i])
+ w.line([chaincoords])
+ w.record(chainName + '_1')
+ w.close()