Renders GeoJSON geometries as SVG path strings.
Takes GeoJSON data and a projection to produce SVG paths suitable for rendering maps.
Examples
projection = Visualize.Geo.Projection.new(:mercator)
|> Visualize.Geo.Projection.scale(100)
|> Visualize.Geo.Projection.translate(200, 150)
geo_path = Visualize.Geo.Path.new(projection)
# Render a GeoJSON feature
feature = %{
"type" => "Feature",
"geometry" => %{
"type" => "Polygon",
"coordinates" => [[[-122, 37], [-122, 38], [-121, 38], [-121, 37], [-122, 37]]]
}
}
path_data = Visualize.Geo.Path.render(geo_path, feature)Clipping on the sphere
With a projection, lines and polygons are clipped on the sphere before they are
projected, as d3-geo clips them (spec/07 §2.2.1, D-127): under a projection with a
clip_angle they are cut where they cross the small circle of that radius about the
centre — the orthographic's horizon — a line into several subpaths and a polygon closed
along the circle, so a globe never closes its land by a chord across the disc; under a
projection without one they are cut where they cross ±180° of the rotated frame and a
polygon is closed along the seam and the poles, so a rotated map never joins a ring the
long way round. Winding is d3's: a polygon's exterior ring runs clockwise on a north-up
map, and a ring wound the other way is the rest of the sphere.
Summary
Functions
Computes the projected planar area of a GeoJSON geometry.
Computes the bounding box of a GeoJSON geometry.
Computes the centroid of a GeoJSON geometry.
Creates a new GeoPath with the given projection
The GeoJSON object as a Visualize.IR.Path (spec/07 §2.2): the same walk as render/2,
its numbers the projected coordinates unrounded, and an empty path for a geometry with
nothing to draw.
Sets the radius for Point geometries
Sets the projection
Renders GeoJSON to an SVG path string.
Types
@type t() :: %Visualize.Geo.Path{ context: any(), point_radius: number(), projection: Visualize.Geo.Projection.t() | nil }
Functions
Computes the projected planar area of a GeoJSON geometry.
Computes the bounding box of a GeoJSON geometry.
Returns [x0, y0, x1, y1] in projected coordinates.
Computes the centroid of a GeoJSON geometry.
Returns {x, y} in projected coordinates.
@spec new(Visualize.Geo.Projection.t() | nil) :: t()
Creates a new GeoPath with the given projection
@spec path(t(), map()) :: Visualize.IR.Path.t()
The GeoJSON object as a Visualize.IR.Path (spec/07 §2.2): the same walk as render/2,
its numbers the projected coordinates unrounded, and an empty path for a geometry with
nothing to draw.
Sets the radius for Point geometries
@spec projection(t(), Visualize.Geo.Projection.t()) :: t()
Sets the projection
Renders GeoJSON to an SVG path string.
Accepts GeoJSON Feature, FeatureCollection, or raw Geometry objects.