【发布时间】:2020-12-01 13:23:32
【问题描述】:
我有两个功能。其中一个返回一个列表,其中包含来自输入值的坐标子列表。另一个将这些坐标周围的缓冲区作为字典返回。我想简化这些功能,并可能以某种方式将它们组合起来。
buffer = 300
def coordinates(k_leht):
x1 = int(k_leht[-3:]) * 1000
y1 = int(k_leht[:3]) * 1000 + 6000000
x2 = x1 + 1000
y2 = y1 + 1000
return [[x1, y1], [x2, y1], [x2, y2], [x1, y2], [x1, y1]]
def coordinates_buffer(k_leht):
# Coordinates are created the same way as in the previous function
x1 = int(k_leht[-3:]) * 1000
y1 = int(k_leht[:3]) * 1000 + 6000000
x2 = x1 + 1000
y2 = y1 + 1000
# Buffers around the coordinates
x1_puhv = x1 - buffer
y1_puhv = y1 - buffer
x2_puhv = x2 + buffer
y2_puhv = y2 + buffer
return {'x1_puhv': x1_puhv, 'y1_puhv': y1_puhv, 'x2_puhv': x2_puhv, 'y2_puhv': y2_puhv}
【问题讨论】:
-
只需将前几行分解成一个返回 x1、y1、x2、y2 的
extract_coordinates函数?然后删除重复的部分并通过调用extract_coordinates(k_leht)替换它们。
标签: python coordinates gis