def fitShapePointsToMesh(freeBorderShapefile, shapefileToAdjust):
print(" === fitShapePointsToMesh", freeBorderShapefile, shapefileToAdjust)
+
+ # --- find domain freeBorder: bounding box englobing all others
+
fb = shapefile.Reader(freeBorderShapefile)
fbShapes = fb.shapes()
maxbbox=[1.e30, 1.e30, -1.e30, -1.e30]
outerBboxIndex = i
fbs = fbShapes[outerBboxIndex]
+ # --- find the intersections of the shapefile to adjust and the domain free border:
+ # the closests points (two pairs of points)
+
sf = shapefile.Reader(shapefileToAdjust)
shapes = sf.shapes()
sfta = sf.shape(0)
ifb1 = pdist[1][1]
ifb2 = pdist[0][1]
+ # --- write the adusted shapefile: free border closest points replaced with corresponding points
+ # on the free border. two polylines, one inside the domain, one outside
+
a = os.path.splitext(shapefileToAdjust)
shapefileAdjusted = a[0] + '_adj' + a[1]
chainName = os.path.basename(a[0])
chaincoords = []
chaincoords.append(fbs.points[ifb2])
- for i in range(i2+1, len(sfta.points)):
- chaincoords.append(sfta.points[i])
+ 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])
chaincoords.append(fbs.points[ifb1])
w.record(chainName + '_1')
w.close()
+ # write the free border splited 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])
+
+ w = shapefile.Writer(freeBorderSplit)
+ w.shapeType = 3
+ w.field('name', 'C')
+
+ 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(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()
+