Skip to content

Commit 4188dbb

Browse files
committed
Adding arcpro ij update script.
1 parent e07b323 commit 4188dbb

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

gis_tools/update_ij.pyt

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import arcpy
2+
import sys, string, os
3+
4+
5+
class Toolbox(object):
6+
def __init__(self):
7+
self.label = "Network Tools"
8+
self.alias = "network tools"
9+
10+
# List of tool classes associated with this toolbox
11+
self.tools = [CalculateSinuosity]
12+
13+
class Update_IJ(object):
14+
def __init__(self):
15+
self.label = "Updating I & J Nodes."
16+
self.description = "Edges and Projects have I and J nodes that are defined " + \
17+
"by the correspoding junction at the end point of each segment. " + \
18+
"Inode is the first node in the sketch and Jnode is the last."
19+
20+
def getParameterInfo(self):
21+
#Define parameter definitions
22+
23+
# Input Features parameter
24+
in_lines = arcpy.Parameter(
25+
displayName="Input Lines",
26+
name="in_lines",
27+
datatype="GPFeatureLayer",
28+
parameterType="Required",
29+
direction="Input")
30+
31+
in_lines.filter.list = ["Polyline"]
32+
33+
# Input Features parameter
34+
in_points = arcpy.Parameter(
35+
displayName="Input Points",
36+
name="in_points",
37+
datatype="GPFeatureLayer",
38+
parameterType="Required",
39+
direction="Input")
40+
41+
in_points.filter.list = ["Points"]
42+
43+
# Sinuosity Field parameter
44+
inode_field = arcpy.Parameter(
45+
displayName="INode Field",
46+
name="inode_field",
47+
datatype="Field",
48+
parameterType="Required",
49+
direction="Input")
50+
inode_field.value = 'Inode'
51+
#param1.filter.list = ['Short', 'Long']
52+
#inode_field.parameterDependencies = [in_lines.name]
53+
54+
55+
56+
# Derived Output Features parameter
57+
# Sinuosity Field parameter
58+
jnode_field = arcpy.Parameter(
59+
displayName="JNode Field",
60+
name="jnode_field",
61+
datatype="Field",
62+
parameterType="Required",
63+
direction="Input")
64+
jnode_field.value = 'Jnode'
65+
#param1.filter.list = ['Short', 'Long']
66+
#jnode_field.parameterDependencies = [in_lines.name]
67+
68+
69+
parameters = [in_lines, in_points, inode_field, jnode_field]
70+
71+
return parameters
72+
73+
def isLicensed(self):
74+
return True
75+
76+
def updateParameters(self, parameters):
77+
if parameters[0].altered:
78+
parameters[2].value = arcpy.ValidateFieldName(parameters[2].value,
79+
parameters[0].value)
80+
parameters[3].value = arcpy.ValidateFieldName(parameters[3].value,
81+
parameters[0].value)
82+
83+
return
84+
85+
def updateMessages(self, parameters):
86+
return
87+
88+
def execute(self, parameters, messages):
89+
line_fc = parameters[0].valueAsText
90+
point_fc = parameters[1].valueAsText
91+
inode_field = parameters[2].valueAsText
92+
jnode_field = parameters[3].valueAsText
93+
94+
arcpy.MakeFeatureLayer_management(line_fc, "line_layer")
95+
96+
lyrDesc = arcpy.da.Describe('line_layer')
97+
workspace = '\\'.join(lyrDesc["path"].split('\\')[:-1])
98+
edit = arcpy.da.Editor(workspace)
99+
edit.startEditing(False, True)
100+
edit.startOperation()
101+
102+
#lineRows = arcpy.da.UpdateCursor("line_layer", [inode_field, jnode_field])
103+
#lineRows = arcpy.UpdateCursor("line_layer")
104+
105+
#lineRows = arcpy.UpdateCursor(line_fc)
106+
#lineRows = arcpy.UpdateCursor("line_layer")
107+
108+
109+
#lineRow = lineRows.next()
110+
# Edit each Line
111+
112+
arcpy.MakeFeatureLayer_management(point_fc, "points_lyr")
113+
with arcpy.da.UpdateCursor("line_layer", ['Shape@', inode_field, jnode_field, "OID@"]) as lineRows:
114+
for lineRow in lineRows:
115+
# Get the Line geometry
116+
from_point = lineRow[0].firstPoint
117+
point_geom = arcpy.PointGeometry(from_point)
118+
arcpy.SelectLayerByLocation_management("points_lyr", "CONTAINS", point_geom)
119+
if int(arcpy.GetCount_management('points_lyr')[0]) == 1:
120+
junction_id = arcpy.da.SearchCursor("points_lyr", "PSRCjunctID").next()[0]
121+
if junction_id != lineRow[1]:
122+
lineRow[1] = junction_id
123+
lineRows.updateRow(lineRow)
124+
else:
125+
126+
lineRow[1] = 0
127+
lineRows.updateRow(lineRow)
128+
arcpy.AddWarning(f"Could not find Inode for ObjectID {lineRow[3]}")
129+
130+
to_point = lineRow[0].lastPoint
131+
point_geom = arcpy.PointGeometry(to_point)
132+
arcpy.SelectLayerByLocation_management("points_lyr", "CONTAINS", point_geom)
133+
if int(arcpy.GetCount_management('points_lyr')[0]) == 1:
134+
junction_id = arcpy.da.SearchCursor("points_lyr", "PSRCjunctID").next()[0]
135+
if junction_id != lineRow[2]:
136+
lineRow[2] = junction_id
137+
lineRows.updateRow(lineRow)
138+
else:
139+
lineRow[2] = 0
140+
lineRows.updateRow(lineRow)
141+
arcpy.AddWarning(f"Could not find Jnode for ObjectID {lineRow[3]}")
142+
143+
#lineRow = lineRows.next()
144+
edit.stopOperation()
145+
146+
# Stop the edit session and save the changes
147+
edit.stopEditing(save_changes=True)
148+
del lineRows
149+
del lineRow
150+
arcpy.AddMessage("Finished")
151+
152+
153+
154+
def postExecute(self, parameters):
155+
return

gis_tools/update_ij.pyt.xml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<metadata xml:lang="en"><Esri><CreaDate>20240127</CreaDate><CreaTime>09032500</CreaTime><ArcGISFormat>1.0</ArcGISFormat><SyncOnce>TRUE</SyncOnce><ModDate>20240128</ModDate><ModTime>141705</ModTime></Esri><toolbox name="update_ij" alias="sinuosity"><arcToolboxHelpPath>d:\program files\arcgis\pro\Resources\Help\gp</arcToolboxHelpPath><toolsets/></toolbox><dataIdInfo><idCitation><resTitle>update_ij</resTitle></idCitation></dataIdInfo><distInfo><distributor><distorFormat><formatName>ArcToolbox Toolbox</formatName></distorFormat></distributor></distInfo></metadata>

0 commit comments

Comments
 (0)