Django

Code

root/django/branches/gis/django/contrib/gis/tests/distapp/models.py

Revision 7641, 1.5 kB (checked in by jbronn, 7 months ago)

gis: Refactor of the GeoQuerySet; new features include:

(1) Creation of internal API that eases generation of GeoQuerySet methods.
(2) GeoQuerySet.distance now returns Distance objects instead of floats.
(3) Added the new GeoQuerySet methods: area, centroid, difference, envelope, intersection, length, make_line, mem_size, num_geom, num_points, perimeter, point_on_surface, scale, svg, sym_difference, translate, union.
(4) The model_att keyword may be used to customize the attribute that GeoQuerySet methods attach output to.
(5) Geographic distance lookups and GeoQuerySet.distance calls now use ST_distance_sphere by default (performance benefits far outweigh small loss in accuracy); ST_distance_spheroid may still be used by specifying an option.
(6) GeoQuerySet methods may now operate accross ForeignKey? relations specified via the field_name keyword (but this does not work on Oracle).
(7) Area now has the same units of measure as Distance.

Backward Incompatibilites:

  • The aggregate union method is now known as unionagg.
  • The field_name keyword used for GeoQuerySet methods may no longer be specified via positional arguments.
  • Distance objects returned instead of floats from GeoQuerySet.distance.
  • ST_Distance_sphere used by default for geographic distance calculations.
Line 
1 from django.contrib.gis.db import models
2
3 class SouthTexasCity(models.Model):
4     "City model on projected coordinate system for South Texas."
5     name = models.CharField(max_length=30)
6     point = models.PointField(srid=32140)
7     objects = models.GeoManager()
8     def __unicode__(self): return self.name
9
10 class SouthTexasCityFt(models.Model):
11     "Same City model as above, but U.S. survey feet are the units."
12     name = models.CharField(max_length=30)
13     point = models.PointField(srid=2278)
14     objects = models.GeoManager()
15     def __unicode__(self): return self.name
16
17 class AustraliaCity(models.Model):
18     "City model for Australia, using WGS84."
19     name = models.CharField(max_length=30)
20     point = models.PointField()
21     objects = models.GeoManager()
22     def __unicode__(self): return self.name
23
24 class CensusZipcode(models.Model):
25     "Model for a few South Texas ZIP codes (in original Census NAD83)."
26     name = models.CharField(max_length=5)
27     poly = models.PolygonField(srid=4269)
28     objects = models.GeoManager()
29
30 class SouthTexasZipcode(models.Model):
31     "Model for a few South Texas ZIP codes."
32     name = models.CharField(max_length=5)
33     poly = models.PolygonField(srid=32140)
34     objects = models.GeoManager()
35     def __unicode__(self): return self.name
36
37 class Interstate(models.Model):
38     "Geodetic model for U.S. Interstates."
39     name = models.CharField(max_length=10)
40     line = models.LineStringField()
41     objects = models.GeoManager()
42     def __unicode__(self): return self.name
Note: See TracBrowser for help on using the browser.