2016-11-05 18:35:58 +08:00
|
|
|
from django.contrib.gis.db import models
|
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
|
|
|
|
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
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2015-04-05 00:09:46 +08:00
|
|
|
required_db_features = ['gis_enabled']
|
2014-01-01 18:01:46 +08:00
|
|
|
|
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
|
|
|
|
2016-01-22 19:03:05 +08:00
|
|
|
class CountryWebMercator(NamedModel):
|
|
|
|
mpoly = models.MultiPolygonField(srid=3857)
|
|
|
|
|
|
|
|
|
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'
|
2015-04-05 00:09:46 +08:00
|
|
|
required_db_features = ['gis_enabled']
|
2015-03-21 23:59:30 +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)
|
2008-11-06 01:51:11 +08:00
|
|
|
|
2015-03-21 23:59:30 +08:00
|
|
|
class Meta:
|
|
|
|
app_label = 'geoapp'
|
2015-04-05 00:09:46 +08:00
|
|
|
required_db_features = ['gis_enabled']
|
2015-03-21 23:59:30 +08:00
|
|
|
|
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'
|
2015-04-05 00:09:46 +08:00
|
|
|
required_db_features = ['gis_enabled']
|
2015-03-21 23:59:30 +08:00
|
|
|
|
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):
|
2015-07-22 22:43:21 +08:00
|
|
|
city = models.ForeignKey(City, models.CASCADE)
|
2014-11-09 00:08:12 +08:00
|
|
|
point = models.PointField()
|
|
|
|
poly = models.PolygonField()
|
|
|
|
|
2015-09-20 18:41:25 +08:00
|
|
|
class Meta:
|
|
|
|
required_db_features = ['gis_enabled']
|
|
|
|
|
|
|
|
|
|
|
|
class UniqueTogetherModel(models.Model):
|
|
|
|
city = models.CharField(max_length=30)
|
|
|
|
point = models.PointField()
|
|
|
|
|
2015-03-22 00:38:23 +08:00
|
|
|
class Meta:
|
|
|
|
unique_together = ('city', 'point')
|
2015-08-20 02:37:31 +08:00
|
|
|
required_db_features = ['gis_enabled', 'supports_geometry_field_unique_index']
|
2015-03-22 00:38:23 +08:00
|
|
|
|
2014-11-09 00:08:12 +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)
|
2014-01-01 18:01:46 +08:00
|
|
|
|
2015-04-05 00:09:46 +08:00
|
|
|
class Meta:
|
|
|
|
required_db_features = ['gis_enabled']
|
|
|
|
|
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
|
|
|
|
2015-04-05 00:09:46 +08:00
|
|
|
class Meta:
|
|
|
|
required_db_features = ['gis_enabled']
|
|
|
|
|
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)
|