All Functions

Useful information

  • PLA = Points, Lines and Areas

  • Type aliases:

    • RealNum = Union[int, float]

    • Coord = Tuple[RealNum, RealNum]

    • TileCoord = Tuple[int, int, int]

renderer.__version__: str

The version.

Main

renderer.render(plaList: dict, nodeList: dict, skinJson: dict, minZoom: int, maxZoom: int, maxZoomRange: RealNum, saveImages: bool = True, saveDir: str = '', assetsDir: str = os.path.dirname(__file__) + '/skins/assets/', processes: int = 1, tiles: Optional[List[TileCoord]] = None, offset: Tuple[RealNum, RealNum] = (0, 0)) Dict[str, Image]

Renders tiles from given coordinates and zoom values.

Warning

Run this function under if __name__ == "__main__", or else there would be a lot of multiprocessing RuntimeErrors.

Parameters
  • plaList (dict) – a dictionary of PLAs (see formats)

  • nodeList (dict) – a dictionary of nodes (see formats)

  • skinJson (dict) – a JSON of the skin used to render tiles (see formats)

  • minZoom (int) – minimum zoom value

  • maxZoom (int) – maximum zoom value

  • maxZoomRange (RealNum) – range of coordinates covered by a tile in the maximum zoom (how do I phrase this?) For example, a maxZoom of 5 and a maxZoomValue of 8 will make a 5-zoom tile cover 8 units

  • saveImages (int) – whether to save the tile images in a folder or not

  • saveDir (str) – the directory to save tiles in

  • assetsDir (str) – the asset directory for the skin

  • processes (int) – The amount of processes to run for rendering

  • tiles (Optional[List[TileCoord]]) – a list of tiles to render, given in tuples of (z,x,y) where z = zoom and x,y = tile coordinates

  • offset (Tuple[RealNum, RealNum]) – the offset to shift all node coordinates by, given as (x,y)

Returns

Given in the form of "(tile coord)": (PIL Image)

Return type

Dict[str, Image]

Raises

ValueError – if maxZoom < minZoom

renderer.tileMerge(images: Union[str, Dict[str, Image]], saveImages: bool = True, saveDir: str = 'tiles/', zoom: List[int] = []) List[Image]

Merges tiles rendered by renderer.render().

Parameters
  • images (Union[str, Dict[str, Image]]) – Give in the form of "(tile coord)": (PIL Image), like the return value of renderer.render(), or as a path to a directory.

  • saveImages (bool) – whether to save the tile imaegs in a folder or not

  • saveDir (str) – the directory to save tiles in

  • zoom (List[int]) – if left empty, automatically calculates all zoom values based on tiles; otherwise, the layers of zoom to merge.

Returns

Given in the form of "(Zoom)": (PIL Image)

Return type

List[Image]

Tools

renderer.tools.plaJson.findEnds(plaList: dict, nodeList: dict) Tuple[RealNum, RealNum, RealNum, RealNum]

Finds the minimum and maximum X and Y values of a JSON or dictionary of PLAs.

Parameters
  • plaList (dict) – a dictionary of PLAs (see formats)

  • nodeList (dict) – a dictionary of nodes (see formats)

Returns

Returns in the form (xMax, xMin, yMax, yMin)

Return type

Tuple[RealNum, RealNum, RealNum, RealNum]

renderer.tools.plaJson.renderedIn(plaList: dict, nodeList: dict, minZoom: int, maxZoom: int, maxZoomRange: RealNum) List[TileCoord]

Like renderer.tools.lineToTiles(), but for a JSON or dictionary of PLAs.

Parameters
  • plaList (dict) – a dictionary of PLAs (see formats)

  • nodeList (dict) – a dictionary of nodes (see formats)

  • minZoom (int) – minimum zoom value

  • maxZoom (int) – maximum zoom value

  • maxZoomRange (RealNum) – range of coordinates covered by a tile in the maximum zoom (how do I phrase this?) For example, a maxZoom of 5 and a maxZoomValue of 8 will make a 5-zoom tile cover 8 units

Returns

A list of tile coordinates

Return type

List[TileCoord]

Raises

ValueError – if maxZoom < minZoom

renderer.tools.plaJson.toGeoJson(plaList: dict, nodeList: dict, skinJson: dict) dict

Converts PLA Json into GeoJson (with nodes and skin). :param dict plaList: a dictionary of PLAs (see formats) :param dict nodeList: a dictionary of nodes (see formats) :param dict skinJson: a JSON of the skin (see formats)

Returns

A GeoJson dictionary

Return type

dict

renderer.tools.geoJson.toNodePlaJson(geoJson: dict) Tuple[dict, dict]

Converts GeoJson to PLA and Node JSONs.

Parameters

geoJson (dict) – a GeoJson dictionary

Returns

Given in plaJson, nodeJson

Return type

Tuple[dict, dict]

renderer.tools.tile.findEnds(coords: List[TileCoord]) Tuple[RealNum, RealNum, RealNum, RealNum]

Find the minimum and maximum x/y values of a set of tiles coords.

Parameters

coords (List[TileCoord]) – a list of tile coordinates, provide in a tuple of (z,x,y)

Returns

Returns in the form (xMax, xMin, yMax, yMin)

Return type

Tuple[RealNum, RealNum, RealNum, RealNum]

renderer.tools.line.findEnds(coords: List[Coord]) Tuple[RealNum, RealNum, RealNum, RealNum]

Find the minimum and maximum x/y values of a set of coords.

Parameters

coords (List[Coord]) – a list of coordinates, provide in a tuple of (x,y)

Returns

Returns in the form (xMax, xMin, yMax, yMin)

Return type

Tuple[RealNum, RealNum, RealNum, RealNum]

renderer.tools.line.toTiles(coords: List[Coord], minZoom: int, maxZoom: int, maxZoomRange: RealNum) List[TileCoord]

Generates tile coordinates from list of regular coordinates using renderer.tools.coordToTiles(). Mainly for rendering whole PLAs.

Parameters
  • coords (List[Coord]) – of coordinates in tuples of (x,y)

  • minZoom (int) – minimum zoom value

  • maxZoom (int) – maximum zoom value

  • maxZoomRange (RealNum) – range of coordinates covered by a tile in the maximum zoom (how do I phrase this?) For example, a maxZoom of 5 and a maxZoomValue of 8 will make a 5-zoom tile cover 8 units

Returns

A list of tile coordinates

Return type

List[TileCoord]

Raises
  • ValueError – if maxZoom < minZoom

  • ValueError – if empty list of coords given

renderer.tools.node.findPlasAttached(nodeId: str, plaList: dict) List[Tuple[str, int]]

Finds which PLAs attach to a node.

Parameters
  • nodeId (str) – the node to search for

  • plaList (dict) – a dictionary of PLAs (see formats)

Returns

A tuple in the form of (plaId, posInNodeList)

Return type

List[Tuple[str, int]]

renderer.tools.node.toCoords(nodes: List[str], nodeList: dict) List[Coord]

Converts a list of nodes IDs into a list of coordinates with a node dictionary/JSON as its reference.

Parameters
  • nodes (list) – a list of node IDs

  • nodeList (dict) – a dictionary of nodes (see formats)

Returns

A list of coordinates

Return type

List[Coord]

Raises

KeyError – if a node does not exist

renderer.tools.coord.toTiles(coord: Coord, minZoom: int, maxZoom: int, maxZoomRange: RealNum) List[TileCoord]

Returns all tiles in the form of tile coordinates that contain the provided regular coordinate.

Parameters
  • coord (Coord) – Coordinates provided in the form (x,y)

  • minZoom (int) – minimum zoom value

  • maxZoom (int) – maximum zoom value

  • maxZoomRange (RealNum) – range of coordinates covered by a tile in the maximum zoom (how do I phrase this?) For example, a maxZoom of 5 and a maxZoomValue of 8 will make a 5-zoom tile cover 8 units

Returns

A list of tile coordinates

Return type

List[TileCoord]

Raises

ValueError – if maxZoom < minZoom

Math Tools

renderer.mathtools.midpoint(x1: RealNum, y1: RealNum, x2: RealNum, y2: RealNum, o: RealNum, n: int = 1, returnBoth: bool = False) Union[List[Tuple[RealNum, RealNum, RealNum]], List[List[Tuple[RealNum, RealNum, RealNum]]]]

Calculates the midpoint of two lines, offsets the distance away from the line, and calculates the rotation of the line.

Parameters
  • x1 (RealNum) – the x-coordinate of the 1st point

  • y1 (RealNum) – the y-coordinate of the 1st point

  • x2 (RealNum) – the x-coordinate of the 2nd point

  • y2 (RealNum) – the y-coordinate of the 2nd point

  • o (RealNum) – the offset from the line. If positive, the point above the line is returned; if negative, the point below the line is returned

  • n (int) – the number of midpoints on a single segment

  • returnBoth (bool) – if True, it will return both possible points.

Returns

A list of (lists of, when returnBoth=True) tuples in the form of (x, y, rot)

Return type

List[Tuple[RealNum, RealNum, RealNum]] when returnBoth=False, List[List[Tuple[RealNum, RealNum, RealNum]]] when returnBoth=True

renderer.mathtools.linesIntersect(x1: RealNum, y1: RealNum, x2: RealNum, y2: RealNum, x3: RealNum, y3: RealNum, x4: RealNum, y4: RealNum) bool:

Finds if two segments intersect.

Parameters
  • x1 (RealNum) – the x-coordinate of the 1st point of the 1st segment.

  • y1 (RealNum) – the y-coordinate of the 1st point of the 1st segment.

  • x2 (RealNum) – the x-coordinate of the 2nd point of the 1st segment.

  • y2 (RealNum) – the y-coordinate of the 2nd point of the 1st segment.

  • x3 (RealNum) – the x-coordinate of the 1st point of the 2nd segment.

  • y3 (RealNum) – the y-coordinate of the 1st point of the 2nd segment.

  • x4 (RealNum) – the x-coordinate of the 2nd point of the 2nd segment.

  • y4 (RealNum) – the y-coordinate of the 2nd point of the 2nd segment.

Returns

Whether the two segments intersect.

Return type

bool

renderer.mathtools.pointInPoly(xp: RealNum, yp: RealNum, coords: List[Coord]) bool

Finds if a point is in a polygon.

Parameters
  • xp (RealNum) – the x-coordinate of the point.

  • yp (RealNum) – the y-coordinate of the point.

  • List[Coord] (list) – the coordinates of the polygon; give in (x,y)

Returns

Whether the point is inside the polygon.

Return type

bool

renderer.mathtools.polyCenter(coords: List[Coord]) Coord

Finds the center point of a polygon.

Parameters

coords (List[Coord]) – the coordinates of the polygon; give in (x,y)

Returns

The center of the polygon, given in (x,y)

Return type

Coord

renderer.mathtools.lineInBox(line: List[Coord], top: RealNum, bottom: RealNum, left: RealNum, right: RealNum) bool

Finds if any nodes of a line go within the box.

Parameters
  • line (List[Coord]) – the line to check for

  • top (RealNum) – the bounds of the box

  • bottom (RealNum) – the bounds of the box

  • left (RealNum) – the bounds of the box

  • right (RealNum) – the bounds of the box

Returns

Whether any nodes of a line go within the box.

Return type

bool

renderer.mathtools.dash(x1: RealNum, y1: RealNum, x2: RealNum, y2: RealNum, d: RealNum, g: RealNum, o: RealNum = 0, emptyStart: bool = False) List[List[Coord]]

Finds points along a segment that are a specified distance apart.

Parameters
  • x1 (RealNum) – the x-coordinate of the 1st point

  • y1 (RealNum) – the y-coordinate of the 1st point

  • x2 (RealNum) – the x-coordinate of the 2nd point

  • y2 (RealNum) – the y-coordinate of the 2nd point

  • d (RealNum) – the length of a single dash

  • g (RealNum) – the length of the gap between dashes

  • o (RealNum) – the offset from (x1,y1) towards (x2,y2) before dashes are calculated

  • emptyStart (bool) – Whether to start the line from (x1,y1) empty before the start of the next dash

Returns

A list of points along the segment, given in [[(x1, y1), (x2, y2)], etc]

Return type

List[List[Coord]]

renderer.mathtools.dashOffset(coords: List[Coord], d: RealNum, g: RealNum) Tuple[RealNum, bool]

Calculates the offsets on each coord of a line for a smoother dashing sequence.

Parameters
  • coords (List[Coord]) – the coords of the line

  • d (RealNum) – the length of a single dash

  • g (RealNum) – the length of the gap between dashes

Returns

The offsets of each coordinate, and whether to start the next segment with emptyStart, given in (offset, emptyStart)

Return type

Tuple[RealNum, bool]

renderer.mathtools.rotateAroundPivot(x: RealNum, y: RealNum, px: RealNum, py: RealNum, theta: RealNum) Coord

Rotates a set of coordinates around a pivot point.

Parameters
  • x (RealNum) – the x-coordinate to be rotated

  • y (RealNum) – the y-coordinate to be rotated

  • px (RealNum) – the x-coordinate of the pivot

  • py (RealNum) – the y-coordinate of the pivot

  • theta (RealNum) – how many degrees to rotate

Returns

The rotated coordinates, given in (x,y)

Return type

Coord

renderer.mathtools.pointsAway(x: RealNum, y: RealNum, d: RealNum, m: RealNum) List[Coord]

Finds two points that are a specified distance away from a specified point, all on a straight line.

Parameters
  • y (RealNum x,) – the coordinates of the original point

  • d (RealNum) – the distance the two points from the original point

  • m (RealNum) – the gradient of the line. Give None for a gradient of undefined.

Returns

Given in [(x1, y1), (x2, y2)]

Return type

List[Coord]

Validate

renderer.validate.vCoords(coords: List[Coord]) True

Validates a list of coordinates.

Parameters

coords (List[Coord]) – a list of coordinates.

Returns

Returns True if no errors

renderer.validate.vTileCoords(tiles: List[TileCoord], minZoom: int, maxZoom: int) True

Validates a list of tile coordinates.

Parameters
  • tiles (List[TileCoord]) – a list of tile coordinates.

  • minZoom (int) – minimum zoom value

  • maxZoom (int) – maximum zoom value

Returns

Returns True if no errors

renderer.validate.vNodeList(nodes: List[str], nodeList: dict) True

Validates a list of node IDs.

Parameters
  • nodes (List[str]) – a list of node IDs.

  • nodeList (dict) – a dictionary of nodes (see formats)

Returns

Returns True if no errors

renderer.validate.vNodeJson(nodeList: dict) True

Validates a dictionary/JSON of nodes.

Parameters

nodeList (dict) – a dictionary of nodes (see formats)

Returns

Returns True if no errors

renderer.validate.vPlaJson(plaList: dict, nodeList: dict) True

Validates a dictionary/JSON of PLAs.

Parameters
  • plaList (dict) – a dictionary of PLAs (see formats)

  • nodeList (dict) – a dictionary of nodes (see formats)

Returns

Returns True if no errors

renderer.validate.vSkinJson(skinJson: dict) True

Validates a skin JSON file.

Parameters

skinJson (dict) – the skin JSON file

Returns

Returns True if no errors

renderer.validate.vGeoJson(geoJson: dict) True

Validates a GeoJson file.

Parameters

geoJson (dict) – the GeoJson file

Returns

Returns True if no errors

Misc

renderer.misc.getSkin(name: str) dict

Gets a skin from inside the package.

Parameters

name (str) – the name of the skin

Returns

The skin JSON

Return type

dict

Raises

FileNotFoundError – if skin does not exist