Skip to content

Commit bac6e11

Browse files
committed
main
1 parent 83dea9e commit bac6e11

2 files changed

Lines changed: 38 additions & 55 deletions

File tree

cadastral.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ def _setup_frame_coords(self):
4646

4747
return frame_left, frame_bottom, frame_right, frame_top
4848

49+
def _get_drawing_extent(self) -> float:
50+
# get bounding box
51+
min_x, min_y, max_x, max_y = self._bounding_box
52+
if min_x is None or min_y is None or max_x is None or max_y is None:
53+
return 0.0
54+
55+
width = max_x - min_x
56+
height = max_y - min_y
57+
extent = math.sqrt(width ** 2 + height ** 2)
58+
return extent
59+
4960
def draw_beacons(self):
5061
if not self.coordinates:
5162
return
@@ -87,7 +98,7 @@ def add_leg_labels(self, leg, orientation: str):
8798

8899
# Offset text above/below the line
89100
normals = line_normals((leg.from_.easting, leg.from_.northing), (leg.to.easting, leg.to.northing), orientation)
90-
offset_distance = self.beacon_size * 0.2
101+
offset_distance = self._get_drawing_extent() * 0.005
91102
offset_inside_x = (normals[0][0] / math.hypot(*normals[0])) * offset_distance
92103
offset_inside_y = (normals[0][1] / math.hypot(*normals[0])) * offset_distance
93104
offset_outside_x = (normals[1][0] / math.hypot(*normals[1])) * offset_distance
@@ -180,11 +191,6 @@ def draw_north_arrow(self):
180191
height = (self._frame_coords[3] - self._frame_coords[1]) * 0.07
181192
self._drawer.draw_north_arrow(coord.easting, self._frame_coords[3] - height, height)
182193

183-
def draw_starting_point_lines(self):
184-
if len(self.parcels) == 0:
185-
return
186-
187-
188194
def draw(self):
189195
# Draw elements
190196
self.draw_beacons()

topographic.py

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,11 @@
99
from scipy.interpolate import griddata, LinearNDInterpolator
1010
from scipy.ndimage import gaussian_filter
1111
from scipy.spatial import Delaunay
12-
from scipy.spatial.distance import cdist
13-
from typing import List, Tuple, Dict, Optional, Union
12+
from typing import List, Tuple, Optional
1413

1514
import math
1615
import numpy as np
1716

18-
19-
def apply_minimum_distance_filter(coordinates, min_distance):
20-
"""
21-
Filter contour points to maintain the minimum distance between points
22-
"""
23-
if len(coordinates) < 3 or min_distance <= 0:
24-
return coordinates
25-
26-
filtered_coords = [coordinates[0]] # Always keep the first point
27-
28-
for i in range(1, len(coordinates)):
29-
current_point = coordinates[i]
30-
last_kept_point = filtered_coords[-1]
31-
32-
# Calculate distance to the last kept point
33-
distance = np.sqrt((current_point[0] - last_kept_point[0]) ** 2 +
34-
(current_point[1] - last_kept_point[1]) ** 2)
35-
36-
if distance >= min_distance:
37-
filtered_coords.append(current_point)
38-
39-
# Always keep the last point if it's not already kept
40-
if len(filtered_coords) > 1 and not np.array_equal(filtered_coords[-1], coordinates[-1]):
41-
filtered_coords.append(coordinates[-1])
42-
43-
return filtered_coords
44-
45-
def calculate_average_point_spacing(x, y):
46-
"""Calculate average distance between survey points"""
47-
if len(x) < 2:
48-
return 0
49-
50-
points = np.column_stack((x, y))
51-
distances = cdist(points, points)
52-
53-
# Get non-zero distances (exclude self-distances)
54-
non_zero_distances = distances[distances > 0]
55-
56-
return np.mean(non_zero_distances) if len(non_zero_distances) > 0 else 0
57-
58-
5917
class TopographicPlan(PlanProps):
6018
_drawer: SurveyDXFManager = PrivateAttr()
6119

@@ -114,6 +72,17 @@ def _setup_topo_points(self):
11472
pts = [(coord.easting, coord.northing, coord.elevation) for coord in self.coordinates]
11573
return np.array(pts)
11674

75+
def _get_drawing_extent(self) -> float:
76+
# get bounding box
77+
min_x, min_y, max_x, max_y = self._bounding_box
78+
if min_x is None or min_y is None or max_x is None or max_y is None:
79+
return 0.0
80+
81+
width = max_x - min_x
82+
height = max_y - min_y
83+
extent = math.sqrt(width ** 2 + height ** 2)
84+
return extent
85+
11786
def draw_beacons(self):
11887
if not self.topographic_boundary:
11988
return
@@ -155,16 +124,16 @@ def add_leg_labels(self, leg, orientation: str):
155124
angle_deg = math.degrees(angle_rad)
156125

157126
# Fractional positions
158-
first_x = leg.from_.easting + 0.2 * (leg.to.easting - leg.from_.easting)
159-
first_y = leg.from_.northing + 0.2 * (leg.to.northing - leg.from_.northing)
160-
last_x = leg.from_.easting + 0.8 * (leg.to.easting - leg.from_.easting)
161-
last_y = leg.from_.northing + 0.8 * (leg.to.northing - leg.from_.northing)
127+
first_x = leg.from_.easting + (0.2 * (leg.to.easting - leg.from_.easting))
128+
first_y = leg.from_.northing + (0.2 * (leg.to.northing - leg.from_.northing))
129+
last_x = leg.from_.easting + (0.8 * (leg.to.easting - leg.from_.easting))
130+
last_y = leg.from_.northing + (0.8 * (leg.to.northing - leg.from_.northing))
162131
mid_x = (leg.from_.easting + leg.to.easting) / 2
163132
mid_y = (leg.from_.northing + leg.to.northing) / 2
164133

165134
# Offset text above/below the line
166135
normals = line_normals((leg.from_.easting, leg.from_.northing), (leg.to.easting, leg.to.northing), orientation)
167-
offset_distance = 1 * self.get_drawing_scale()
136+
offset_distance = self._get_drawing_extent() * 0.005
168137
offset_inside_x = (normals[0][0] / math.hypot(*normals[0])) * offset_distance
169138
offset_inside_y = (normals[0][1] / math.hypot(*normals[0])) * offset_distance
170139
offset_outside_x = (normals[1][0] / math.hypot(*normals[1])) * offset_distance
@@ -542,16 +511,24 @@ def draw_topo_map(self):
542511
if self.topographic_setting.grid:
543512
self._drawer.toggle_layer("GRID_MESH", self.topographic_setting.show_mesh)
544513

514+
def draw_north_arrow(self):
515+
if len(self.topographic_boundary.coordinates) == 0:
516+
return
517+
518+
coord = self._coord_dict[self.topographic_boundary.coordinates[0].id]
519+
height = (self._frame_coords[3] - self._frame_coords[1]) * 0.07
520+
self._drawer.draw_north_arrow(coord.easting, self._frame_coords[3] - height, height)
545521

546522
def draw(self):
547523
# Draw elements
548-
self.draw_topo_points()
549524
self.draw_beacons()
525+
self.draw_topo_points()
550526
self.draw_boundary()
551527
self.draw_frames()
552528
self.draw_title_block()
553529
self.draw_footer_boxes()
554530
self.draw_topo_map()
531+
self.draw_north_arrow()
555532

556533
def save_dxf(self, file_path: str):
557534
self._drawer.save_dxf(file_path)

0 commit comments

Comments
 (0)