我正在尝试在OpenStreetMap对象/建筑物内构造房间。但是我被困在最简单,最快的方法上。到目前为止,我一直在考虑:
我已经成功地使用了pyosmium获得了建筑物的外层和内层,并使用了Polygon函数来使形状整齐:
######################################################
########## RELATION
# Plot inner and outer layer of hospital building
# From RELATION
relation_outer = rel2nod('building', 'hospital', 'w', 'outer') # output is nodes of outer layer
relation_inner = rel2nod('building', 'hospital', 'w', 'inner')
# plot the points
polygons = Polygon(relation_outer[0], relation_inner)
x,y = polygons.exterior.xy
plt.plot(x,y, zorder=1)
然后从其边界框点尝试为网格制作一个矩形框架。
# make rectangular box
bounding = polygons.bounds
minx = bounding[0]
miny = bounding[1]
maxx = bounding[2]
maxy = bounding[3]
chordfish = []
chordfish.append(Point(minx,maxy))
chordfish.append(Point(maxx,maxy))
chordfish.append(Point(minx,miny))
chordfish.append(Point(maxx,miny))
然后使用
object.parallel_offset(距离,侧面)
从形状开始起作用,它取一条直线并将其移位一定距离并平行于其自身。我试图使一条线从其外线平行平移。我的计划是迭代该过程,直到它触及该外线的另一侧。但是由于该功能使用的是地图边界框的原点(0,0)map,因此我无法翻译。 (0,0)building而不是我在封闭建筑物之前制作的盒子的原点。
我希望我的解释很清楚。我还把结果弄清楚了问题所在。 我希望有人知道如何做得更好。因为我陷入了这一步。谢谢您的回应和想法。
# select point of outer layer that touched the bounding box
# make the line defining grid
# with a scale between lines == gap
for n in list(polygons.exterior.coords):
if n[0] == minx:
left_side = n
elif n[0] == maxx:
right_side = n
elif n[1] == miny:
down_side = n
elif n[1] == maxy:
up_side = n
upper_line = LineString([left_side, up_side])
lower_line = LineString([down_side, right_side])
distance_lines = upper_line.distance(lower_line)
gap = distance_lines/grid_horizontal
grid_line_horizontal = [] # make it tuple
for i in range(grid_horizontal):
if i == 0:
grid_line_horizontal.append(upper_line.parallel_offset(gap, 'right'))
else:
grid_line_horizontal.append(grid_line_horizontal[i-1].parallel_offset(gap, 'right'))
x2,y2 = grid_line_horizontal[0].xy
plt.plot(x2, y2, zorder=1)
# plotting
for cor in chordfish:
plt.plot(cor.x, cor.y, 'o')
#plt.show()
mplleaflet.show()
结果: