Exemple #1
0
 def __getattr__(self, name):
     try:
         return self[name]
     except KeyError:
         if name == _name_:
             return _NamedDict.name.fget(self)
     raise _AttributeError(item=self._dot_(name), txt=_doesn_t_exist_)
Exemple #2
0
    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(attr=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)
Exemple #3
0
 def _immutable(inst, value):
     '''Throws an C{AttributeError}, always.
     '''
     from pygeodesy.named import classname
     s = _DOT_(repr(inst), self.name)
     s = _EQUALSPACED_(s, repr(value))
     t = _SPACE_(_immutable_, classname(self))
     raise _AttributeError(s, txt=t)
Exemple #4
0
 def __getattr__(self, name):
     '''Get the value of an attribute or enum by B{C{name}}.
     '''
     try:
         return self[name]
     except KeyError:
         if name == _name_:
             return _NamedDict.name.fget(self)
     raise _AttributeError(item=self._DOT_(name), txt=_doesn_t_exist_)
Exemple #5
0
def _boolkwds(inst, **name_value_pairs):  # in .frechet, .hausdorff, .heights
    '''(INTERNAL) Set applicable C{bool} properties/attributes.
    '''
    for n, v in name_value_pairs.items():
        b = getattr(inst, n, None)
        if b is None:  # invalid bool attr
            t = _SPACE_(_EQUAL_(n, repr(v)), 'for',
                        inst.__class__.__name__)  # XXX .classname
            raise _AttributeError(t, txt=_not_('applicable'))
        if v in (False, True) and v != b:
            setattr(inst, NN(_UNDER_, n), v)
Exemple #6
0
 def _getattr(o, a):
     if hasattr(o, a):
         return getattr(o, a)
     raise _AttributeError(Fmt.DOT(a), o)
Exemple #7
0
 def _getattr(o, a):
     if hasattr(o, a):
         return getattr(o, a)
     raise _AttributeError('.%s' % (a, ), o)
Exemple #8
0
 def immutable(inst, value):
     '''Throws an C{AttributeError}, always.
     '''
     t = immutable.__name__, inst, method.__name__, value
     raise _AttributeError('%s property: %r.%s = %r' % t)
Exemple #9
0
 def __getattr__(self, attr):
     try:
         return self[attr]
     except KeyError:  # PYCHOK no cover
         from pygeodesy.errors import _AttributeError
         raise _AttributeError(self._DOT_(attr), txt=_doesn_t_exist_)