def save(self): utmz, utmx, utmy = util.get_utm(self.latitude, self.longitude) self.utm_zone = utmz if self.rounding: utmx = util.round_to_nearest(utmx, self.rounding) utmy = util.round_to_nearest(utmy, self.rounding) self.utm_x_rounded = utmx self.utm_y_rounded = utmy super(Post, self).save()
def test(): # cambridge, ma myloc_lat = decimal.Decimal("40.77131") myloc_lng = decimal.Decimal("-73.95676") myz, myx, myy = util.get_utm(myloc_lat, myloc_lng) for post in Post.objects.all(): havdist = util.haversine_gcdist_deg(myloc_lat, myloc_lng, post.latitude, post.longitude) z, x, y = util.get_utm(post.latitude, post.longitude) if myz != z: print "skipping %d; zones differ (%d!=%d)" % (post.id, myz, z) else: euclidist = util.euclidean_dist(x, y, myx, myy) print "%d: %f %f DIFFERENCE FRACTION %f" % ( post.id, havdist, euclidist, (abs(havdist - euclidist) / havdist), ) post.save() # hack:update the x,y,z!