我仍然是Python的新手。我正在进行一个项目,在税图上绘制我们县内的建筑物足迹。
我找到了一个可能对此项目非常有用的上一个问题:https://gis.stackexchange.com/questions/6724/creating-line-of-varying-distance-from-origin-point-using-python-in-arcgis-deskt
我们的Cama系统生成包含所需信息的视图/表格。以下是一个例子:
PARID LLINE VECT X_COORD Y_COORD
1016649 0 R59D26L39U9L20U17 482547 1710874
180,59,270,26,0,39,90,9,0,20,90,17 (VECT column converted)
我找到了一些python示例来转换VECT列,它们是用逗号分隔的角度和距离的距离和方向调用。
我的问题: 有没有办法在下面的脚本中实现一个循环来利用表而不是静态的,用户输入的数字?这对县来说非常有价值,因为我们有数千个多边形要建造。
以下是将距离和角度更改为在ArcMap 10.2中生成的x,y点的代码段
#Using trig to deflect from a starting point
import arcpy
from math import radians, sin, cos
origin_x, origin_y = (400460.99, 135836.7)
distance = 800
angle = 15 # in degrees
# calculate offsets with light trig
(disp_x, disp_y) = (distance * sin(radians(angle)),\
distance * cos(radians(angle)))
(end_x, end_y) = (origin_x + disp_x, origin_y + disp_y)
output = "offset-line.shp"
arcpy.CreateFeatureClass_management("c:\workspace", output, "Polyline")
cur = arcpy.InsertCursor(output)
lineArray = arcpy.Array()
# start point
start = arcpy.Point()
(start.ID, start.X, start.Y) = (1, origin_x, origin_y)
lineArray.add(start)
# end point
end = arcpy.Point()
(end.ID, end.X, end.Y) = (2, end_x, end_y)
lineArray.add(end)
# write our fancy feature to the shapefile
feat = cur.newRow()
feat.shape = lineArray
cur.insertRow(feat)
# yes, this shouldn't really be necessary...
lineArray.removeAll()
del cur
任何建议都将不胜感激。
感谢您宝贵的时间和知识。
答案 0 :(得分:1)
您可以从给定的表创建一个字典字典,该字典将包含所有不同的值。如
d = {1:{"x":400460.99,"y":135836.7,"distance":800,"angle":15},
2:{"x":"etc","y":"etc","distance":"etc","angle":"etc"}}
for k in d.keys():
origin_x, d[k]["x"]
origin_y = d[k]["y"]
distance = d[k]["distance"]
angle = d[k]["angle"]
#rest of the code
#.....