| 30 | | Schools.objects.geo_near(point=x, radius=1.0) |
| 31 | | Schools.objects.geo_within(bound_box=box) |
| 32 | | }}} |
| | 30 | from django.db import models |
| | 31 | from django.contrib.gis import db as gis_db |
| | 32 | |
| | 33 | class School(meta.Model): |
| | 34 | name = ... |
| | 35 | objects = gis_db.Manager() |
| | 36 | |
| | 37 | Assume a location column has already been added to the DB, e.g. |
| | 38 | select addgeometrycolumn('','schools_school','location',-1, 'POINT', 2); |
| | 39 | |
| | 40 | Then this would work: |
| | 41 | from django.contrib.gis.geometry import Point |
| | 42 | x = Point(-95.36819458007812, 30.2184318620219) |
| | 43 | School.objects.geo_near('location', point=x, radius=1.0) |
| | 44 | |
| | 45 | This could construct a LinearRing approximating the circle around x |
| | 46 | and issue something like: |
| | 47 | |
| | 48 | poly = "POLYGON (...points from curve approximation...)" |
| | 49 | _where.append(""" |
| | 50 | where schools_school.location && %s and |
| | 51 | within(schools_school.location, %s) |
| | 52 | """) |
| | 53 | _params.append(poly, poly)}}} |