2008-08-06 02:13:06 +08:00
|
|
|
from django.contrib.gis.db import models
|
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
|
|
|
|
2015-02-10 23:07:44 +08:00
|
|
|
from ..utils import gisfield_may_be_null
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2014-01-01 18:01:46 +08:00
|
|
|
class NamedModel(models.Model):
|
2008-08-06 02:13:06 +08:00
|
|
|
name = models.CharField(max_length=30)
|
2014-01-01 18:01:46 +08:00
|
|
|
|
2008-08-06 02:13:06 +08:00
|
|
|
objects = models.GeoManager()
|
2013-10-17 16:17:41 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2013-10-17 16:17:41 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2014-01-02 01:37:52 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class Country(NamedModel):
|
|
|
|
mpoly = models.MultiPolygonField() # SRID, by default, is 4326
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2013-10-17 16:17:41 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class City(NamedModel):
|
|
|
|
point = models.PointField()
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2015-03-21 23:59:30 +08:00
|
|
|
class Meta:
|
|
|
|
app_label = 'geoapp'
|
|
|
|
|
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)
|
2008-11-06 01:51:11 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
# TODO: This should be implicitly inherited.
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2008-08-06 02:13:06 +08:00
|
|
|
objects = models.GeoManager()
|
2013-10-17 16:17:41 +08:00
|
|
|
|
2015-03-21 23:59:30 +08:00
|
|
|
class Meta:
|
|
|
|
app_label = 'geoapp'
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class State(NamedModel):
|
2014-08-22 00:47:57 +08:00
|
|
|
poly = models.PolygonField(null=gisfield_may_be_null) # Allowing NULL geometries here.
|
2013-10-17 16:17:41 +08:00
|
|
|
|
2015-03-21 23:59:30 +08:00
|
|
|
class Meta:
|
|
|
|
app_label = 'geoapp'
|
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
|
|
|
|
class Track(NamedModel):
|
|
|
|
line = models.LineStringField()
|
2010-01-29 10:20:58 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-11-09 00:08:12 +08:00
|
|
|
class MultiFields(NamedModel):
|
|
|
|
city = models.ForeignKey(City)
|
|
|
|
point = models.PointField()
|
|
|
|
poly = models.PolygonField()
|
|
|
|
|
|
|
|
|
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)
|
2014-01-01 18:01:46 +08:00
|
|
|
|
2012-03-03 06:32:22 +08:00
|
|
|
objects = models.GeoManager()
|
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
|
2014-08-20 00:47:23 +08:00
|
|
|
class Feature(NamedModel):
|
|
|
|
geom = models.GeometryField()
|
2014-01-01 18:01:46 +08:00
|
|
|
|
2013-10-17 16:17:41 +08:00
|
|
|
|
2014-08-20 00:47:23 +08:00
|
|
|
class MinusOneSRID(models.Model):
|
|
|
|
geom = models.PointField(srid=-1) # Minus one SRID.
|
2014-01-01 18:01:46 +08:00
|
|
|
|
2014-08-20 00:47:23 +08:00
|
|
|
objects = models.GeoManager()
|
2014-01-01 18:01:46 +08:00
|
|
|
|
2014-08-12 20:08:40 +08: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)
|