SVGIS¶
Draw SVG maps
-
class
svgis.svgis.
SVGIS
(files, bounds=None, crs=None, **kwargs)¶ Draw geodata files to SVG.
Parameters: - files (list) – A list of files to draw.
- bounds (Sequence) – An iterable with four float coordinates in (minx, miny, maxx, maxy) format
- crs (dict) – A proj-4 like mapping, or a projection method keyword (file, local, utm).
- style (str) – CSS to add to output file
- scalar (int) – Map scaling factor (output coordinate are multiplied by this)
- style – CSS styles
- padding (number) – Buffer each edge by this many map units.
- precision (int) – Precision for rounding output coordinates.
- simplify (int) – Simplification factor (between 1 and 100).
- id_field (str) – Field in data to use for ID’ing elements.
- class_fields (Sequence) – Fields in data for added classes to elements.
-
compose
(bounds=None, style=None, viewbox=True, inline=True, **kwargs)¶ Draw files to svg.
Parameters: - bounds (Sequence) – Map bounding box in WGS84 (longlat) coordinates. Defaults to map data bounds.
- 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 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.
-
compose_file
(path, unprojected_bounds=None, **kwargs)¶ Draw fiona file to an SVG group.
Parameters: - path (string) – path to a fiona-readable file, or an Apache Commons VFS spec for a zip
or tar archive, e.g.
zip://path/to/archive.zip/file.shp
. - unprojected_bounds (tuple) – (minx, maxx, miny, maxy) in the layer’s coordinate system. ‘None’ values are OK. “Unprojected” here refers to the fact that we haven’t transformed these bounds yet. They may well, in fact, be in a projection.
- padding (int) – Number of map units by which to pad output bounds.
- scalar (int) – map scale
- class_fields (sequence) – Fields to turn in the element classes (default: self.class_fields).
- id_field (string) – Field to use as element ID (default: self.id_field).
Returns: members, id, class. This is ready to be passed to svgis.svg.group.
Return type: dict with keys
- path (string) – path to a fiona-readable file, or an Apache Commons VFS spec for a zip
or tar archive, e.g.
-
draw
(members, scalar=None, precision=None, style=None, **kwargs)¶ Combine drawn layers into an SVG drawing.
Parameters: - members (list) – unicode representations of SVG groups.
- 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.
-
feature
(feature, transforms, classes, **kwargs)¶ Draw a single feature.
Parameters: - feature (dict) – A GeoJSON like feature dict produced by Fiona.
- transforms (list) – Functions to apply to the geometry.
- classes (list) – Names (unsanitized) of fields to apply as classes in the output element.
- precision (int) – rounding precision for coordinates.
- id_field (str) – Field to use as id of the output element.
- name (str) – layer name (usually basename of the input file).
Returns: str (unicode in Python 2)
-
projected_bounds
¶ Returns None if projected bounds aren’t (yet) set
-
set_out_crs
(bounds)¶ Set the output CRS, if not yet set.
-
unprojected_bounds
¶ Returns None if projected bounds aren’t set
-
update_projected_bounds
(in_crs, out_crs, bounds, padding=None)¶ Extend projected_bounds bbox with self.padding.
Parameters: - in_crs (dict) – CRS of bounds.
- (dict) desired output CRS. (out_crs) –
- bounds (tuple) – bounding box.
Returns: (tuple) bounding box in out_crs coordinates.
-
svgis.svgis.
map
(layers, bounds=None, scale=None, **kwargs)¶ Draw a geodata layer to SVG. This is shorthand for creating a
SVGIS
instance and immediately runnningSVGIS.compose
.Parameters: - layers (sequence) – Input geodata files.
- bounds (sequence) – (minx, miny, maxx, maxy)
- scale (int) – Map scale. Larger numbers -> smaller maps
- padding (int) – Pad around bounds by this much. In projection units.
- crs (string) – EPSG code, PROJ.4 string, or file containing a PROJ.4 string
- clip (bool) – If true, clip features output to bounds.
- style (Sequence) – Path to a css file or a css string.
- class_fields (Sequence) – A comma-separated string or list of class names to use the SVG drawing.
- id_field (string) – Field to use to determine id of each element in the drawing.
- inline (bool) – If False, do not move CSS declarations into each element.
- precision (int) – Precision for rounding output coordinates.
- simplify (int) – Integer between 1 and 99 describing simplification level. 99: not very much. 1: a lot.
Returns: String (unicode in Python 2) containing an entire SVG document.