微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python – 如何在5米的距离内查询我的所有数据?

我正在使用GeoDjango和PostGIS.然后我在如何查询我的postgres数据库表以获取5米范围内的所有数据时遇到麻烦.

UPDATES1
我正在使用GeoDjango 1.2.7

我从这个网址https://docs.djangoproject.com/en/dev/ref/contrib/gis/geoquerysets/#std:fieldlookup-distance_lte找到了一些东西

Zipcode.objects.filter(poly__distance_lte =(geom,D(* m * = 5)))

但不知道如何准备参数和变量.

>什么是poly_distance_lte?是一个功能
>什么是geom?是一个变量?怎么创造它?
>什么是D?是一个功能?如果是,m是D函数的参数名称

解决方法:

通常,此类查询的最佳PostGIS功能ST_DWithin()

Returns true if the geometries are within the specified distance of one another.

例如.所有居住在距离商店#1 1000米范围内的客户:

SELECT customers.* 
FROM customers, shops
WHERE ST_DWithin(customers.the_geog, shops.the_geog, 1000)
  AND shop.id = 1

ST_DWithin将使用您应该创建的空间索引,因此优于ST_distance.

在Django中似乎有一个名为dwithin的相应过滤器:

Returns models where the distance to the geometry field from the lookup geometry are within the given distance from one another.

06001

D(m = 5)返回长度为5米的距离物体

geom是要从中计算Zipcode对象距离的几何体

dwithin()是使用的函数

poly是Zipcode对象的几何属性

z = Zipcode(code=77096, poly='polyGON(( 10 10, 10 20, 20 20, 20 15, 10 10))')

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐