text
stringlengths
1
93.6k
# be too long & their slope calculations are no longer local
segment_list = []
for segment in split_contour:
if segment.length > max_spacing * 3:
segment_list += even_splitter(segment)
else:
segment_list += [segment]
too_short = []
too_long = []
clip_all = []
for segment in segment_list:
if segment.status == 1:
too_short.append(segment)
elif segment.status == 2:
too_long.append(segment)
elif segment.status == 0:
clip_all.append(segment)
# too_short: this segment spans 2 hachures that are too close
# too_long: segment's 2 hachures are too far apart
# clip_all: this segment's slope is low enough that hachures stop
# We first find which hachures must be clipped off
to_clip = []
for seg in clip_all:
to_clip.extend(seg.hachures)
for seg in too_short:
hachures = seg.hachures
if len(hachures) == 2:
# Some segments won't touch enough hachures
random.shuffle(hachures)
to_clip.append(hachures[0])
# to_clip can have duplicates. A hachure may have too_short segments
# on each side, and both of them choose that particular hachure as
# the 1 that needs to be clipped off. So we remove duplicates:
to_clip = list(set(to_clip))
# Remove those to be clipped from the current hachures
current_hachures = [f for f in current_hachures if f not in to_clip]
# Clip them, then put them back
clipped_hachures = haircut(contour,to_clip)
current_hachures += clipped_hachures
#Let's next deal with adding new hachures to the too_long segments
made_additions = False
if len(too_long) > 0:
dashes = dash_maker(too_long)
if dashes: #this could come back with None so we must check
made_additions = True
additions = hachure_generator(dashes)
if made_additions:
current_hachures += additions
#----Clips off hachures that need to stop at this particular contour----
def haircut(contour,hachure_list):
contour_poly_geometry = contour.polygon
clipped = []
for hachure in hachure_list:
hachure_geo = hachure.geometry()
feat = QgsFeature()
feat.setGeometry(hachure_geo.difference(contour_poly_geometry))
clipped.append(feat)
return clipped
#--Generates new hachures starting at the middle of any given segment---
def hachure_generator(segment_list):
#First we need the midpoint in each line, to begin our hachure from
start_points = []
for segment in segment_list:
midpoint = segment.length / 2
midpoint = segment.geometry.interpolate(midpoint)
start_points.append(midpoint.asPoint())
#Next loop through the start_points & make hachures