3

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).

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).

Hope it makes sense.

pmah
  • 157
  • 1
  • 2
  • 8
  • if circle Equation is (X-H)square2+(Y-K)square2=Rsquare2. If (H,K) are GeoDjango pointField and R is decimal and all these circles are stored in DB. if I query with search point(A,B) i should able to tell Which Circle it will fall in my DB. – dilip kumbham Jun 08 '12 at 06:07
  • Is same as http://stackoverflow.com/questions/1627520/find-points-that-are-within-a-circle-given-center-and-radius – dilip kumbham Jun 08 '12 at 06:20
  • Not quite sure if I'd use 'contains' for this type of logic. Your circle will have a centre point and a radius... the logic 'where distance between a point and centre of circle is less than radius' should work instead of a 'contains'. – Twelfth Jun 08 '12 at 21:02

1 Answers1

2

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)

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.

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.

Community
  • 1
  • 1
Mike T
  • 41,085
  • 18
  • 152
  • 203