Paths

detroit.geo_path(projection: Projection | None = None, context: Context | None = None)

Creates a new geographic path generator with the default settings. If projection is specified, sets the current projection. If context is specified, sets the current context.

Parameters:
class detroit.geo.path.path.GeoPath(projection: Projection | None = None, context: Context | None = None)

Creates a new geographic path generator with the default settings. If projection is specified, sets the current projection. If context is specified, sets the current context.

Parameters:
__call__(obj: dict[str, Any], *args: Any) str | None

Renders the given object, which may be any GeoJSON feature or geometry object:

  • Point - a single position

  • MultiPoint - an array of positions

  • LineString - an array of positions forming a continuous line

  • MultiLineString - an array of arrays of positions forming several lines

  • Polygon - an array of arrays of positions forming a polygon (possibly with holes)

  • MultiPolygon - a multidimensional array of positions forming multiple polygons

  • GeometryCollection - an array of geometry objects

  • Feature - a feature containing one of the above geometry objects

  • FeatureCollection - an array of feature objects

The type Sphere is also supported, which is useful for rendering the outline of the globe; a sphere has no coordinates. Any additional arguments are passed along to the pointRadius accessor.

Parameters:
  • obj (GeoJSON) – GeoJSON object

  • *args (Any) – Additional arguments passed to point_radius function

Returns:

Path

Return type:

str | None

area(obj: dict[str, Any]) float

Returns the projected planar area (typically in square pixels) for the specified GeoJSON object.

Parameters:

obj (GeoJSON) – GeoJSON object

Returns:

Area in px²

Return type:

float

measure(obj: dict[str, Any]) float

Returns the projected planar length (typically in pixels) for the specified GeoJSON object.

Parameters:

obj (GeoJSON) – GeoJSON object

Returns:

Projected planar length in px

Return type:

float

bounds(obj: dict[str, Any]) tuple[tuple[float, float], tuple[float, float]]

Returns the projected planar bounding box (typically in pixels) for the specified GeoJSON object.

Parameters:

obj (GeoJSON) – GeoJSON object

Returns:

Projected planar bounding box

Return type:

tuple[Point2D, Point2D]

centroid(obj: dict[str, Any]) tuple[float, float]

Returns the projected planar centroid (typically in pixels) for the specified GeoJSON object.

Parameters:

obj (GeoJSON) – GeoJSON object

Returns:

Projected planar centroid

Return type:

Point2D

set_projection(projection: Projection | None = None) GeoPath

If a projection is specified, sets the current projection to the specified projection. The projection defaults to None, which represents the identity transformation: the input geometry is not projected and is instead rendered directly in raw coordinates. This can be useful for fast rendering of pre-projected geometry, or for fast rendering of the equirectangular projection.

The given projection is typically one of built-in geographic projections; however, any object that exposes a projection.stream function can be used, enabling the use of custom projections.

Parameters:

projection (Projection | None) – Projection

Returns:

Itself

Return type:

GeoPath

set_context(context: Context | None = None) GeoPath

If context is specified, sets the current render context and returns the path generator. If the context is None, then the path generator will return an SVG path string; if the context is not None, the path generator will instead call methods on the specified context to render geometry.

Parameters:

context (Context | None) – Context

Returns:

Itself

Return type:

GeoPath

set_point_radius(radius: Callable[[...], float] | float) GeoPath

If radius is specified, sets the radius used to display Point and MultiPoint geometries to the specified number.

Parameters:

radius (Callable[..., float] | float) – Radius function or constant value

Returns:

Itself

Return type:

GeoPath

set_digits(digits: str | float | None = None) GeoPath

If digits is specified (as a non-negative number), sets the number of fractional digits for coordinates generated in SVG path strings.

Parameters:

digits (str | float | None) – Digits value

Returns:

Itself

Return type:

GeoPath

class detroit.geo.common.Context

Context definition

abstractmethod arc(x: float, y: float, r: float)

Adds an arc

Parameters:
  • x (float) – x value of the end point

  • y (float) – y value of the end point

  • r (float) – radius value

abstractmethod move_to(x: float, y: float)

Moves to a specific point

Parameters:
  • x (float) – x value of the end point

  • y (float) – y value of the end point

abstractmethod line_to(x: float, y: float)

Makes a line

Parameters:
  • x (float) – x value of the end point

  • y (float) – y value of the end point

abstractmethod close_path()

Closes the path