Skip to content

Commit

Permalink
exception treatment on crossing generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kauevestena committed Dec 17, 2023
1 parent 4a894ae commit ec3086d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,5 @@ temporary/*

# REPORTS:
reports/*

tests.py
24 changes: 16 additions & 8 deletions generic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,20 +905,27 @@ def point_forms_minor_angle_w2(fixedpoint_A,centerpoint_B,pointlist,return_index


for point in pointlist:
pC = qgsgeom_to_pointuple(point)
try:
pC = qgsgeom_to_pointuple(point)


angle = QgsGeometryUtils.angleBetweenThreePoints(*pA,*pB,*pC) * (180/pi)
angle = QgsGeometryUtils.angleBetweenThreePoints(*pA,*pB,*pC) * (180/pi)

if angle > 180:
angle = 360 - angle
if angle > 180:
angle = 360 - angle

anglelist.append(angle)
anglelist.append(angle)
except:
anglelist.append(360)

if print_angles:
print(anglelist)

index = anglelist.index(min(anglelist))
if anglelist:

index = anglelist.index(min(anglelist))
else:
index = 0

if return_index:
return index
Expand Down Expand Up @@ -953,8 +960,9 @@ def check_sidewalk_intersection(intersectiongeom,referencepoint):
return True,intersectiongeom
else:
# if it returns Multipart geometry, it was because there are 2 points of intersection, so we chose the nearest to "referencepoint"
print(intersectiongeom.asWkt())
print(intersectiongeom.wkbType())

# print(intersectiongeom.asWkt())
# print(intersectiongeom.wkbType())

as_geomcollection = intersectiongeom.asGeometryCollection()

Expand Down
24 changes: 16 additions & 8 deletions osm_sidewalkreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def change_all_labels_bylang(self):
(self.dlg.dontsplit_checkbox,"Don't Split",'Não Dividir'),
(self.dlg.input_feature_text,"input feature:\n(-1: none)",'Feição de Entrada\n(-1: nenhuma)'),

(self.dlg.min_seg_len_label,"min segment\nlength",'comprimento\nmin. (seg.)'),
(self.dlg.min_seg_len_label,"min road\nsegment length",'comprimento min.\n(seg. via)'),
(self.dlg.ch_remove_abovetol,"remove above tolerance",'remover se acima da tol.'),


Expand Down Expand Up @@ -1137,16 +1137,20 @@ def draw_crossings(self):
'''


paralell_unsucessful = False

if self.dlg.opt_parallel_crossings.isChecked():
pts_inters_P0 = points_intersecting_buffer_boundary(P0,self.splitted_lines,list(P0_intersecting_widths))

# chosen index:
ch_index = point_forms_minor_angle_w2(innerP0_0,P0,pts_inters_P0,True)
try:
ch_index = point_forms_minor_angle_w2(innerP0_0,P0,pts_inters_P0)
dirvecs_dict[innerP0_id] = vector_from_2_pts(P0,pts_inters_P0[ch_index],initial_vec_len)
except:
paralell_unsucessful = True

dirvecs_dict[innerP0_id] = vector_from_2_pts(P0,pts_inters_P0[ch_index],initial_vec_len)

if self.dlg.opt_perp_crossings.isChecked():
if self.dlg.opt_perp_crossings.isChecked() or paralell_unsucessful:

# creating a perpendicular vector:
# first, we create a vector parallel to the current street segment
Expand Down Expand Up @@ -1222,25 +1226,29 @@ def draw_crossings(self):
'''
in the next functions, we:
- create the candidate points, intersecting lines with circle
- create the candidate points, intersecting lines with a circle
- find the index of the point that forms the minor angle
- create the vector containing the direction of the crossing
'''

paralell_unsucessful = False

if self.dlg.opt_parallel_crossings.isChecked():
pts_inters_PF = points_intersecting_buffer_boundary(PF,self.splitted_lines,list(PF_intersecting_widths))


# chosen index:
ch_index = point_forms_minor_angle_w2(innerPF_0,PF,pts_inters_PF,True)
try:
ch_index = point_forms_minor_angle_w2(innerPF_0,PF,pts_inters_PF,True)

dirvecs_dict[innerPF_id] = vector_from_2_pts(PF,pts_inters_PF[ch_index],initial_vec_len)
dirvecs_dict[innerPF_id] = vector_from_2_pts(PF,pts_inters_PF[ch_index],initial_vec_len)
except:
paralell_unsucessful = True


if self.dlg.opt_perp_crossings.isChecked():
if self.dlg.opt_perp_crossings.isChecked() or paralell_unsucessful:

# creating a perpendicular vector:
# first, we create a vector parallel to the current street segment
Expand Down
4 changes: 2 additions & 2 deletions osm_sidewalkreator_dialog_base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ Compute Intersections</string>
<string notr="true">background-color: rgb(255, 253, 197);</string>
</property>
<property name="text">
<string>Many Times its better to
<string>Sometimes it's better to
correct errors on OSM data first!</string>
</property>
<property name="alignment">
Expand Down Expand Up @@ -1244,7 +1244,7 @@ dicularly</string>
<bool>false</bool>
</property>
<property name="text">
<string>min segment
<string>min road segment
length</string>
</property>
<property name="alignment">
Expand Down
6 changes: 0 additions & 6 deletions tests.py

This file was deleted.

0 comments on commit ec3086d

Please sign in to comment.