|
9 | 9 | import matplotlib.pyplot as plt |
10 | 10 | import numpy as np |
11 | 11 | import ocsmesh |
| 12 | +import pandas as pd |
12 | 13 | import rasterio |
13 | 14 | from jigsawpy.msh_t import jigsaw_msh_t |
14 | 15 | from matplotlib.axes import Axes |
15 | 16 | from netCDF4 import Dataset |
16 | 17 | from pyproj.enums import TransformDirection |
17 | 18 | from rasterio.mask import mask |
18 | | -from shapely.geometry import Polygon, mapping |
| 19 | +from shapely.geometry import LineString, MultiLineString, Polygon, mapping |
19 | 20 | from shapely.ops import transform |
20 | 21 |
|
21 | 22 | from ..core.geo import buffer_area_for_polygon |
@@ -1084,3 +1085,33 @@ def define_mesh_target_size( |
1084 | 1085 | simpl_UTM = 100.0 # Simplification tolerance in meters |
1085 | 1086 | simplified_shape = simply_polygon(base_shape, simpl_UTM, project) |
1086 | 1087 | print(simplified_shape) |
| 1088 | + |
| 1089 | + |
| 1090 | +def read_lines(poly_line: str) -> MultiLineString: |
| 1091 | + """ |
| 1092 | + Reads a CSV file containing coordinates of a polyline and returns a MultiLineString. |
| 1093 | + The CSV file should have two columns for x and y coordinates, with NaN values indicating breaks in the line. |
| 1094 | + Parameters |
| 1095 | + ---------- |
| 1096 | + poly_line : str |
| 1097 | + Path to the CSV file containing the polyline coordinates |
| 1098 | + Returns |
| 1099 | + ------- |
| 1100 | + MultiLineString |
| 1101 | + A MultiLineString object representing the polyline segments |
| 1102 | + """ |
| 1103 | + |
| 1104 | + coords_line = pd.read_csv(poly_line, sep=",", header=None) |
| 1105 | + segments = [] |
| 1106 | + current_segment = [] |
| 1107 | + for index, row in coords_line.iterrows(): |
| 1108 | + if row.isna().any(): |
| 1109 | + if current_segment: |
| 1110 | + segments.append(LineString(current_segment)) |
| 1111 | + current_segment = [] |
| 1112 | + else: |
| 1113 | + current_segment.append(tuple(row)) |
| 1114 | + |
| 1115 | + if current_segment: |
| 1116 | + segments.append(LineString(current_segment)) |
| 1117 | + return MultiLineString(segments) |
0 commit comments