πŸ“„ d3/d3-geo/stream

File: stream.md | Updated: 11/15/2025

Source: https://d3js.org/d3-geo/stream

Skip to content

On this page

Streams ​

====================================================

Rather than materializing intermediate representations, streams transform geometry through function calls to minimize overhead. Streams must implement several methods to receive input geometry. Streams are inherently stateful; the meaning of a point depends on whether the point is inside of a line , and likewise a line is distinguished from a ring by a polygon . Despite the name β€œstream”, these method calls are currently synchronous.

geoStream(object, stream) ​


Source Β· Streams the specified GeoJSON object to the specified projection stream . While both features and geometry objects are supported as input, the stream interface only describes the geometry, and thus additional feature properties are not visible to streams.

stream.point(x, y, z) ​


Indicates a point with the specified coordinates x and y (and optionally z). The coordinate system is unspecified and implementation-dependent; for example, projection streams require spherical coordinates in degrees as input. Outside the context of a polygon or line, a point indicates a point geometry object (Point or MultiPoint ). Within a line or polygon ring, the point indicates a control point.

stream.lineStart() ​


Indicates the start of a line or ring. Within a polygon, indicates the start of a ring. The first ring of a polygon is the exterior ring, and is typically clockwise. Any subsequent rings indicate holes in the polygon, and are typically counterclockwise.

stream.lineEnd() ​


Indicates the end of a line or ring. Within a polygon, indicates the end of a ring. Unlike GeoJSON, the redundant closing coordinate of a ring is not indicated via point , and instead is implied via lineEnd within a polygon. Thus, the given polygon input:

json

{
  "type": "Polygon",
  "coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]
}

Will produce the following series of method calls on the stream:

js

stream.polygonStart();
stream.lineStart();
stream.point(0, 0);
stream.point(0, 1);
stream.point(1, 1);
stream.point(1, 0);
stream.lineEnd();
stream.polygonEnd();

stream.polygonStart() ​


Indicates the start of a polygon. The first line of a polygon indicates the exterior ring, and any subsequent lines indicate interior holes.

stream.polygonEnd() ​


Indicates the end of a polygon.

stream.sphere() ​


Indicates the sphere (the globe; the unit sphere centered at ⟨0,0,0⟩).