获取所有包含点的线


12

我使用QGIS,并且拥有一个点和道路网络。我需要自动提取包围特​​定点的道路名称。在此处输入图片说明 最近的邻居分析和缓冲区无法完成这项工作,因为在许多情况下,根据测量距离,该点更接近邻居道路而不是封闭道路。是否有关于仅提取封闭道路的想法?


6
也许将封闭区域(由一系列线组成)转换为多边形,并具有构成多边形墙的道路的属性-然后您可以通过重叠位置进行简单选择。在此示例中,点“ 145699”落在多边形“ roada_roadb_roadc_roadd”内。
地图人

Answers:


3

关于我的测试数据:

  1. 像OSM道路数据一样,每条道路几何图形都在十字路口结束。
  2. 每条道路都有唯一的ID。

解决方案一

如果有两个假设:

  1. 道路是住宅区。

  2. 您正在使用公制系统。

这个想法是增加/减少点的X和Y坐标。如果您在公制系统内工作,则可以向您的点以东1m处,创建一个新点,并用原始点创建一条线。您将向东走,直到线与一条道路相交。要在西部寻找相交点,必须从原始X坐标减去1m。Y坐标相同。如果在北/东/南/西没有路,则计数器在1000(m)处停止。当您知道一条距离超过1000m的道路时,您必须更改此值。

您可以使用以下代码解决该任务:

已编辑

for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
    if lyr.name() == "point":
        startpoint = lyr

for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
    if lyr.name() == "roads":
        roads = lyr

startpoint_iter = startpoint.getFeatures()
for feature in startpoint_iter:
    geom = feature.geometry()
    if geom.type() == QGis.Point:
        xy = geom.asPoint()
        x,y = xy[0], xy[1]

line_start = QgsPoint(x,y)      

def reached(direction, count_m):
    road_reached = None
    road = None
    count=1
    while road_reached < 1 and count <=count_m:
        count += 1
        if direction == 'N':
            line_end = QgsPoint(x, y+count)
        if direction == 'E':
            line_end = QgsPoint(x+count,y)
        if direction == 'S':
            line_end = QgsPoint(x,y-count)
        if direction == 'W':
            line_end = QgsPoint(x-count,y)
        line = QgsGeometry.fromPolyline([line_start,line_end])
        for f in roads.getFeatures():
            if line.intersects(f.geometry()):
                road_reached = 1
                road = f['name']
                print road

reached('N', 1000)
reached('E', 1000)
reached('S', 1000)
reached('W', 1000)

另一个例子表明,东部的道路e没有被识别为该点附近的道路。

在此处输入图片说明

如何调用函数和输出:

>>>>reached('N', 1000)
road a
>>>>reached('E', 1000)
road b
>>>>reached('S', 1000)
road c
>>>>reached('W', 1000)
road d

如果封闭点的道路超过4条,则您必须朝更多方向看(同时更改X和Y)。或者,您可以更改线的方位角,这意味着您可以在0-360°范围内将其旋转1度。

解决方案二

从评论中得到启发,您也Polygonize可以先走道路。因此,您可以使用QGIS中的工具:Processing > Toolbox > QGIS geoalgorithms > Vector geometry tools > Polygonize。重命名临时层为polygon。假设您只想拥有完全被道路包围的点的道路名称。否则,您必须使用解我。仅在所有道路都已连接(捕捉)的情况下才有效!

在此处输入图片说明

首先,该点必须与多边形相交。现在的想法是,AND封闭线的两个起点都必须与多边形相交。

for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
    if lyr.name() == "point":
        startpoint = lyr

for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
    if lyr.name() == "polygon":
        poly = lyr

for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
    if lyr.name() == "roads":
        roads = lyr

for h in startpoint.getFeatures():
    for g in poly.getFeatures():
        if h.geometry().intersects(g.geometry()):
            poly_geom = g.geometry()
            for f in roads.getFeatures():
                geom = f.geometry().asPolyline()
                start_point = QgsGeometry.fromPoint(QgsPoint(geom[0]))
                end_point = QgsGeometry.fromPoint(QgsPoint(geom[-1]))
                if poly_geom.intersects(start_point) and poly_geom.intersects(end_point):
                    print f['name']

输出:

road c
road b
road e
road f
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.