2008-08-05 18:13:06 +00:00
|
|
|
from django.contrib.gis.db import models
|
2012-08-12 10:32:08 +00:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2008-08-05 18:13:06 +00:00
|
|
|
|
2015-02-10 15:07:44 +00:00
|
|
|
from ..utils import gisfield_may_be_null
|
|
|
|
|
2013-11-02 20:12:09 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2014-01-01 10:01:46 +00:00
|
|
|
class NamedModel(models.Model):
|
2008-08-05 18:13:06 +00:00
|
|
|
name = models.CharField(max_length=30)
|
2014-01-01 10:01:46 +00:00
|
|
|
|
2008-08-05 18:13:06 +00:00
|
|
|
objects = models.GeoManager()
|
2013-10-17 08:17:41 +00:00
|
|
|
|
2014-01-01 10:01:46 +00:00
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2013-10-17 08:17:41 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2008-08-05 18:13:06 +00:00
|
|
|
|
2014-01-01 17:37:52 +00:00
|
|
|
|
2014-01-01 10:01:46 +00:00
|
|
|
class Country(NamedModel):
|
|
|
|
mpoly = models.MultiPolygonField() # SRID, by default, is 4326
|
2013-11-02 20:12:09 +00:00
|
|
|
|
2013-10-17 08:17:41 +00:00
|
|
|
|
2014-01-01 10:01:46 +00:00
|
|
|
class City(NamedModel):
|
|
|
|
point = models.PointField()
|
2008-08-05 18:13:06 +00:00
|
|
|
|
2015-03-21 15:59:30 +00:00
|
|
|
class Meta:
|
|
|
|
app_label = 'geoapp'
|
|
|
|
|
2013-11-02 20:12:09 +00:00
|
|
|
|
2008-11-05 17:51:11 +00:00
|
|
|
# This is an inherited model from City
|
|
|
|
class PennsylvaniaCity(City):
|
|
|
|
county = models.CharField(max_length=30)
|
2011-09-09 22:34:23 +00:00
|
|
|
founded = models.DateTimeField(null=True)
|
2008-11-05 17:51:11 +00:00
|
|
|
|
2014-01-01 10:01:46 +00:00
|
|
|
# TODO: This should be implicitly inherited.
|
2013-11-02 20:12:09 +00:00
|
|
|
|
2008-08-05 18:13:06 +00:00
|
|
|
objects = models.GeoManager()
|
2013-10-17 08:17:41 +00:00
|
|
|
|
2015-03-21 15:59:30 +00:00
|
|
|
class Meta:
|
|
|
|
app_label = 'geoapp'
|
|
|
|
|
2013-11-02 20:12:09 +00:00
|
|
|
|
2014-01-01 10:01:46 +00:00
|
|
|
class State(NamedModel):
|
2014-08-21 16:47:57 +00:00
|
|
|
poly = models.PolygonField(null=gisfield_may_be_null) # Allowing NULL geometries here.
|
2013-10-17 08:17:41 +00:00
|
|
|
|
2015-03-21 15:59:30 +00:00
|
|
|
class Meta:
|
|
|
|
app_label = 'geoapp'
|
|
|
|
|
2014-01-01 10:01:46 +00:00
|
|
|
|
|
|
|
class Track(NamedModel):
|
|
|
|
line = models.LineStringField()
|
2010-01-29 02:20:58 +00:00
|
|
|
|
2013-11-02 20:12:09 +00:00
|
|
|
|
2014-11-08 16:08:12 +00:00
|
|
|
class MultiFields(NamedModel):
|
|
|
|
city = models.ForeignKey(City)
|
|
|
|
point = models.PointField()
|
|
|
|
poly = models.PolygonField()
|
|
|
|
|
|
|
|
|
2012-03-02 22:32:22 +00:00
|
|
|
class Truth(models.Model):
|
2013-08-11 20:19:09 +00:00
|
|
|
val = models.BooleanField(default=False)
|
2014-01-01 10:01:46 +00:00
|
|
|
|
2012-03-02 22:32:22 +00:00
|
|
|
objects = models.GeoManager()
|
|
|
|
|
2014-01-01 10:01:46 +00:00
|
|
|
|
2014-08-19 16:47:23 +00:00
|
|
|
class Feature(NamedModel):
|
|
|
|
geom = models.GeometryField()
|
2014-01-01 10:01:46 +00:00
|
|
|
|
2013-10-17 08:17:41 +00:00
|
|
|
|
2014-08-19 16:47:23 +00:00
|
|
|
class MinusOneSRID(models.Model):
|
|
|
|
geom = models.PointField(srid=-1) # Minus one SRID.
|
2014-01-01 10:01:46 +00:00
|
|
|
|
2014-08-19 16:47:23 +00:00
|
|
|
objects = models.GeoManager()
|
2014-01-01 10:01:46 +00:00
|
|
|
|
2014-08-12 12:08:40 +00:00
|
|
|
|
|
|
|
class NonConcreteField(models.IntegerField):
|
|
|
|
|
|
|
|
def db_type(self, connection):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_attname_column(self):
|
|
|
|
attname, column = super(NonConcreteField, self).get_attname_column()
|
|
|
|
return attname, None
|
|
|
|
|
|
|
|
|
|
|
|
class NonConcreteModel(NamedModel):
|
|
|
|
non_concrete = NonConcreteField()
|
|
|
|
point = models.PointField(geography=True)
|