2008-08-06 02:13:06 +08:00
|
|
|
from django.contrib.gis.db import models
|
2009-03-31 01:15:49 +08:00
|
|
|
from django.contrib.gis.tests.utils import mysql, spatialite
|
2012-08-12 18:32:08 +08:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2008-08-06 02:13:06 +08:00
|
|
|
|
|
|
|
# MySQL spatial indices can't handle NULL geometries.
|
|
|
|
null_flag = not mysql
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-08-06 02:13:06 +08:00
|
|
|
class Country(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
2013-11-03 05:02:56 +08:00
|
|
|
mpoly = models.MultiPolygonField() # SRID, by default, is 4326
|
2008-08-06 02:13:06 +08:00
|
|
|
objects = models.GeoManager()
|
2013-10-17 16:17:41 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-08-06 02:13:06 +08:00
|
|
|
class City(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
2009-03-31 01:15:49 +08:00
|
|
|
point = models.PointField()
|
2008-08-06 02:13:06 +08:00
|
|
|
objects = models.GeoManager()
|
2013-10-17 16:17:41 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2008-11-06 01:51:11 +08:00
|
|
|
# This is an inherited model from City
|
|
|
|
class PennsylvaniaCity(City):
|
|
|
|
county = models.CharField(max_length=30)
|
2011-09-10 06:34:23 +08:00
|
|
|
founded = models.DateTimeField(null=True)
|
2013-11-03 05:02:56 +08:00
|
|
|
objects = models.GeoManager() # TODO: This should be implicitly inherited.
|
2008-11-06 01:51:11 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-08-06 02:13:06 +08:00
|
|
|
class State(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
2013-11-03 05:02:56 +08:00
|
|
|
poly = models.PolygonField(null=null_flag) # Allowing NULL geometries here.
|
2008-08-06 02:13:06 +08:00
|
|
|
objects = models.GeoManager()
|
2013-10-17 16:17:41 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-01-29 10:20:58 +08:00
|
|
|
class Track(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
line = models.LineStringField()
|
|
|
|
objects = models.GeoManager()
|
2013-10-17 16:17:41 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2010-01-29 10:20:58 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2012-03-03 06:32:22 +08:00
|
|
|
class Truth(models.Model):
|
2013-08-12 04:19:09 +08:00
|
|
|
val = models.BooleanField(default=False)
|
2012-03-03 06:32:22 +08:00
|
|
|
objects = models.GeoManager()
|
|
|
|
|
2009-03-31 01:15:49 +08:00
|
|
|
if not spatialite:
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-03-31 01:15:49 +08:00
|
|
|
class Feature(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
geom = models.GeometryField()
|
|
|
|
objects = models.GeoManager()
|
2013-10-17 16:17:41 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2009-03-31 01:15:49 +08:00
|
|
|
class MinusOneSRID(models.Model):
|
2013-11-03 05:02:56 +08:00
|
|
|
geom = models.PointField(srid=-1) # Minus one SRID.
|
2009-03-31 01:15:49 +08:00
|
|
|
objects = models.GeoManager()
|