2016-11-05 10:35:58 +00:00
|
|
|
from django.contrib.gis.db import models
|
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
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2016-01-22 11:03:05 +00:00
|
|
|
class CountryWebMercator(NamedModel):
|
|
|
|
mpoly = models.MultiPolygonField(srid=3857)
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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):
|
2015-07-22 14:43:21 +00:00
|
|
|
city = models.ForeignKey(City, models.CASCADE)
|
2014-11-08 16:08:12 +00:00
|
|
|
point = models.PointField()
|
|
|
|
poly = models.PolygonField()
|
|
|
|
|
2015-09-20 10:41:25 +00:00
|
|
|
|
|
|
|
class UniqueTogetherModel(models.Model):
|
|
|
|
city = models.CharField(max_length=30)
|
|
|
|
point = models.PointField()
|
|
|
|
|
2015-03-21 16:38:23 +00:00
|
|
|
class Meta:
|
|
|
|
unique_together = ("city", "point")
|
2017-05-04 14:14:35 +00:00
|
|
|
required_db_features = ["supports_geometry_field_unique_index"]
|
2015-03-21 16:38:23 +00:00
|
|
|
|
2014-11-08 16:08:12 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-07-10 15:43:19 +00:00
|
|
|
class ThreeDimensionalFeature(NamedModel):
|
|
|
|
geom = models.GeometryField(dim=3)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
required_db_features = {"supports_3d_storage"}
|
|
|
|
|
|
|
|
|
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-12 12:08:40 +00:00
|
|
|
|
|
|
|
class NonConcreteField(models.IntegerField):
|
|
|
|
def db_type(self, connection):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_attname_column(self):
|
2017-01-21 13:13:44 +00:00
|
|
|
attname, column = super().get_attname_column()
|
2014-08-12 12:08:40 +00:00
|
|
|
return attname, None
|
|
|
|
|
|
|
|
|
|
|
|
class NonConcreteModel(NamedModel):
|
|
|
|
non_concrete = NonConcreteField()
|
|
|
|
point = models.PointField(geography=True)
|
2017-04-10 17:26:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ManyPointModel(NamedModel):
|
|
|
|
point1 = models.PointField()
|
|
|
|
point2 = models.PointField()
|
|
|
|
point3 = models.PointField(srid=3857)
|