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:
projection (Projection | None) – Projection
context (Context | None) – Context
- 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:
projection (Projection | None) – Projection
context (Context | None) – Context
- __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 positionMultiPoint- an array of positionsLineString- an array of positions forming a continuous lineMultiLineString- an array of arrays of positions forming several linesPolygon- an array of arrays of positions forming a polygon (possibly with holes)MultiPolygon- a multidimensional array of positions forming multiple polygonsGeometryCollection- an array of geometry objectsFeature- a feature containing one of the above geometry objectsFeatureCollection- 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_radiusfunction
- 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:
- 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 notNone, the path generator will instead call methods on the specified context to render geometry.
- 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