Skip to content

Commit

Permalink
Implement snap to profile curve
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor committed May 7, 2024
1 parent 658c0d5 commit 1d7b5b8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions swiss_locator/core/profiles/profile_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
QgsFillSymbol,
QgsLineSymbol,
QgsMarkerSymbol,
QgsProfilePoint,
QgsProfileRenderContext,
QgsProfileSnapResult
)

PROFILE_SYMBOLOGY = Qgis.ProfileSurfaceSymbology.FillBelow
Expand Down Expand Up @@ -86,6 +88,29 @@ def zRange(self):
def type(self):
return "swiss-profile-web-service"

def snapPoint(self, point, context):
result = QgsProfileSnapResult()

prev_distance = float('inf')
prev_elevation = 0
for k, v in self.distance_to_height.items():
# find segment which corresponds to the given distance along curve
if k != 0 and prev_distance <= point.distance() <= k:
dx = k - prev_distance
dy = v - prev_elevation
snapped_z = (dy / dx) * (point.distance() - prev_distance) + prev_elevation

if abs(point.elevation() - snapped_z) > context.maximumSurfaceElevationDelta:
return QgsProfileSnapResult()

result.snappedPoint = QgsProfilePoint(point.distance(), snapped_z)
break

prev_distance = k
prev_elevation = v

return result

def renderResults(self, context: QgsProfileRenderContext):
self.__render_continuous_surface(context)
if INCLUDE_PROFILE_MARKERS:
Expand Down

0 comments on commit 1d7b5b8

Please sign in to comment.