|
0
|
1 |
from django.contrib.gis.db import models |
|
|
2 |
|
|
|
3 |
class State(models.Model): |
|
|
4 |
name = models.CharField(max_length=20) |
|
|
5 |
objects = models.GeoManager() |
|
|
6 |
|
|
|
7 |
class County(models.Model): |
|
|
8 |
name = models.CharField(max_length=25) |
|
|
9 |
state = models.ForeignKey(State) |
|
|
10 |
mpoly = models.MultiPolygonField(srid=4269) # Multipolygon in NAD83 |
|
|
11 |
objects = models.GeoManager() |
|
|
12 |
|
|
|
13 |
class CountyFeat(models.Model): |
|
|
14 |
name = models.CharField(max_length=25) |
|
|
15 |
poly = models.PolygonField(srid=4269) |
|
|
16 |
objects = models.GeoManager() |
|
|
17 |
|
|
|
18 |
class City(models.Model): |
|
|
19 |
name = models.CharField(max_length=25) |
|
|
20 |
population = models.IntegerField() |
|
|
21 |
density = models.DecimalField(max_digits=7, decimal_places=1) |
|
|
22 |
dt = models.DateField() |
|
|
23 |
point = models.PointField() |
|
|
24 |
objects = models.GeoManager() |
|
|
25 |
|
|
|
26 |
class Interstate(models.Model): |
|
|
27 |
name = models.CharField(max_length=20) |
|
|
28 |
length = models.DecimalField(max_digits=6, decimal_places=2) |
|
|
29 |
path = models.LineStringField() |
|
|
30 |
objects = models.GeoManager() |
|
|
31 |
|
|
|
32 |
# Mapping dictionaries for the models above. |
|
|
33 |
co_mapping = {'name' : 'Name', |
|
|
34 |
'state' : {'name' : 'State'}, # ForeignKey's use another mapping dictionary for the _related_ Model (State in this case). |
|
|
35 |
'mpoly' : 'MULTIPOLYGON', # Will convert POLYGON features into MULTIPOLYGONS. |
|
|
36 |
} |
|
|
37 |
|
|
|
38 |
cofeat_mapping = {'name' : 'Name', |
|
|
39 |
'poly' : 'POLYGON', |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
city_mapping = {'name' : 'Name', |
|
|
43 |
'population' : 'Population', |
|
|
44 |
'density' : 'Density', |
|
|
45 |
'dt' : 'Created', |
|
|
46 |
'point' : 'POINT', |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
inter_mapping = {'name' : 'Name', |
|
|
50 |
'length' : 'Length', |
|
|
51 |
'path' : 'LINESTRING', |
|
|
52 |
} |