def vwr(self, attr): '''Return the Visvalingam-Whyatt results, optionally including the triangular area (in meters) as attribute attr to each simplified point. ''' pts, r = self.pts, self.r # double check the minimal triangular area assert min(t2.h2 for t2 in r) > self.s2 > 0 if attr: # return the trangular area (actually # the sqrt of double the triangular area) # converted back from degrees to meter if isNumpy2(pts): raise AttributeError('%r invalid' % (attr,)) m = radians(1.0) * self.radius r[0].h2 = r[-1].h2 = 0 # zap sentinels for t2 in r: # convert back to meter setattr(pts[t2.ix], attr, sqrt(t2.h2) * m) # double check for duplicates n = len(r) r = dict((t2.ix, True) for t2 in r) assert len(r) == n return self.points(r)
def points(self, r): '''Return the list of simplified points or indices. ''' r = sorted(r.keys()) if self.indices: return list(r) elif isNumpy2(self.pts) or isTuple2(self.pts): return self.pts.subset(r) else: return [self.pts[i] for i in r]