在Geodjango + Postgres中存储一个圈子 [英] Store a Circle in Geodjango + Postgres

查看:197
本文介绍了在Geodjango + Postgres中存储一个圈子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要在geodjango字段中存储一个圆圈,所以我可以使用geodjango查询__contains来查找一个点是否在圆圈中(类似于使用PolygonField可以做的)。

Looking to store a circle in a geodjango field so I can use the geodjango query __contains to find out if a point is in the circle (similar to what can be done with a PolygonField).

目前将其存储为十进制半径和GeoDjango点字段,但需要一种查询数据库中某个位置列表的方法,以使这些变化的圆(点域和半径)包含我的搜索点/ lat)。

Currently have it stored as a Decimal radius and GeoDjango Point Field, but need a way to query a list of locations in the DB such that these varying circles (point field and radii) contain my search point (long/lat).

希望是有道理的。

推荐答案

PostGIS支持 CurvePolygon CircularString 几何类型,可用于存储曲面几何。例如,x = 10,y = 10的2单位半径已被64点缓冲多边形近似为:

Technically speaking, PostGIS supports CurvePolygon and CircularString geometry types, which can be used to store curved geometries. For example, a 2-unit radius around x=10, y=10 that has been approximated by a 64-point buffered polygon is:

SELECT ST_AsText(ST_LineToCurve(ST_Buffer(ST_MakePoint(10, 10), 2, 16)));
                   st_astext
------------------------------------------------
 CURVEPOLYGON(CIRCULARSTRING(12 10,8 10,12 10))
(1 row)

但是,这种方法通常不会完成,因为对这种几何类型的支持非常有限(即 ST_AsSVG ,以及别人不行)。这些几何类型可能会导致很多的悲伤,我建议不要这样做。

However, this approach is not typically done, as there is very limited support for this geometry type (i.e., ST_AsSVG, and others won't work). These geometry types will likely cause plenty of grief, and I'd recommend not doing this.

通常,所有几何体都存储为一种良好支持的类型: POINT LINESTRING POLYGON (可选 MULTI - prefix)。使用这些类型,请使用 ST_DWithin 函数(例如, GeoDjango 调用此__dwithin,另请参阅此问题)来查询是否另一个几何在一定距离内。例如,如果您有点位置,您可以从点了解其他几何是否在一定距离内(即,半径)。

Typically, all geometries are stored as a well supported type: POINT, LINESTRING or POLYGON (with optional MULTI- prefix). With these types, use the ST_DWithin function (e.g., GeoDjango calls this __dwithin, see also this question) to query if another geometry is within a specified distance. For example, if you have a point location, you can see if other geometries are within a certain distance (i.e., radius) from the point.

这篇关于在Geodjango + Postgres中存储一个圈子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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