text stringlengths 1 93.6k |
|---|
return aspect_block.value(row,col)
|
#-----------Given a slope, find the ideal spacing of hachures-----------
|
def ideal_spacing(slope):
|
if slope > max_slope:
|
slope = max_slope
|
elif slope < min_slope:
|
# None indicates that slope is too shallow & needs no hachures
|
return None
|
# Finds where the slop is in the range of min/max slope
|
# Then normalizes it to the range of min/max spacing
|
slope_pct = (slope - min_slope) / slope_range
|
spacing_qty = slope_pct * spacing_range
|
spacing = max_spacing - spacing_qty
|
return spacing
|
#--Take Segments & turn them into dashed lines based on ideal spacing---
|
def dash_maker(contour_segment_list):
|
output_segments = []
|
for contour_segment in contour_segment_list:
|
slope = contour_segment.slope
|
if slope < min_slope:
|
continue
|
spacing = ideal_spacing(slope)
|
#We tune the spacing value based on the segment length to ensure
|
#an integer number of dashes. This is rather like the automatic
|
#dash/gap spacing in Adobe Illustrator
|
#Our goal here is to split a segment into dashes & gaps, thusly:
|
# ---- ---- ---- ---- ---- ---- ----
|
#Each dash length = spacing, surrounded by gaps half that width
|
#Thus one unit looks like this: | ---- |
|
total_length = spacing * 2 #the length of a gap + dash + gap
|
total_units = round(contour_segment.length / total_length)
|
if total_units == 0:
|
#Just in case we round down to the point of having 0 dashes
|
continue
|
dash_gap_length = contour_segment.length / total_units
|
dash_width = dash_gap_length / 2
|
#half of our gap-dash-gap is the dash
|
gap_width = dash_width / 2
|
start_point = gap_width
|
end_point = dash_width + gap_width
|
geometry = contour_segment.geometry
|
while True:
|
substring_feature = QgsFeature()
|
line_substring = geometry.constGet().curveSubstring(
|
start_point, end_point)
|
substring_feature.setGeometry(line_substring)
|
output_segments.append(Segment(substring_feature))
|
start_point += dash_gap_length
|
end_point += dash_gap_length
|
if end_point > contour_segment.length:
|
break
|
if len(output_segments) > 0:
|
return output_segments
|
else:
|
return None
|
#-------------------Starts our first set of hachures--------------------
|
def first_contour(contour):
|
global current_hachures
|
# Split the contour into even segments to begin
|
contour_segments = even_splitter(contour)
|
# Then turn them into dashes
|
dashes = dash_maker(contour_segments)
|
if dashes:
|
current_hachures = hachure_generator(dashes)
|
#----Checks a contour to see where hachures need to be trimmed/begun----
|
def subsequent_contour(contour):
|
global current_hachures
|
# First we split the contour according to the existing hachures
|
split_contour = contour.split_by_hachures()
|
# We may need to further subdivide some of these. Some segments may
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.