Meridian.IO.GeoJSON (Meridian v0.1.0)

Copy Markdown View Source

Ingests GeoJSON into Meridian.Graph structures.

Requires the optional :jason dependency.

Supported Geometry Types

  • Point — single node
  • LineString — edge path; intermediate vertices become nodes
  • MultiLineString — multiple edges
  • Polygon — ring of edges
  • FeatureCollection — iterated over features

Examples

geojson = ~s[{"type":"FeatureCollection","features":[...]}]
{:ok, graph} = Meridian.IO.GeoJSON.from_string(geojson)

Summary

Functions

Reads a GeoJSON file and builds a Meridian.Graph.

Reads a GeoJSON file and builds a Meridian.Graph, raising on error.

Builds a graph from a decoded GeoJSON map.

Parses a GeoJSON string and builds a Meridian.Graph.

Parses a GeoJSON string and builds a Meridian.Graph, raising on error.

Functions

from_file(path, opts \\ [])

@spec from_file(
  Path.t(),
  keyword()
) :: {:ok, Meridian.Graph.t()} | {:error, String.t()}

Reads a GeoJSON file and builds a Meridian.Graph.

Returns {:ok, graph} on success or {:error, reason} on failure.

from_file!(path, opts \\ [])

@spec from_file!(
  Path.t(),
  keyword()
) :: Meridian.Graph.t()

Reads a GeoJSON file and builds a Meridian.Graph, raising on error.

from_map(geojson, opts \\ [])

@spec from_map(
  map(),
  keyword()
) :: Meridian.Graph.t()

Builds a graph from a decoded GeoJSON map.

from_string(json, opts \\ [])

@spec from_string(
  String.t(),
  keyword()
) :: {:ok, Meridian.Graph.t()} | {:error, String.t()}

Parses a GeoJSON string and builds a Meridian.Graph.

Returns {:ok, graph} on success or {:error, reason} on failure.

Options

  • :kind:directed (default) or :undirected
  • :crs — CRS string override, default "EPSG:4326"
  • :weight_fn — function (%Geo.LineString{} -> number) to compute edge weights

Examples

iex> geojson = ~s|{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"LineString","coordinates":[[0,0],[0,1]]},"properties":{}}]}|
iex> {:ok, graph} = Meridian.IO.GeoJSON.from_string(geojson)
iex> Meridian.Graph.node_count(graph) == 2
true
iex> Meridian.Graph.edge_count(graph) == 1
true

from_string!(json, opts \\ [])

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

Parses a GeoJSON string and builds a Meridian.Graph, raising on error.