Meridian.Render.GeoJSON (Meridian v0.1.0)

Copy Markdown View Source

Renders a Meridian.Graph as GeoJSON.

Requires the optional :jason dependency for JSON output.

Examples

graph =
  Meridian.Graph.new()
  |> Meridian.Graph.add_node(:a, %{geometry: %Geo.Point{coordinates: {0.0, 0.0}}, name: "A"})
  |> Meridian.Graph.add_node(:b, %{geometry: %Geo.Point{coordinates: {1.0, 1.0}}, name: "B"})
  |> Meridian.Graph.add_edge_ensure(:a, :b, %{distance: 10.0})

geojson = Meridian.Render.GeoJSON.to_string(graph)

Summary

Functions

Writes a spatial graph to a GeoJSON file.

Converts a spatial graph to a GeoJSON FeatureCollection string.

Functions

to_file(graph, path, opts \\ [])

@spec to_file(Meridian.Graph.t(), Path.t(), keyword()) :: :ok | {:error, File.posix()}

Writes a spatial graph to a GeoJSON file.

Options

Accepts the same options as to_string/2.

to_string(graph, opts \\ [])

@spec to_string(
  Meridian.Graph.t(),
  keyword()
) :: String.t()

Converts a spatial graph to a GeoJSON FeatureCollection string.

Options

  • :include_edges — emit edges as LineString features (default true)
  • :edge_properties_fn — function (from, to, weight) -> map for edge props
  • :node_properties_fn — function (id, data) -> map for node props

Examples

iex> g = Meridian.Graph.new()
iex> g = g
...>   |> Meridian.Graph.add_node(:a, %{geometry: %Geo.Point{coordinates: {0.0, 0.0}}, label: "A"})
...>   |> Meridian.Graph.add_node(:b, %{geometry: %Geo.Point{coordinates: {1.0, 1.0}}, label: "B"})
...>   |> Meridian.Graph.add_edge_ensure(:a, :b, %{distance: 10.0})
iex> json = Meridian.Render.GeoJSON.to_string(g)
iex> String.contains?(json, "FeatureCollection")
true