使用 Tastypie 进行距离空间查询 [英] Distance Spatial Queries with Tastypie

查看:32
本文介绍了使用 Tastypie 进行距离空间查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定如何使用带有美味馅饼的 distance_lte 空间过滤器.我可以使用 contains 空间过滤器,但我无法弄清楚 distance_lte 过滤器的格式.

Not sure how to use distance_lte spatial filters with tasty-pie. I can use the contains spatial filter i am unable to figure out the format for the distance_lte filter.

这是我尝试过的:

http://www.domain.com/myapp/api/v1/location/?format=json&coord__distance_lte={"type": "Point", "coordinates": [153.09537, -27.52618]},D(m=5)

返回{"error": "提供的资源查找数据无效(类型不匹配)."}

推荐答案

这是因为 Tastypie 错误地使用 querysets query.query_terms 属性寻找有效过滤器

This is because Tastypie erroneously looks for valid filters using the querysets query.query_terms attributes

它不会包含距离",因此您会得到错误.

It won't contain 'distance', and as a result you get the error.

除了包含之外,TastyPie 在这些 GIS 搜索中几乎没有任何功能(至少没有添加您自己的特殊调味料.)

Except for contains, TastyPie is mostly non-functional with these GIS searches (at least without adding in your own special sauce.)

例如,您可以通过覆盖 build_filters 并将距离"添加到有效过滤器集来使距离起作用:

You could make distance work, for example, by overriding build_filters and adding 'distance' to the valid set of filters:

def build_filters(self, filters=None):
   '''
   Add in some filters so spatial queries will work.
   '''
   self._meta.queryset.query.query_terms.update(set(['distance','distance_lte']))
   return super(MyResource, self).build_filters(filters)

之后文档开始变得正确,关于您如何将 WKT 和/或 GeoJSON 作为获取参数传递.

After which the documentation starts to become correct in regard to how you pass in WKT and/or GeoJSON as get parameters.

这篇关于使用 Tastypie 进行距离空间查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆