2016-11-05 18:35:58 +08:00
|
|
|
from django.contrib.gis.db import models
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class NamedModel(models.Model):
|
|
|
|
name = models.CharField(max_length=25)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class State(NamedModel):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class County(NamedModel):
|
2015-07-22 22:43:21 +08:00
|
|
|
state = models.ForeignKey(State, models.CASCADE)
|
2018-06-19 20:21:39 +08:00
|
|
|
mpoly = models.MultiPolygonField(srid=4269, null=True) # Multipolygon in NAD83
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class CountyFeat(NamedModel):
|
2008-08-06 02:13:06 +08:00
|
|
|
poly = models.PolygonField(srid=4269)
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class City(NamedModel):
|
2012-05-24 15:57:22 +08:00
|
|
|
name_txt = models.TextField(default="")
|
2014-09-19 00:54:38 +08:00
|
|
|
name_short = models.CharField(max_length=5)
|
2008-08-06 02:13:06 +08:00
|
|
|
population = models.IntegerField()
|
|
|
|
density = models.DecimalField(max_digits=7, decimal_places=1)
|
|
|
|
dt = models.DateField()
|
|
|
|
point = models.PointField()
|
|
|
|
|
2015-03-21 23:59:30 +08:00
|
|
|
class Meta:
|
|
|
|
app_label = "layermap"
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class Interstate(NamedModel):
|
2008-08-06 02:13:06 +08:00
|
|
|
length = models.DecimalField(max_digits=6, decimal_places=2)
|
|
|
|
path = models.LineStringField()
|
|
|
|
|
2015-03-21 23:59:30 +08:00
|
|
|
class Meta:
|
|
|
|
app_label = "layermap"
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2009-11-02 10:17:56 +08:00
|
|
|
# Same as `City` above, but for testing model inheritance.
|
2014-01-01 18:01:46 +08:00
|
|
|
class CityBase(NamedModel):
|
2009-11-02 10:17:56 +08:00
|
|
|
population = models.IntegerField()
|
|
|
|
density = models.DecimalField(max_digits=7, decimal_places=1)
|
|
|
|
point = models.PointField()
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2009-11-02 10:17:56 +08:00
|
|
|
class ICity1(CityBase):
|
|
|
|
dt = models.DateField()
|
2013-10-11 04:42:30 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class Meta(CityBase.Meta):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2009-11-02 10:17:56 +08:00
|
|
|
class ICity2(ICity1):
|
|
|
|
dt_time = models.DateTimeField(auto_now=True)
|
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class Meta(ICity1.Meta):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2011-03-15 10:26:37 +08:00
|
|
|
class Invalid(models.Model):
|
|
|
|
point = models.PointField()
|
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
|
2019-02-01 08:50:16 +08:00
|
|
|
class HasNulls(models.Model):
|
|
|
|
uuid = models.UUIDField(primary_key=True, editable=False)
|
|
|
|
geom = models.PolygonField(srid=4326, blank=True, null=True)
|
|
|
|
datetime = models.DateTimeField(blank=True, null=True)
|
|
|
|
integer = models.IntegerField(blank=True, null=True)
|
|
|
|
num = models.FloatField(blank=True, null=True)
|
|
|
|
boolean = models.BooleanField(blank=True, null=True)
|
|
|
|
name = models.CharField(blank=True, null=True, max_length=20)
|
|
|
|
|
|
|
|
|
|
|
|
class DoesNotAllowNulls(models.Model):
|
|
|
|
uuid = models.UUIDField(primary_key=True, editable=False)
|
|
|
|
geom = models.PolygonField(srid=4326)
|
|
|
|
datetime = models.DateTimeField()
|
|
|
|
integer = models.IntegerField()
|
|
|
|
num = models.FloatField()
|
|
|
|
boolean = models.BooleanField()
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
|
|
|
|
|
2008-08-06 02:13:06 +08:00
|
|
|
# Mapping dictionaries for the models above.
|
2014-09-04 20:15:09 +08:00
|
|
|
co_mapping = {
|
|
|
|
"name": "Name",
|
|
|
|
# ForeignKey's use another mapping dictionary for the _related_ Model
|
|
|
|
# (State in this case).
|
|
|
|
"state": {"name": "State"},
|
|
|
|
"mpoly": "MULTIPOLYGON", # Will convert POLYGON features into MULTIPOLYGONS.
|
|
|
|
}
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2019-01-03 07:18:19 +08:00
|
|
|
cofeat_mapping = {
|
|
|
|
"name": "Name",
|
|
|
|
"poly": "POLYGON",
|
|
|
|
}
|
|
|
|
|
|
|
|
city_mapping = {
|
|
|
|
"name": "Name",
|
|
|
|
"population": "Population",
|
|
|
|
"density": "Density",
|
|
|
|
"dt": "Created",
|
|
|
|
"point": "POINT",
|
|
|
|
}
|
|
|
|
|
|
|
|
inter_mapping = {
|
|
|
|
"name": "Name",
|
|
|
|
"length": "Length",
|
|
|
|
"path": "LINESTRING",
|
|
|
|
}
|
2019-02-01 08:50:16 +08:00
|
|
|
|
|
|
|
has_nulls_mapping = {
|
|
|
|
"geom": "POLYGON",
|
|
|
|
"uuid": "uuid",
|
|
|
|
"datetime": "datetime",
|
|
|
|
"name": "name",
|
|
|
|
"integer": "integer",
|
|
|
|
"num": "num",
|
|
|
|
"boolean": "boolean",
|
|
|
|
}
|