Skip to content

Commit 41dd7c5

Browse files
committed
wip
1 parent 1816612 commit 41dd7c5

6 files changed

Lines changed: 597 additions & 469 deletions

File tree

app.py

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -37,159 +37,6 @@ def generate_topographic_plan():
3737
url = plan.save()
3838
return jsonify({"message": "Topographic plan generated", "filename": plan.name, "url": url}), 200
3939

40-
# @app.route("/route/plan", methods=["POST"])
41-
# def generate_route_plan():
42-
# data = request.get_json()
43-
# plan = PlanProps(**data)
44-
# return jsonify({"message": "Cadastral plan generated", "filename": plan.name, "url": "url"}), 200
45-
46-
# def read_json_file(file_path: str):
47-
# """
48-
# Reads data from a JSON file.
49-
#
50-
# Args:
51-
# file_path (str): Path to the JSON file.
52-
#
53-
# Returns:
54-
# dict | list: Parsed JSON data.
55-
# """
56-
# try:
57-
# with open(file_path, "r", encoding="utf-8") as f:
58-
# data = json.load(f)
59-
# return data
60-
# except FileNotFoundError:
61-
# print(f"Error: File '{file_path}' not found.")
62-
# return None
63-
# except json.JSONDecodeError as e:
64-
# print(f"Error: Failed to decode JSON - {e}")
65-
# return None
66-
67-
# @app.route("/topographic/plan", methods=["POST"])
68-
# def generate_topographic_plan():
69-
# data = request.get_json()
70-
#
71-
# plan = PlanProps(**data)
72-
#
73-
# drawer = SurveyDXFManager(plan_name=plan.name, scale=plan.get_drawing_scale())
74-
# drawer.setup_font(plan.font)
75-
# drawer.setup_topo_point_style()
76-
#
77-
# data = read_json_file("point2.json")
78-
# plan.coordinates = [CoordinateProps(**c) for c in data]
79-
#
80-
# # draw spot heights
81-
# # for coord in plan.coordinates:
82-
# # drawer.add_topo_point(coord.easting, coord.northing, coord.elevation, f"{coord.elevation:.3f}", plan.top_setting.point_label_scale)
83-
#
84-
# # Generate a surface (TIN interpolation).
85-
# x = np.array([coord.easting for coord in plan.coordinates])
86-
# y = np.array([coord.northing for coord in plan.coordinates])
87-
# z = np.array([coord.elevation for coord in plan.coordinates])
88-
#
89-
# # Create triangulation
90-
# triangulation = Triangulation(x, y)
91-
#
92-
# # Generate contour levels
93-
# z_min, z_max = z.min(), z.max()
94-
# levels = np.linspace(z_min, z_max, 100)
95-
#
96-
# # Create matplotlib contours (using memory buffer to avoid display)
97-
# contours = plt.tricontour(triangulation, z, levels=levels)
98-
99-
# # Define major contour interval (every 5th contour)
100-
# major_interval = max(1, len(levels) // 5)
101-
#
102-
# # Extract and draw contour lines
103-
# contour_data = []
104-
#
105-
# # Access contour segments using allsegs attribute (more reliable)
106-
# if hasattr(contours, 'allsegs') and len(contours.allsegs) > 0:
107-
# for level_idx, level_segments in enumerate(contours.allsegs):
108-
# elevation = levels[level_idx]
109-
# is_major = (level_idx % major_interval == 0)
110-
# layer_name = 'CONTOURS_MAJOR' if is_major else 'CONTOURS_MINOR'
111-
#
112-
# # Process each contour segment at this elevation
113-
# for segment in level_segments:
114-
# if len(segment) < 2:
115-
# continue
116-
#
117-
# # Convert to list of tuples for ezdxf
118-
# points = [(float(x), float(y), float(elevation)) for x, y in segment]
119-
#
120-
# # Add polyline to DXF
121-
# polyline = drawer.msp.add_polyline3d(
122-
# points,
123-
# dxfattribs={'layer': layer_name}
124-
# )
125-
#
126-
# # Store contour data
127-
# contour_data.append({
128-
# 'elevation': elevation,
129-
# 'coordinates': segment,
130-
# 'is_major': is_major,
131-
# 'polyline': polyline
132-
# })
133-
#
134-
# # Add elevation labels for major contours
135-
# if is_major and len(points) > 0:
136-
# # Place label at midpoint of contour
137-
# mid_idx = len(points) // 2
138-
# label_x, label_y, _ = points[mid_idx]
139-
#
140-
# drawer.msp.add_text(
141-
# f"{elevation:.1f}",
142-
# dxfattribs={
143-
# 'layer': 'CONTOUR_LABELS',
144-
# 'height': 2.5,
145-
# 'style': 'Standard'
146-
# }
147-
# ).set_placement((label_x, label_y), align=TextEntityAlignment.MIDDLE_CENTER)
148-
# else:
149-
# print("Warning: No contour segments found. Check your input data.")
150-
#
151-
# # # Create triangulation
152-
# # triangulation = Triangulation(x, y)
153-
# #
154-
# # # Draw triangle edges
155-
# # for triangle in triangulation.triangles:
156-
# # # Get the three vertices of each triangle
157-
# # p1 = (x[triangle[0]], y[triangle[0]])
158-
# # p2 = (x[triangle[1]], y[triangle[1]])
159-
# # p3 = (x[triangle[2]], y[triangle[2]])
160-
# #
161-
# # # Create closed polyline for triangle
162-
# # triangle_points = [p1, p2, p3, p1] # Close the triangle
163-
# #
164-
# # drawer.msp.add_lwpolyline(
165-
# # triangle_points,
166-
# # dxfattribs={'layer': "TIN_TRIANGLES"}
167-
# # )
168-
#
169-
# # # Find range
170-
# # z_min, z_max = z.min(), z.max()
171-
# #
172-
# # # Choose interval (e.g., 1 meter)
173-
# # interval = 0.1
174-
# #
175-
# # # Define levels
176-
# # levels = np.arange(np.floor(z_min), np.ceil(z_max) + interval, interval)
177-
# #
178-
# # contours = plt.tricontour(triang, z, levels=levels)
179-
# #
180-
# # # ✅ Each contour level has multiple paths
181-
# # for level, path_collection in zip(contours.levels, contours.get_paths()):
182-
# # for polygon in path_collection.to_polygons():
183-
# # points = [(pt[0], pt[1], float(level)) for pt in polygon]
184-
# # if len(points) > 1:
185-
# # # Create 3D polyline
186-
# # drawer.msp.add_polyline3d(points, dxfattribs={"layer": "CONTOURS"})
187-
#
188-
# drawer.save_dxf()
189-
# # url = drawer.save()
190-
# return jsonify({"message": "Topographic plan generated", "filename": plan.name, "url": "url"}), 200
191-
192-
19340

19441
@app.errorhandler(404)
19542
def not_found(e):

cadastral.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self, **kwargs):
1717
self._frame_y_percent = 0.8
1818
self._bounding_box = self.get_bounding_box()
1919
self._frame_coords = self._setup_frame_coords()
20+
self._coord_dict = {coord.id: coord for coord in self.coordinates}
2021
if not self._frame_coords:
2122
raise ValueError("Cannot determine frame coordinates without valid coordinates.")
2223
self._drawer = self._setup_drawer()
@@ -25,7 +26,6 @@ def _setup_drawer(self) -> SurveyDXFManager:
2526
drawer = SurveyDXFManager(plan_name=self.name, scale=self.get_drawing_scale())
2627
drawer.setup_font(self.font)
2728
drawer.setup_beacon_style(self.beacon_type, self.beacon_size)
28-
drawer.setup_graphical_scale_style(length=(self._frame_coords[2] - self._frame_coords[0]) * 0.4)
2929
return drawer
3030

3131
def _setup_frame_coords(self):
@@ -57,12 +57,9 @@ def draw_parcels(self):
5757
if not self.parcels or not self.coordinates:
5858
return
5959

60-
# create a dictionary of coordinates for easy lookup
61-
coord_dict = {coord.id: coord for coord in self.coordinates}
62-
6360
for parcel in self.parcels:
64-
parcel_points = [(coord_dict[pid].easting, coord_dict[pid].northing)
65-
for pid in parcel.ids if pid in coord_dict]
61+
parcel_points = [(self._coord_dict[pid].easting, self._coord_dict[pid].northing)
62+
for pid in parcel.ids if pid in self._coord_dict]
6663

6764
if not parcel_points:
6865
continue
@@ -175,13 +172,27 @@ def draw_footer_boxes(self):
175172
y2 = y1 + box_height
176173
self._drawer.draw_footer_box(html_to_mtext(footer), x1, y1, x2, y2, self.footer_scale)
177174

175+
def draw_north_arrow(self):
176+
if len(self.parcels) == 0:
177+
return
178+
179+
coord = self._coord_dict[self.parcels[0].ids[0]]
180+
height = (self._frame_coords[3] - self._frame_coords[1]) * 0.07
181+
self._drawer.draw_north_arrow(coord.easting, self._frame_coords[3] - height, height)
182+
183+
def draw_starting_point_lines(self):
184+
if len(self.parcels) == 0:
185+
return
186+
187+
178188
def draw(self):
179189
# Draw elements
180190
self.draw_beacons()
181191
self.draw_parcels()
182192
self.draw_frames()
183193
self.draw_title_block()
184194
self.draw_footer_boxes()
195+
self.draw_north_arrow()
185196

186197
def save_dxf(self, file_path: str):
187198
self._drawer.save_dxf(file_path)

0 commit comments

Comments
 (0)