Permalink
Browse files

Added primary key to Feature and tested for duplicates, but that does…

…n't do anything.
  • Loading branch information...
1 parent 08a45f1 commit 98148413fa7346d77b309206e4b8a0e0507280d2 @jrasky jrasky committed May 29, 2012
Showing with 6 additions and 1 deletion.
  1. +4 −0 geocamLayer/models.py
  2. +2 −1 geocamLayer/noaaExampleParser.py
View
4 geocamLayer/models.py
@@ -48,6 +48,8 @@ class Feature(BaseFeature):
name = models.CharField(max_length=80)
description = models.TextField()
cell = models.ForeignKey('QuadTreeCell')
+ # primary key because
+ pkey = models.FloatField(primary_key=True, unique=True)
def __unicode__(self):
return u'Feature "%s" (%.6f, %.6f)' % (self.name, self.lng, self.lat)
@@ -180,6 +182,8 @@ def getBounds(self):
return (west, south, west + size, south + size)
def updateStats(self, feature):
+ if hasattr(self, 'features') and feature in self.features:
+ return # we don't want to have duplicate features in a cell
self.lng = (self.count * self.lng + feature.lng) / (self.count + 1)
self.lat = (self.count * self.lat + feature.lat) / (self.count + 1)
View
3 geocamLayer/noaaExampleParser.py
@@ -42,4 +42,5 @@ def readNoaaWeatherStations(fname):
yield Feature(lat=parseLatitude(stationLatitude),
lng=parseLongitude(stationLongitude),
name=placeName,
- description=countryName)
+ description=countryName,
+ pkey=random.random())

0 comments on commit 9814841

Please sign in to comment.