-
Notifications
You must be signed in to change notification settings - Fork 1
/
WSEL_Intersects_Clean.py
92 lines (77 loc) · 3.87 KB
/
WSEL_Intersects_Clean.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from __future__ import print_function
import sys, os, re, arcpy
from arcpy import env
from safe_print import Safe_Print
class WSEL_Intersects_Clean:
def __init__(self, config):
self.config = config
def __enter__(self):
self.scratchgdb = self.config['scratchgdb']
self.xs_original = self.config['xs_original']
self.xs_dataset = self.config['xs_dataset']
self.streams_original = self.config['streams_original']
self.xs_intersect_dataset = self.config['xs_intersect_dataset']
self.streams_intersect_dataset = self.config['streams_intersect_dataset']
self.routes_dataset = self.config['routes_dataset']
self.streams_dataset = self.config['streams_dataset']
self.vertices_dataset = self.config['vertices_dataset']
self.multi=self.config['multiproc']
self.modelbuilder=self.config['modelbuilder']
self.print_config = {'multi': self.multi, 'modelbuilder': self.modelbuilder}
self.safe_print = Safe_Print(self.print_config)
env.workspace = self.scratchgdb
env.overwriteOutput = True
env.MResolution = 0.0001
env.MDomain = "0 10000000"
env.outputMFlag = "Enabled"
env.outputZFlag = "Enabled"
return self
def __exit__(self, type, value, traceback):
return
def remove_duplicate_pts(self, stream_intersects):
self.safe_print.print_out("Removing duplicate intersection points keeping ones with higher WSEL")
tempLayer = "intersectLayer"
expression = """ "Route_ID_1"='Delete' """
expression2 = "[Route_ID]"
expression3 = "[Route_ID_1]"
expression4 = "[POINT_M]"
keep_fields=['SHAPE', 'OBJECTID', 'Route_ID', 'Intersects','WSEL', 'Station','strm_length']
comb_intersect = stream_intersects
compare =[]
fields = [f.name for f in arcpy.ListFields(comb_intersect)]
cursor = arcpy.SearchCursor(comb_intersect, ['Route_ID','Route_ID_1','strm_length'])
for row in cursor:
compare.append([row.getValue('Route_ID'),row.getValue('Route_ID_1'),row.getValue('strm_length')])
del row
del cursor
cursor = arcpy.UpdateCursor(comb_intersect,['Route_ID','Route_ID_1','strm_length'])
for row in cursor:
intersect = row.getValue('Route_ID_1')
intersect_stream = row.getValue('Route_ID')
intersect_length = int(row.getValue('strm_length'))
for strm in compare:
stream = strm[1]
stream_name = strm[0]
stream_length = int(strm[2])
if intersect == stream_name and intersect_stream == stream and intersect_length < stream_length:
row.setValue("Route_ID_1","Delete")
cursor.updateRow(row)
del row
del cursor
arcpy.AddField_management(comb_intersect,"Intersects","TEXT","","",50)
arcpy.AddField_management(comb_intersect,'Station',"FLOAT",10,3)
arcpy.CalculateField_management(comb_intersect, "Intersects", expression2, "VB")
arcpy.CalculateField_management(comb_intersect, "Route_ID", expression3, "VB")
arcpy.CalculateField_management(comb_intersect, "Station", expression4, "VB")
arcpy.MakeFeatureLayer_management(comb_intersect, tempLayer)
arcpy.SelectLayerByAttribute_management(tempLayer, "NEW_SELECTION",expression)
if int(arcpy.GetCount_management(tempLayer).getOutput(0)) > 0:
arcpy.DeleteFeatures_management(tempLayer)
fields = [f.name for f in arcpy.ListFields(comb_intersect) if not f.required and f.name not in keep_fields ]
arcpy.DeleteField_management(comb_intersect, fields)
return
def processStream(self):
self.warnings=[]
comb_intersect = self.scratchgdb+'\\streams_intersect_all_1'
self.remove_duplicate_pts(comb_intersect)
return