def _write_boat_area(pier, stg_manager, coords_transform: co.Transformation): if len(pier.nodes) < 3: return # Guess a possible position for realistic boat placement linear_ring = shg.LinearRing(pier.nodes) centroid = linear_ring.centroid # Simplify ring = linear_ring.convex_hull.buffer( 40, cap_style=CAP_STYLE.square, join_style=JOIN_STYLE.bevel).simplify(20) for p in ring.exterior.coords: line_coords = [[centroid.x, centroid.y], p] target_vector = shg.LineString(line_coords) coords = linear_ring.coords for i in range(len(coords) - 1): segment = LineString(coords[i:i + 2]) if segment.length > 20 and segment.intersects(target_vector): direction = math.degrees( math.atan2(segment.coords[0][0] - segment.coords[1][0], segment.coords[0][1] - segment.coords[1][1])) parallel = segment.parallel_offset(10, 'right') boat_position = parallel.interpolate(segment.length / 2) try: pos_global = coords_transform.to_global( (boat_position.x, boat_position.y)) _write_model(segment.length, stg_manager, pos_global, direction, pier.elevation) except AttributeError as reason: logging.error(reason)
def shift_points(points, distance=1, side='left', resolution=16, join_style=3, mitre_limit=5.0): """Takes array of points, create linestring, shift the linestring and return shifted""" line = LineString(points) shift_line = line.parallel_offset(distance, side) print('shift_line=\n', shift_line) return shift_line
def _write_boat_line(pier, stg_manager, coords_transform: co.Transformation): line_string = LineString(pier.nodes) right_line = line_string.parallel_offset(4, 'left', resolution=8, join_style=1, mitre_limit=10.0) if isinstance(right_line, LineString): # FIXME: what to do else? coords = right_line.coords for i in range(len(coords) - 1): segment = LineString(coords[i:i + 2]) boat_position = segment.interpolate(segment.length / 2) try: pos_global = coords_transform.to_global( (boat_position.x, boat_position.y)) direction = math.degrees( math.atan2(segment.coords[0][0] - segment.coords[1][0], segment.coords[0][1] - segment.coords[1][1])) if segment.length > 5: _write_model(segment.length, stg_manager, pos_global, direction, pier.elevation) except AttributeError as reason: logging.error(reason)