2014-01-22 46 views
2

我试图使用shapely的“内”功能来做一个线串和一个点文件的'空间连接'(fyi - 点文件是使用插值函数生成的线串)。问题是 - 什么都没有被返回。确定整形点是否在一个线串/多线串

我错过了什么?

    for x in range(1, numIntervals): 
        newPt = s.interpolate(interval * x) 
        ## this print statement confirms that the shapely point objects work 
        ## and are being made 
        print newPt 

        ## all things fail within the if/write statement 
        if newPt.within(shape(i['geometry'])): 
         newPt['properties'] = i['properties'] 
         e.write({'geometry':mapping(newPt),'properties':i['properties']}) 

NOTES: 

i = {'geometry': {'type': 'LineString', 'coordinates': [(-9765787.998118492, 5488940.974948905), (-9748582.801636808, 5488402.127570709)]}, 'type': 'Feature', 'id': '0', 'properties': OrderedDict([(u'gid', 3)])} 

newPt = POINT (-9763788.9782693591000000 5488878.3678984242000000) 

回答

6

有浮点精度误差发现线路上的点的时候。改为使用具有适当阈值的距离。

from shapely.geometry import Point, LineString 

line = LineString([(-9765787.9981184918, 5488940.9749489054), (-9748582.8016368076, 5488402.1275707092)]) 
point = Point(-9763788.9782693591, 5488878.3678984242) 

line.within(point) # False 
line.distance(point) # 7.765244949417793e-11 
line.distance(point) < 1e-8 # True 
+0

嗨。我们如何才能选择适当的门槛呢?我面临同样的问题,只有当我选择1e-4时,它才适用于我。我们应该选择什么基础?我正在使用wgs84纬度长点 –

+0

我的意思是对于某行,当我使用<1e-4和一些1e-3时,line.distance(point)返回true。这是否意味着,我必须计算点和数据集中所有行之间的距离,并采用最小距离的点?有没有其他有效的方法呢? –

+0

@ds_user这实际上取决于你如何获得数据,或者它代表了什么样的分辨率(例如见[十进制度](https://en.wikipedia.org/wiki/Decimal_degrees))。您需要检查GIS中未投影的数据,以获得您的案例中的想法。 –

相关问题