-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
840f135
commit 391ff45
Showing
7 changed files
with
3,922 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# internal imports | ||
from ..utils import calculate_vector_along_line, calculate_angle | ||
|
||
#external imports | ||
import numpy | ||
import geopandas | ||
import shapely | ||
|
||
|
||
class FaultConnector: | ||
|
||
|
||
def __init__(self, data: geopandas.GeoDataFrame): | ||
self._data = data.copy() | ||
self.processed_data = None | ||
|
||
def connect_faults(self): | ||
|
||
"""Process the GeoDataFrame to merge faults based on the angle criterion.""" | ||
|
||
self.processed_data = self._data.copy() | ||
i = 0 | ||
|
||
while i < len(self.processed_data): | ||
j = i + 1 | ||
while j < len(self.processed_data): | ||
line1 = self.processed_data.iloc[i].geometry | ||
line2 = self.processed_data.iloc[j].geometry | ||
|
||
# Find the intersection | ||
intersection = line1.intersection(line2) | ||
if intersection.is_empty or not intersection.geom_type == "Point": | ||
j += 1 | ||
continue # Skip if no intersection or if it's not a point | ||
|
||
# Get the intersection point | ||
intersection_point = numpy.array(intersection.coords[0]) | ||
|
||
# Compute vectors aligned with each LineString | ||
vector1 = calculate_vector_along_line(line1, intersection_point) | ||
vector2 = calculate_vector_along_line(line2, intersection_point) | ||
|
||
# Ensure non-zero vectors before proceeding | ||
if numpy.linalg.norm(vector1) == 0 or numpy.linalg.norm(vector2) == 0: | ||
j += 1 | ||
continue | ||
|
||
# Calculate the angle between the vectors | ||
angle = calculate_angle(vector1, vector2) | ||
|
||
# If the angle is below 20 degrees, merge the lines | ||
if angle < 20: | ||
merged_line = shapely.geometry.LineString(list(line1.coords) + list(line2.coords)) | ||
|
||
# Add the merged line and remove the old ones | ||
self.processed_data = self.processed_data.drop([i, j]).reset_index(drop=True) | ||
self.processed_data = self.processed_data.append({'geometry': merged_line}, ignore_index=True) | ||
|
||
# Restart processing for safety (to avoid index shifts) | ||
i = 0 | ||
j = 0 | ||
else: | ||
j += 1 # Move to the next line | ||
|
||
i += 1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import numpy | ||
import shapely | ||
|
||
|
||
def unit_vector(vector): | ||
"""Returns the unit vector of the vector.""" | ||
return vector / numpy.linalg.norm(vector) | ||
|
||
|
||
def calculate_angle(v1, v2): | ||
"""Returns the angle in degrees between two vectors.""" | ||
v1_u = unit_vector(v1) | ||
v2_u = unit_vector(v2) | ||
angle = numpy.degrees(numpy.arccos(numpy.clip(numpy.dot(v1_u, v2_u), -1.0, 1.0))) | ||
return angle | ||
|
||
|
||
def calculate_vector_along_line(line, intersection_point): | ||
""" | ||
Computes a unit vector along the LineString that is aligned with its direction. | ||
""" | ||
# Project the intersection point onto the line to find its position along the line | ||
proj_point = line.interpolate(line.project(shapely.geometry.Point(intersection_point))) | ||
|
||
# Get the two closest segments of the line around the intersection point | ||
coords = list(line.coords) | ||
for i in range(len(coords) - 1): | ||
start, end = numpy.array(coords[i], dtype=object), numpy.array(coords[i + 1], dtype=object) | ||
if ( | ||
shapely.geometry.Point(start).distance(proj_point) | ||
+ shapely.geometry.Point(end).distance(proj_point) | ||
) == shapely.geometry.Point(start).distance(shapely.geometry.Point(end)): | ||
# Found the segment containing the projection point | ||
segment_vector = end - start | ||
return unit_vector(segment_vector) | ||
|
||
# Fallback: Return zero vector if no segment is found (shouldn't happen) | ||
return numpy.array([0, 0, 0]) |
Oops, something went wrong.