How to use the svgis.utils function in svgis

To help you get started, we’ve selected a few svgis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fitnr / svgis / tests / test_utils.py View on Github external
def testPosInt(self):
        with self.assertRaises(ValueError):
            utils.posint(-1)
        assert utils.posint(1) == 1
        assert utils.posint(111) == 111
        assert utils.posint(1.11) == 1
github fitnr / svgis / tests / test_utils.py View on Github external
def testPosInt(self):
        with self.assertRaises(ValueError):
            utils.posint(-1)
        assert utils.posint(1) == 1
        assert utils.posint(111) == 111
        assert utils.posint(1.11) == 1
github fitnr / svgis / svgis / bounding.py View on Github external
def ring(bounds):
    '''Convert min, max points to a boundary ring.'''
    minx, miny, maxx, maxy = bounds
    xs, ys = list(utils.between(minx, maxx)), list(utils.between(miny, maxy))

    left_top = [(minx, y) for y in ys] + [(x, maxy) for x in xs][1:]

    ys.reverse()
    xs.reverse()

    return left_top + [(maxx, y) for y in ys] + [(x, miny) for x in xs]
github fitnr / svgis / svgis / svgis.py View on Github external
scalar (int): factor by which to scale the data, generally a small number (1/map scale).
            style (str): CSS to append to parent object CSS.
            viewbox (bool): If True, draw SVG with a viewbox. If False, translate coordinates to
                            the frame. Defaults to True.
            inline (bool): If True, try to run CSS into each element.

        Returns:
            String (unicode in Python 2) containing an entire SVG document.
        '''
        scalar = scalar or self.scalar
        precision = precision or self.precision
        style = style or self.style
        transform_attrib = 'scale(1,-1)'

        try:
            if any((utils.isinf(b) for b in self._projected_bounds)):
                self.log.warning('Drawing has infinite bounds, consider changing projection or bounding box.')

            dims = [float(b or 0.) * scalar for b in self.projected_bounds]
        except TypeError:
            self.log.warning('Unable to find bounds, the map probably empty ¯\_(ツ)_/¯')
            dims = 0, 0, 0, 0

        # width and height
        size = [dims[2] - dims[0], dims[3] - dims[1]]

        self.log.debug('Size: %f x %f', *size)

        if kwargs.pop('viewbox', True):
            viewbox = [dims[0], -dims[3]] + size
            self.log.debug('drawing with viewbox')
        else:
github fitnr / svgis / svgis / svgis.py View on Github external
def set_in_crs(self, crs):
        if not self.in_crs and crs:
            self._in_crs = crs

        if not crs:
            # Assume input CRS is WGS 84
            self._in_crs = utils.DEFAULT_GEOID
            self.log.warning(
                'Found no input coordinate system, '
                'assuming WGS84 (long/lat) coordinates.'
github fitnr / svgis / svgis / svg.py View on Github external
def poly(coordinates, precision=None, **kwargs):
        fmt = _fmt(precision)

        points = utils.dedupe(fmt.format(c) for c in coordinates)
        return _element(name(), points=' '.join(points), **kwargs)
github fitnr / svgis / svgis / svg.py View on Github external
def rect(start, width, height, precision=None, **kwargs):
    '''
    Create an svg rect element.

    Args:
        start (tuple): starting coordinate
        width (int): rect width
        height (int): rect height
        precision (int): rounding precision

    Returns:
        str (unicode in Python 2)
    '''
    start = [utils.rnd(i, precision) for i in start]
    width = utils.rnd(width, precision)
    height = utils.rnd(height, precision)

    return _element('rect', x=start[0], y=start[1], width=width, height=height, **kwargs)