text stringlengths 1 93.6k |
|---|
start_point = 0
|
cut_locations.append(line_geometry.length())
|
cut_locations.sort()
|
segment_list = []
|
for cut_spot in cut_locations:
|
line_substring = line_geometry.constGet().curveSubstring(
|
start_point,cut_spot)
|
new_feature = QgsFeature()
|
new_feature.setGeometry(line_substring)
|
segment_list.append(Segment(new_feature))
|
start_point = cut_spot
|
return segment_list
|
#---Like master_splitter, but uses CutPoints instead of cut locations---
|
def cutpoint_splitter(line_geometry,CutPoint_list):
|
CutPoint_list.sort(key = lambda x: x.cut_location)
|
# CutPoints hold info on what hachure generated them; we want to add
|
# that info to the subsequent segments
|
segment_list = []
|
# Add first segment
|
line_substring = line_geometry.constGet().curveSubstring(
|
0,CutPoint_list[0].cut_location)
|
new_feature = QgsFeature()
|
new_feature.setGeometry(line_substring)
|
segment_list.append(Segment(new_feature))
|
# Then do all the middle cuts & append hachure data to the Segments
|
for i in range(0,len(CutPoint_list)):
|
start_point = CutPoint_list[i]
|
start_location = start_point.cut_location
|
if i == len(CutPoint_list) - 1:
|
# Checks if we're at end of the list & handles final segment
|
end_location = line_geometry.length()
|
else:
|
end_point = CutPoint_list[i+1]
|
end_location = end_point.cut_location
|
line_substring = line_geometry.constGet().curveSubstring(
|
start_location,end_location)
|
new_feature = QgsFeature()
|
new_feature.setGeometry(line_substring)
|
new_segment = Segment(new_feature)
|
segment_list.append(new_segment)
|
if i != len(CutPoint_list) - 1:
|
new_segment.hachures = [start_point.hachure,end_point.hachure]
|
return segment_list
|
#===============FUNCTIONS OVER; BEGIN CONTOUR PREPARATION===============
|
#-STEP 1: Process the contours so that they are all in the needed format
|
instance.addMapLayer(filled_contours,False)
|
# Add filled_contours as hidden layer so I can work with it below
|
# First we sort the contours from low elevation to high.
|
# They probably were already sorted this way, but let's not chance it.
|
contour_polys = [f for f in filled_contours.getFeatures()]
|
contour_polys.sort(key = lambda x: x.attributeMap()['ELEV_MIN'])
|
# Each contour poly will be turned into a new polygon showing all areas
|
# that are *higher* than that contour
|
#-----STEP 2: Make a simple rectangle poly covering contours' extent----
|
extent = filled_contours.extent()
|
boundary_polygon = QgsGeometry.fromRect(extent)
|
#--STEP 3: Iterate through each contour poly and subtract it from our---
|
#------rectangle, thus yielding rectangles with varying size holes------
|
contour_geometries = [f.geometry() for f in contour_polys]
|
# Loop below starts with our boundary rectangle, subtracts the lowest
|
# elevation poly from it, and stores the result. It then subtracts the
|
# 2nd-lowest poly from that result and stores that. And so on, each time
|
# subtracting the next-lowest poly from the result of the last operation
|
working_geometry = boundary_polygon
|
contour_differences = []
|
for geom in contour_geometries[:-1]:
|
# We drop the last one because it's going to be empty
|
working_geometry = working_geometry.difference(geom)
|
contour_differences.append(working_geometry)
|
#------------------STEP 4: Dissolve the contour lines-------------------
|
contour_dict = defaultdict(list)
|
for feature in line_contours.getFeatures():
|
contour_dict[feature.attributeMap()['ELEV']].append(feature)
|
#this dict is now of the form {Elevation: [list of features]}
|
keys = list(contour_dict.keys())
|
keys.sort()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.