How to use the svgis.svg 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_svg.py View on Github external
def test_create(self):
        s = svg.drawing((100, 100), [])
        assert isinstance(s, six.string_types)

        s = svg.drawing((100, 100), [])
        assert isinstance(s, six.string_types)

        s = svg.drawing((100, 100), [], style=self.newstyle)

        assert self.newstyle in s
github fitnr / svgis / svgis / draw.py View on Github external
def func(coordinates, **kwargs):
        ID = kwargs.pop('id', None)
        result = svg.group(multifunc(coordinates, **kwargs), fill_rule="evenodd", id=ID)
        return result
github fitnr / svgis / svgis / svgis.py View on Github external
# 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:
            viewbox = None
            transform_attrib += ' translate({},{})'.format(-dims[0], -dims[3])
            self.log.debug('translating contents to fit')

        # Create container and then SVG
        container = svg.group(members, fill_rule='evenodd', transform=transform_attrib)
        drawing = svg.drawing(size, [container], style=style, precision=precision, viewbox=viewbox)

        if kwargs.pop('inline', False):
            self.log.info('inlining styles')
            drawing = _style.inline(drawing, style)

        return drawing
github fitnr / svgis / svgis / draw.py View on Github external
def geometrycollection(collection, bbox, precision, **kwargs):
    ID = kwargs.pop('id', None)
    geoms = (geometry(g, bbox=bbox, precision=precision, **kwargs)
             for g in collection['geometries'])
    return svg.group(geoms, fill_rule="evenodd", id=ID)
github fitnr / svgis / svgis / svgis.py View on Github external
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 False, do not add CSS style attributes to each element.
            padding (int): Number of (projected) units to pad bounds by.
            precision (int): Precision for rounding output coordinates.

        Returns:
            String (unicode in Python 2) containing an entire SVG document.
        '''
        # Set up arguments
        scalar = kwargs.pop('scalar', self.scalar)
        bounds = bounding.check(bounds) or self.unprojected_bounds

        # Draw files
        members = [svg.group(**self.compose_file(f, bounds, scalar=scalar, **kwargs))
                   for f in self.files]

        self.log.info('composing drawing')
        drawing = self.draw(members, scalar, kwargs.get('precision'),
                             style=style, viewbox=viewbox, inline=inline)

        # Always reset projected bounds.
        self._projected_bounds = (None,) * 4

        return drawing
github fitnr / svgis / svgis / draw.py View on Github external
def points(geom, **kwargs):
    '''
    Draw a Point or MultiPoint geometry

    Args:
        geom (object): A GeoJSON-like Point or MultiPoint geometry object.

    Returns:
        str (unicode in Python 2) representation of the SVG group, or circle element
    '''
    kwargs['r'] = kwargs.get('r', 1)

    if geom['type'] == 'Point':
        return svg.circle(geom['coordinates'], **kwargs)

    if geom['type'] == 'MultiPoint':
        return multipoint(geom['coordinates'], **kwargs)
github fitnr / svgis / svgis / draw.py View on Github external
def linestring(coordinates, **kwargs):
    return svg.polyline(coordinates, **kwargs)
github fitnr / svgis / svgis / draw.py View on Github external
def polygon(coordinates, **kwargs):
    if len(coordinates) == 1:
        return svg.polygon(coordinates[0], **kwargs)

    kwargs['class'] = ('polygon ' + kwargs.pop('class', '')).strip()

    instructions = ['M']
    # This is trickier because drawing holes in SVG.
    # We go clockwise on the first ring, then counterclockwise
    if measure.counterclockwise(coordinates[0]):
        instructions.extend(coordinates[0][::-1])
    else:
        instructions.extend(coordinates[0])

    instructions.append('z')

    for ring in coordinates[1:]:
        # make all interior run the counter-clockwise
        instructions.append('M')