text stringlengths 1 93.6k |
|---|
feature_list = []
|
for coords in start_points:
|
line_coords = [coords]
|
x,y = coords
|
rc = xy_to_rc(coords)
|
value = sample_raster(rc,1) # 1= Get the aspect value
|
if value == 0: #if we go out of bounds, stop this line
|
continue
|
#And here I try to recall 11th-grade trigonometry
|
value += 180
|
new_x = x + math.sin(math.radians(value)) * jump_distance
|
new_y = y + math.cos(math.radians(value)) * jump_distance
|
line_coords += [(new_x,new_y)]
|
for i in range(0,150):
|
# this loop is a failsafe in case other checks below fail
|
# to stop the hachure when they should
|
x,y = line_coords[-1]
|
rc = xy_to_rc(line_coords[-1])
|
value = sample_raster(rc,1) #get the aspect value
|
slope = sample_raster(rc,0) #the slope, too
|
if value == 0: # we're out of bounds of the raster
|
del line_coords[-1]
|
break
|
if slope < min_slope:
|
#if we hit shallow slopes, lines should end
|
del line_coords[-1]
|
break
|
value += 180
|
new_x = x + math.sin(math.radians(value)) * jump_distance
|
new_y = y + math.cos(math.radians(value)) * jump_distance
|
# Hachures often bounce back and forth in shallow slopes &
|
# should stop. If lines are zig-zagging, every other point
|
# will be separated by only a small distance
|
if (len(line_coords) > 3 and
|
dist(line_coords[-1], line_coords[-3])
|
< (jump_distance * 1.5)):
|
# Snip off the last couple points if we've gone bad:
|
del line_coords[-2:]
|
break
|
line_coords += [(new_x,new_y)]
|
if len(line_coords) > 1:
|
# if we stopped before we even got 2 points, don't bother
|
feature_list.append(make_lines(line_coords))
|
return feature_list
|
#---------------------Cartesian distance calculator---------------------
|
def dist(one,two):
|
x1,y1 = one
|
x2,y2 = two
|
return math.sqrt((x1-x2)**2 + (y1-y2)**2)
|
#-------Turns list of tuples of xy coodinates into a line feature-------
|
def make_lines(coord_list):
|
points = [QgsPointXY(x, y) for x, y in coord_list]
|
polyline = QgsGeometry.fromPolylineXY(points)
|
feature = QgsFeature()
|
feature.setGeometry(polyline)
|
return feature
|
#-----Splits a line feature into even segments based on max_spacing-----
|
def even_splitter(contour):
|
spacing = max_spacing * 3
|
output_segments = []
|
for line_geometry in contour.ring_list():
|
length = line_geometry.length()
|
start_point = 0
|
end_point = spacing
|
i = spacing
|
cut_locations = []
|
while i < length:
|
cut_locations.append(i)
|
i += spacing
|
output_segments.extend(master_splitter(line_geometry,cut_locations))
|
return output_segments
|
#---Takes a single line geometry and splits it at a list of locations---
|
def master_splitter(line_geometry,cut_locations):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.