-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chainager.py
43 lines (40 loc) · 1.98 KB
/
Chainager.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
import arcpy
mxd = arcpy.mapping.MapDocument(r"D:\ArcGIS projects\MXD\Chainager.mxd")
dataframe_Layers = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0]
lines = arcpy.mapping.ListLayers(mxd, "Pipeline", dataframe_Layers)[0]
points = arcpy.mapping.ListLayers(mxd, "Points_from_building_footprint", dataframe_Layers)[0]
# Run the Copy Features tool, setting the output to the geometry object.
# geometries is returned as a list of geometry objects.
geometries = arcpy.CopyFeatures_management(lines,arcpy.Geometry())
length = 0
with arcpy.da.SearchCursor(points, ['Pipe_id','SHAPE@XY']) as cursor:
for row in cursor:
coordX = row[1][0]
coordY = row[1][1]
for geometry in geometries:
length = geometry.measureOnLine(arcpy.Point(coordX, coordY))
lengthRoundsplit = str(round(length)).split(".")[0]
points.definitionQuery = "Pipe_id=" +"'"+row[0]+"'"
with arcpy.da.UpdateCursor(points,'Chainage') as cursor:
for row in cursor:
if len(lengthRoundsplit) == 1:
chainage = "0"+"+"+"0"+"0" + lengthRoundsplit
print chainage
row[0] = chainage
if len(lengthRoundsplit) == 2:
chainage = "0"+"+"+"0"+lengthRoundsplit
print chainage
row[0] = chainage
if len(lengthRoundsplit) == 3:
chainage = "0"+"+"+lengthRoundsplit
print chainage
row[0] = chainage
if len(lengthRoundsplit) >= 4:
constantVar = len(lengthRoundsplit) - 3
chainage = lengthRoundsplit[:constantVar] + "+" + lengthRoundsplit[constantVar:]
print chainage
row[0] = chainage
cursor.updateRow(row)
points.definitionQuery = None
del cursor
del mxd