Skip to content

Commit

Permalink
Merge pull request #78 from kartverket/waterpolygon_centerline
Browse files Browse the repository at this point in the history
Waterpolygon centerline
  • Loading branch information
EllingOftedalKV authored Feb 14, 2024
2 parents 3890159 + 8fbb0f6 commit 32d5aec
Show file tree
Hide file tree
Showing 4 changed files with 605 additions and 18 deletions.
168 changes: 166 additions & 2 deletions file_manager/n100/file_manager_rivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ def generate_file_name_lyrx(
river_centerline = "river_centerline"
centerline_pruning = "centerline_pruning"
thin_hydrology_lines = "thin_hydrology_lines"
centerline_pruning_loop = "centerline_pruning_loop"

##############################################################################################################################################


class River_N100(Enum):

###########################################
########### RIVER DATA PREPARATION ##########
###########################################
Expand All @@ -119,7 +119,7 @@ class River_N100(Enum):
)

#################################################
########### UNCONNECTED RIVER GEOMETRY #########
########### UNCONNECTED RIVER GEOMETRY ###########
#################################################

unconnected_river_geometry__river_area_selection__n100 = generate_file_name_gdb(
Expand Down Expand Up @@ -315,3 +315,167 @@ class River_N100(Enum):
description="visible_streams",
scale=scale,
)

#################################################
########### RIVER CENTERLINE PROONING LOOP ###########
#################################################

centerline_pruning_loop__lake_features__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="lake_features",
scale=scale,
)

centerline_pruning_loop__rivers_erased_with_lake_features__n100 = (
generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="rivers_erased_with_lake_features",
scale=scale,
)
)

centerline_pruning_loop__study_area__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="study_area",
scale=scale,
)

centerline_pruning_loop__water_features_study_area__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="water_features_study_area",
scale=scale,
)

centerline_pruning_loop__water_features_dissolved__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="water_features_dissolved",
scale=scale,
)

centerline_pruning_loop__water_features_dissolved_river_intersect__n100 = (
generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="water_features_dissolved_river_intersect",
scale=scale,
)
)

centerline_pruning_loop__water_features_river_final_selection__n100 = (
generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="water_features_river_final_selection",
scale=scale,
)
)

centerline_pruning_loop__polygon_to_line__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="polygon_to_line",
scale=scale,
)

centerline_pruning_loop__water_features_shared_boundaries__n100 = (
generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="water_features_shared_boundaries",
scale=scale,
)
)

centerline_pruning_loop__shared_boundaries_midpoint__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="shared_boundaries_midpoint",
scale=scale,
)

centerline_pruning_loop__river_inlets__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="river_inlets",
scale=scale,
)

centerline_pruning_loop__river_inlets_erased__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="river_inlets_erased",
scale=scale,
)

centerline_pruning_loop__river_inlets_points_merged__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="river_inlets_points_merged",
scale=scale,
)

short_name__water__n100 = generate_file_name_gdb(
function_name="short_name",
description="water",
scale=scale,
)

centerline_pruning_loop__collapsed_hydropolygon__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="collapsed_hydropolygon",
scale=scale,
)

centerline_pruning_loop__closed_centerline_lines__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="closed_centerline_lines",
scale=scale,
)

centerline_pruning_loop__closed_centerline_point__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="closed_centerline_point",
scale=scale,
)

centerline_pruning_loop__intersection_points_merged__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="intersection_points_merged",
scale=scale,
)

centerline_pruning_loop__centerline_start_end_vertex__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="centerline_start_end_vertex",
scale=scale,
)

centerline_pruning_loop__centerline_intersection_vertex__n100 = (
generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="centerline_intersection_vertex",
scale=scale,
)
)

centerline_pruning_loop__river_inlet_dangles__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="river_inlet_dangles",
scale=scale,
)

# centerline_pruning_loop__river_inlet_dangles_merged__n100 = generate_file_name_gdb(
# function_name=centerline_pruning_loop,
# description="river_inlet_dangles_merged",
# scale=scale,
# )

centerline_pruning_loop__water_feature_summarized__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="water_feature_summarized",
scale=scale,
)

centerline_pruning_loop__simple_water_features__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="simple_water_features",
scale=scale,
)

centerline_pruning_loop__complex_water_features__n100 = generate_file_name_gdb(
function_name=centerline_pruning_loop,
description="complex_water_features",
scale=scale,
)
45 changes: 30 additions & 15 deletions generalization/n100/river/extend_river_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ def create_lines_from_coordinates(line_points, all_rivers):

# Create a line from the start point to the end point
line = arcpy.Polyline(
arcpy.Array([start_point, end_point]),
environment_setup.project_spatial_reference,
arcpy.Array(
[start_point, end_point],
),
# spatial_reference=environment_setup.project_spatial_reference,
)
new_lines.append(line)

Expand All @@ -201,19 +203,26 @@ def process_new_lines(new_lines, all_rivers):
"""
# Create an in-memory feature class to hold the new lines
new_lines_feature_class = River_N100.extending_river_geometry__new_lines__n100.value
arcpy.CopyFeatures_management(new_lines, new_lines_feature_class)

# if arcpy.Exists(new_lines_feature_class):
# arcpy.management.Delete(new_lines_feature_class)
#
# arcpy.CreateFeatureclass_management(
# out_path=os.path.dirname(new_lines_feature_class),
# out_name=os.path.basename(new_lines_feature_class),
# geometry_type="POLYLINE",
# spatial_reference=environment_setup.project_spatial_reference,
# xytolerance="0.02 Meters",
# xy_resolution="0.01 Meters",
# )
# arcpy.CopyFeatures_management(new_lines, new_lines_feature_class)

# Check if the feature class already exists, and if so, delete it
if arcpy.Exists(new_lines_feature_class):
arcpy.management.Delete(new_lines_feature_class)

sr = arcpy.Describe(
River_N100.unconnected_river_geometry__unsplit_river_features__n100.value
).spatialReference
# Create a new feature class with the correct spatial reference, resolution, and tolerance
arcpy.CreateFeatureclass_management(
out_path=os.path.dirname(new_lines_feature_class),
out_name=os.path.basename(new_lines_feature_class),
geometry_type="POLYLINE",
spatial_reference=sr,
)
arcpy.management.Append(
inputs=new_lines,
target=new_lines_feature_class,
)

print("Created new lines to the river network")
arcpy.UnsplitLine_management(
Expand Down Expand Up @@ -256,3 +265,9 @@ def process_new_lines(new_lines, all_rivers):

if __name__ == "__main__":
main()


"""
Tested a lot of things regarding the Resolution and Tolerance issues. Current theory is that it is somewhere in
the creation of line in "create_lines_from_coordinates". Or perhaps an issue with the near table itself.
"""
Loading

0 comments on commit 32d5aec

Please sign in to comment.