1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# -*- coding: utf-8 -*-
# models.py
# All standard Django fields as well as GeoDjango geometry fields and the GeoManager() can be
# imported from django.contrib.gis.db after adding django.contrib.gis to INSTALLED_APPS
from django.contrib.gis.db import models
from django.contrib.sitemaps import Sitemap
# Used to display html 'help text' links within Admin App
from django.utils.safestring import mark_safe
class Region(models.Model):
name = models.CharField(max_length=50, )
slug = models.SlugField()
pub_date = models.DateTimeField('Date published',null=True)
# GeoDjango specific Polygon Field and GeoManager
geometry = models.MultiPolygonField(srid=4326, null=True)
lon = models.FloatField('Longitude',help_text="Longitude of centerpoint",null=True)
lat = models.FloatField('Latitude',help_text="Latitude of centerpoint",null=True)
zoom_level = models.CharField(max_length=2,null=True)
# GeoManager, a subclass that adds a rich set of geospatial queryset methods
objects = models.GeoManager()
def get_absolute_url(self):
return "/locations/region/%s/" % (self.slug)
def __unicode__(self): return self.name
# imported from django.contrib.gis.db
from django.contrib.gis.db import models
# Used to display html 'help text' links within Admin App
from django.utils.safestring import mark_safe
class Country(models.Model):
"""
A geographic model based on the v3 of the simplified world borders multipolygon shapefile
from http://thematicmapping.org/downloads/world_borders.php.
Field names, Django types, and max_lengths were autogenerated using the ogrinspect utility with hand
edits to add alternative field names and help_text.
Imported using LayerMapping (requires GDAL) called within the load_data.py script provided
within this sample project.
All fields match the source dataset, an ESRI format shapefile made up of several related files:
.shp - holds the vector data that is to be stored in the MultiPolygonField field named'geometry'.
.shx - spatial index file for geometries stored in the .shp.
.dbf - database file for holding attribute data (can be opened in excel and open office).
.prj - contains the spatial reference information for the geometries stored in the .shp
"""
# Regular Django fields corresponding to the attributes in the
# world borders shapefile
name = models.CharField(max_length=50)
area = models.IntegerField(help_text="Area of Country in SQ meters")
pop2005 = models.IntegerField('Population 2005')
fips = models.CharField('FIPS Code', max_length=2, help_text=mark_safe('<a href="http://www.census.gov/geo/www/fips/fips.html">Federal Information Processing Standard Code</a>'))
iso2 = models.CharField('2 Digit ISO', max_length=2, help_text=mark_safe('<a href="http://www.iso.org/">International Organization for Standardization</a>' ))
iso3 = models.CharField('3 Digit ISO', max_length=3,help_text=mark_safe('<a href="http://www.iso.org/">International Organization for Standardization</a>' ))
un = models.IntegerField('United Nations Code')
REGION_CODES = (
(0, 'MISC'),
(2, 'Africa'),
(9, 'Oceania'),
(19, 'Americas'),
(142, 'Asia'),
(150, 'Europe'),
)
SUBREGION_CODES = (
(0, 'MISC'),
(5, 'South America'),
(11, 'Western Africa'),
(13, 'Central America'),
(14, 'Eastern Africa'),
(15, 'Northern Africa'),
(17, 'Middle Africa'),
(18, 'Southern Africa'),
(21, 'North America'),
(29, 'Caribbean'),
(30, 'Eastern Asia'),
(34, 'Southern Asia'),
(35, 'Southeast Asia'),
(39, 'Southern Europe'),
(53, 'Australia and New Zealand'),
(54, 'Melanesia'),
(57, 'Micronesia'),
(61, 'Polynesia'),
(143, 'Central Asia'),
(145, 'Western Asia'),
(151, 'Eastern Europe'),
(154, 'Northern Europe'),
(155, 'Western Europe'),
)
region = models.IntegerField('Region Code',choices=REGION_CODES)
subregion = models.IntegerField('Sub-Region Code',choices=SUBREGION_CODES)
lon = models.FloatField('Longitude',help_text="Longitude of centerpoint")
lat = models.FloatField('Latitude',help_text="Latitude of centerpoint")
zoom_level = models.CharField(max_length=2,null=True)
slug = models.SlugField(null=True)
visited = models.BooleanField(default=False)
lux_region = models.ForeignKey(Region, null=True)
pub_date = models.DateTimeField('Date published',null=True)
# GeoDjango-specific: a geometry field (MultiPolygonField), and
# overriding the default manager with a GeoManager instance.
geometry = models.MultiPolygonField('Country Border',srid=4326)
objects = models.GeoManager()
# Returns the string representation of the model.
def __unicode__(self):
return self.name
class Meta:
ordering = ['name']
verbose_name_plural = 'Countries'
def get_absolute_url(self):
return "/locations/%s/" % (self.slug)
class State(models.Model):
name = models.CharField(max_length=250, blank=True, null=True,)
country = models.ForeignKey(Country)
slug = models.SlugField()
code = models.CharField(max_length=2, null=True, blank=True)
pub_date = models.DateTimeField('Date published',null=True)
geometry = models.MultiPolygonField(srid=4326,null=True)
objects = models.GeoManager()
class Meta:
ordering = ['name']
class Admin:
pass
def __unicode__(self):
return "%s" %(self.name)
def get_absolute_url(self):
return "/locations/%s/%s/" % (self.country.slug, self.slug)
class Location(models.Model):
state = models.ForeignKey(State)
name = models.CharField(max_length=50, )
slug = models.SlugField()
pub_date = models.DateTimeField('Date published',null=True)
# GeoDjango specific Polygon Field and GeoManager
geometry = models.MultiPolygonField(srid=4326)
# GeoManager, a subclass that adds a rich set of geospatial queryset methods
objects = models.GeoManager()
def get_absolute_url(self):
return "/locations/%s/%s/%s/" % (self.state.country.slug, self.state.slug, self.slug)
def __unicode__(self): return self.name
class BirdingLocation(models.Model):
location = models.ForeignKey(Location)
name = models.CharField(max_length=50)
slug = models.SlugField()
date_visited = models.DateTimeField('Date visited',null=True)
point = models.PointField()
# GeoManager, a subclass that adds a rich set of geospatial queryset methods
objects = models.GeoManager()
def get_absolute_url(self):
return "/birdinglocations/%s/%s/%s/" % (self.state.country.slug, self.state.slug, self.slug)
def __unicode__(self): return self.name
class Route(models.Model):
name = models.CharField(max_length=200)
slug = models.SlugField()
zoom = models.CharField(max_length=2, null=True)
template_var_name = models.CharField(max_length=10, null=True)
pub_date = models.DateTimeField('Date published',null=True)
# GeoDjango specific Polygon Field and GeoManager
geometry = models.MultiPointField(srid=4326)
# GeoManager, a subclass that adds a rich set of geospatial queryset methods
objects = models.GeoManager()
def get_absolute_url(self):
return "/locations/%s/%s/%s/" % (self.slug)
def __unicode__(self): return self.name
class WritingbyLocationSitemap(Sitemap):
changefreq = "weekly"
priority = 0.6
def location():
return '/writing/%s/1/' %(self.slug)
def items(self):
return Location.objects.all()
|