/
rural_draw_cross_section_locations.py
132 lines (105 loc) · 4.12 KB
/
rural_draw_cross_section_locations.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# (c) Nelen & Schuurmans. GPL licensed, see LICENSE.txt
# -*- coding: utf-8 -*-
import logging
import sys
import os
import traceback
from turtlebase.logutils import LoggingConfig
from turtlebase import mainutils
import nens.gp
import turtlebase.network
log = logging.getLogger(__name__)
import arcgisscripting
gp = arcgisscripting.create()
def read_lines(gp, line_fc, ident=None):
"""
"""
points = {}
inDesc = gp.describe(line_fc)
row = gp.SearchCursor(line_fc)
id_int = 0
for item in nens.gp.gp_iterator(row):
feat = item.GetValue(inDesc.ShapeFieldName)
shape_length = feat.length
if ident is None:
item_id = id_int
id_int += 1
else:
item_id = item.GetValue(ident)
part = feat.getpart(0)
pnt_list = [(float(pnt.x), float(pnt.y)) for pnt in nens.gp.gp_iterator(part)]
points[(item_id, shape_length)] = pnt_list
return points
def calculate_sp(percentage, max_d, lengte, points):
x = 0
d = float(percentage) * float(lengte)
if float(d) > float(max_d):
d = float(max_d)
dist_first = turtlebase.network.distance(points[x], points[x + 1])
while dist_first < d:
d -= dist_first
x += 1
dist_first = turtlebase.network.distance(points[x], points[x + 1])
XY = turtlebase.network.create_station_point(points[x], points[x + 1], d)
return XY
def main():
try:
gp = mainutils.create_geoprocessor()
config = mainutils.read_config(__file__, 'turtle-settings.ini')
logfile = mainutils.log_filename(config)
logging_config = LoggingConfig(gp, logfile=logfile)
mainutils.log_header(__name__)
#---------------------------------------------------------------------
# Input parameters
if len(sys.argv) == 5:
input_watergangen = sys.argv[1]
procent = sys.argv[2]
max_distance = sys.argv[3]
output_profiles = sys.argv[4]
else:
log.warning("usage: <input_watergangen> <procent> <max_distance> <output_profiles>")
sys.exit(1)
percentage = float(procent) / 100
gp.CreateFeatureclass_management(os.path.dirname(output_profiles), os.path.basename(output_profiles), "POINT")
gp.AddField_management(output_profiles, "LOCIDENT", "TEXT")
gp.AddField_management(output_profiles, "PROIDENT", "TEXT")
in_rows = gp.SearchCursor(input_watergangen)
in_row = in_rows.Next()
out_rows = gp.InsertCursor(output_profiles)
pnt = gp.CreateObject("Point")
inDesc = gp.describe(input_watergangen)
log.info("draw profiles")
while in_row:
ident = in_row.GetValue("OVKIDENT")
log.info("- %s" % ident)
feat = in_row.GetValue(inDesc.ShapeFieldName)
lengte = feat.length
part = feat.getpart(0)
pnt_list = [(float(pnt.x), float(pnt.y)) for pnt in nens.gp.gp_iterator(part)]
XY = calculate_sp(percentage, max_distance, lengte, pnt_list)
pnt.X = XY[0]
pnt.Y = XY[1]
out_row = out_rows.newRow()
out_row.shape = pnt
out_row.setValue("PROIDENT", ident)
out_row.setValue("LOCIDENT", "%s_a" % ident)
out_rows.insertRow(out_row)
pnt_list.reverse()
XY = calculate_sp(percentage, max_distance, lengte, pnt_list)
pnt.X = XY[0]
pnt.Y = XY[1]
out_row = out_rows.newRow()
out_row.shape = pnt
out_row.setValue("PROIDENT", ident)
out_row.setValue("LOCIDENT", "%s_b" % ident)
out_rows.insertRow(out_row)
in_row = in_rows.Next()
del out_rows
del in_rows
mainutils.log_footer()
except:
log.error(traceback.format_exc())
sys.exit(1)
finally:
logging_config.cleanup()
del gp