text stringlengths 1 93.6k |
|---|
for line_geometry in self.ring_list():
|
intersection_points = []
|
for hachure_feature in current_hachures:
|
hachure_geometry = hachure_feature.geometry()
|
point = line_geometry.intersection(hachure_geometry)
|
if point.wkbType() == QgsWkbTypes.MultiPoint:
|
intersection_points += [CutPoint(
|
QgsGeometry.fromPointXY(p),hachure_feature)
|
for p in point.asMultiPoint()]
|
elif point.wkbType() == QgsWkbTypes.Point:
|
intersection_points += [CutPoint(point, hachure_feature)]
|
# The intersection can return Empty or (rarely)
|
# a geometryCollection. We can safely skip over these
|
for point in intersection_points:
|
# This tells us where along the line to cut
|
point.cut_location = line_geometry.lineLocatePoint(
|
point.geometry)
|
if len(intersection_points) > 0:
|
# If we found intersections, use them to cut the ring
|
contour_segments = cutpoint_splitter(line_geometry,
|
intersection_points)
|
all_segments += contour_segments
|
else:
|
# If not, we should still return the unbroken ring
|
ring_feature = QgsFeature()
|
ring_feature.setGeometry(line_geometry)
|
all_segments.append(Segment(ring_feature))
|
return all_segments
|
#----Segments are contour pieces used to space or generate hachures-----
|
class Segment:
|
def __init__(self,segFeature):
|
self.geometry = segFeature.geometry()
|
self.length = self.geometry.length()
|
self.slope = self.slope()
|
self.hachures = []
|
self.status = None
|
# Status stores info on how this segment should affect hachures
|
# These values are used later in subsequent_contour
|
if self.slope < min_slope:
|
self.status = 0
|
elif self.length < (ideal_spacing(self.slope) * 0.9):
|
self.status = 1
|
elif self.length > (ideal_spacing(self.slope) * 2.2):
|
self.status = 2
|
# The 0.9 and 2.2 above are thermostat controls. Instead of a
|
# line being "too short" when it exactly falls below its ideal
|
# spacing, we let it get a little tighter to avoid near-parallel
|
# hachures cycling on/off rapidly.
|
def ring_list(self):
|
return [self.geometry]
|
def slope(self):
|
# Get the average slope under this segment
|
densified_line = self.geometry.densifyByDistance(average_pixel_size)
|
vertices = [(vertex.x(), vertex.y())
|
for vertex in densified_line.vertices()]
|
row_col_coords = [xy_to_rc(c) for c in vertices]
|
samples = [sample_raster(c,0) for c in row_col_coords]
|
return statistics.fmean(samples)
|
#--------------CutPoints mark where a contour is to be cut--------------
|
class CutPoint:
|
def __init__(self,point_geometry,hachure_feature):
|
self.geometry = point_geometry
|
self.hachure = hachure_feature
|
self.cut_location = None
|
#=========================FUNCTION DEFINITIONS-=========================
|
#--------Converts x/y coords to row/col for sampling the rasters--------
|
def xy_to_rc(location):
|
x,y = location
|
col = round((x - extent.xMinimum()) / cell_width - 0.5)
|
row = round((extent.yMaximum() - y) / cell_height - 0.5)
|
return (row,col)
|
#-------------------Samples the slope or aspect raster------------------
|
def sample_raster(location,type = 0):
|
row,col = location
|
if row >= rows or col >= cols or row < 0 or col < 0:
|
# i.e., if we're out of bounds
|
return 0
|
if type == 0:
|
return slope_block.value(row,col)
|
else:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.