ero*_*ros 3 python postgresql postgis geodjango
我正在使用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)))
但不知道如何准备参数和变量.
und*_*ark 10
通常,这种查询的最佳PostGIS函数是ST_DWithin():
如果几何在彼此的指定距离内,则返回true.
例如.所有居住在距离商店#1 1000米范围内的客户:
SELECT customers.*
FROM customers, shops
WHERE ST_DWithin(customers.the_geog, shops.the_geog, 1000)
AND shop.id = 1
Run Code Online (Sandbox Code Playgroud)
ST_DWithin将使用您应该创建的空间索引,因此优于ST_Distance.
在Django中似乎有一个名为dwithin的相应过滤器:
返回模型,其中查找几何体与几何体字段的距离在彼此给定的距离内.
Run Code Online (Sandbox Code Playgroud)Zipcode.objects.filter(poly__dwithin=(geom, D(m=5))) Backend SQL Equivalent PostGIS ST_DWithin(poly, geom, 5)
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))')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2232 次 |
最近记录: |