Python 身材匀称,把我搞糊涂了

Python 身材匀称,把我搞糊涂了,python,shapely,Python,Shapely,我在获取形状优美的点以实际捕捉线串方面遇到了很多麻烦。例如,能够从地理空间数据构建网络图非常重要。我希望避免使用shapely.ops.snap,因为根据文档,这似乎只是捕捉到线条顶点。相反,我想使用中提出的线性参考技术。对于行字符串中的一个简单点(参见下面的TEST2),这似乎工作得很好,并且断言中的求值为true。然而,我似乎无法使它适用于更复杂的线字符串,即使matplotlib清楚地显示了位于线字符串某处的点 from shapely.wkt import loads from shap

我在获取形状优美的点以实际捕捉线串方面遇到了很多麻烦。例如,能够从地理空间数据构建网络图非常重要。我希望避免使用
shapely.ops.snap
,因为根据文档,这似乎只是捕捉到线条顶点。相反,我想使用中提出的线性参考技术。对于行字符串中的一个简单点(参见下面的TEST2),这似乎工作得很好,并且断言中的
求值为true。然而,我似乎无法使它适用于更复杂的线字符串,即使matplotlib清楚地显示了位于线字符串某处的点

from shapely.wkt import loads
from shapely.geometry import LineString, Point
import matplotlib.pyplot as plt
import geopandas

class Test:
    def __init__(self, point, line):
        self.point = point
        self.line = line
    def snap(self, point, line):
        snapped_point = line.interpolate(line.project(point))
        return snapped_point
    def test(self):
        snapped_point = self.snap(self.point, self.line)
        plt.close()
        fig = plt.figure()
        ax = plt.gca()
        geopandas.GeoDataFrame(geometry=[snapped_point]).plot(ax=ax)
        geopandas.GeoDataFrame(geometry=[ls]).plot(ax=ax)

        return snapped_point.within(self.line)
    def show(self):
        plt.show()

### TEST 1
point = loads('POINT (141508.3132070995 445104.7256057188)')
ls = loads('LINESTRING (141408.7699052179 445535.6376462562, 141420.9609999987 445491.5920000025, 141444.1930000001 445394.7640000023, 141465.3480000009 445299.004, 141486.3999999985 445202.0350000015, 141508.3209999985 445104.6910000004, 141529.2399999978 445006.3560000034, 141550.8399999999 444909.6550000002, 141572.6389999985 444811.9950000045, 141594.0459999999 444713.4210000001, 141614.9339999997 444616.2859999968)')
test1 = Test(point, ls)
print(test1.test())
test1.show()

### TEST 2
point = Point((0.5, 0.46))
ls = LineString([(0,0), (1,1), (2,2)])
test2 = Test(point, ls)
print(test2.test())
test2.show()

为什么第二行字符串检查的值为False?
插值
投影
方法不应该是几何独立的吗

这回答了你的问题吗?这回答了你的问题吗?