在路线附近寻找属性(线串)

问题描述 投票:0回答:1

基本上,我想知道是否有办法使用postgis查询django中靠近线串的地理区域的所有对象。我正在计算一条路线,并希望找到大致在该路线上的物体(比如距线绳2m - 10m的最大距离)。我无法在网上找到解决这个问题的方法。

当然,我可以在2m的路线周围创建一个间隔,然后使用这些间隔创建一个多边形,并检查哪些点落在这个创建的表面内,但我想知道是否有更直接的方法(我上面描述的方式) )。

这是我第一次描述的方法的一些psu代码(这是我想要的)

def get_objects_on_route():
    Model.objects.filter(geo_location__some_lookup=all_points_in_route_route, max_distance=2m)

我可以实现的其他方法

def get_objects_on_route():
points_in_surface = []
for each element in route:
    points_in_surface.append(two_corrected_points)
poly= Polygon(all_points_on_route)
Model.objects.filter(geo_location__covered_by=poly)
python django postgis geodjango
1个回答
0
投票

事实证明,通过创建LineString对象而不是Point,您可以使用Django的PostGIS过滤轻松进行此类查询。

from django.contrib.gis.geos import LineString

line = LineString(*coords_in_route)
Model.object.filter(geo_location__distance_lte=(line, D(m=2)))

我测试了它,似乎工作正常:

map with points along a route highlighred

© www.soinside.com 2019 - 2024. All rights reserved.