Skip to content

¥Streams

流并非具体化中间表示,而是通过函数调用来转换几何体,以最大限度地减少开销。流必须实现多种方法来接收输入几何图形。流本质上是有状态的;point 的含义取决于该点是否位于 line 内部,同样,polygon 可以区分线和环。尽管名称为“流”,但这些方法调用目前是同步的。

¥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)

源代码 · 将指定的 GeoJSON 对象传输到指定的 投影流。虽然支持要素和几何对象作为输入,但流接口仅描述几何体,因此其他要素属性对流不可见。

¥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) {#stream_point}

表示具有指定坐标 x 和 y(以及可选的 z)的点。坐标系未指定,且依赖于具体实现;例如,投影流 需要以度为单位的球面坐标作为输入。 ​​在多边形或线的上下文之外,点表示点几何对象(MultiPoint)。在线或多边形环内,该点表示控制点。

¥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() {#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() {#stream_lineEnd}

表示线或环的终点。在多边形内,表示环的终点。Unlike GeoJSON, the redundant closing coordinate of a ring is not indicated via point, and instead is implied via lineEnd within a polygon.因此,给定的多边形输入:

¥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() {#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() {#stream_polygonEnd}

表示多边形的终点。

¥Indicates the end of a polygon.

stream.sphere() {#stream_sphere}

表示球体(地球;以 ⟨0,0,0⟩ 为中心的单位球体)。

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