Skip to content

Commit

Permalink
vectorize
Browse files Browse the repository at this point in the history
  • Loading branch information
mortewle committed Oct 12, 2023
1 parent 3045c01 commit 5b5aa57
Showing 1 changed file with 0 additions and 74 deletions.
74 changes: 0 additions & 74 deletions src/sgis/networkanalysis/cutting_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,80 +218,6 @@ def change_line_endpoint(

return gdf

for idx in dists.index:
line = gdf.loc[idx, "geometry"]
coordslist = list(line.coords)
coordslist[i] = pointmapper[idx]
gdf.loc[idx, "geometry"] = LineString(coordslist)
return gdf


def split_lines2(
gdf: GeoDataFrame, points: GeoDataFrame, max_distance: int | float
) -> GeoDataFrame:
if not (gdf.geom_type == "LineString").all():
raise ValueError()

geom_col = gdf._geometry_column_name

snapped = snap_within_distance(points, lines, max_distance=max_distance)

line_segments = get_line_segments(gdf)

multipoints = gdf.assign(**{geom_col == extract_unique_points(gdf[geom_col])})
multipoints["_split_idx"] = range(len(multipoints))
points = multipoints.explode(index_parts=False)

snap_points_df = (
GeoDataFrame(
{"geometry": extract_unique_points(get_parts(line_merge(snap_to)))}
).explode(index_parts=False)
# .pipe(remove_points_on_straight_lines)
)


def add_nearest_points_as_line_vertices(
lines: np.ndarray,
points: np.ndarray,
max_distance: int | float | None = None,
) -> np.ndarray:
PRECISION = 0.000001

lines["_line_index"] = range(len(lines))

snapped = snap_within_distance(points, lines, max_distance=max_distance)
snapped.index = snapped.geometry

line_segments = (
get_line_segments(lines)
.reset_index(drop=True)
.sjoin(snapped.pipe(buff, PRECISION))
)

line_segments["endpoints"] = line_segments.geometry.boundary

agged = line_segments.groupby(level=0).apply(sorted_unary_union)
line_segments = line_segments.drop_duplicates("_line_index")
line_segments.geometry = agged

# line_segments = sfilter_inverse(line_segments, geoms)

merged = line_segments.groupby("_line_index", as_index=False)["geometry"].agg(
unary_union
)

merged = merged.join(lines.drop(columns="geometry"))

merged.geometry = line_merge(merged.geometry)

is_not_merged = merged.geom_type == "MultiLineString"

merged.loc[is_not_merged, "geometry"] = merged.loc[is_not_merged, "geometry"].apply(
line_merge_by_force
)

return merged


def cut_lines(gdf: GeoDataFrame, max_length: int, ignore_index=False) -> GeoDataFrame:
"""Cuts lines of a GeoDataFrame into pieces of a given length.
Expand Down

0 comments on commit 5b5aa57

Please sign in to comment.