使用 Tastypie 进行距离空间查询

编程入门 行业动态 更新时间:2024-10-17 20:21:33
本文介绍了使用 Tastypie 进行距离空间查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

不确定如何使用带有美味馅饼的 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/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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 09:37:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1407733.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:距离   空间   Tastypie

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!