Geo v3.3.7 Geo.JSON View Source
Converts Geo structs to and from a map representing GeoJSON.
You are responsible to encoding and decoding of JSON. This is so that you can use any JSON parser you want as well as making it so that you can use the resulting GeoJSON structure as a property in larger JSON structures.
# Using Jason as the JSON parser for these examples
iex>json = "{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0] }"
...>json |> Jason.decode!() |> Geo.JSON.decode!()
%Geo.Point{coordinates: {100.0, 0.0}, srid: nil}
iex>geom = %Geo.Point{coordinates: {100.0, 0.0}, srid: nil}
...>Jason.encode!(geom)
"{\"coordinates\":[100.0,0.0],\"type\":\"Point\"}"
iex>geom = %Geo.Point{coordinates: {100.0, 0.0}, srid: nil}
...>Geo.JSON.encode!(geom)
%{"type" => "Point", "coordinates" => [100.0, 0.0]}
Link to this section Summary
Functions
Takes a map representing GeoJSON and returns a Geometry
Takes a map representing GeoJSON and returns a Geometry
Takes a Geometry and returns a map representing the GeoJSON
See Geo.JSON.Encoder.encode/2
.
Takes a Geometry and returns a map representing the GeoJSON
See Geo.JSON.Encoder.encode!/2
.
Link to this section Functions
decode(geo_json)
View Sourcedecode(map()) :: {:ok, Geo.geometry()} | {:error, Geo.JSON.Decoder.DecodeError.t()}
Takes a map representing GeoJSON and returns a Geometry
Takes a map representing GeoJSON and returns a Geometry
encode(geom)
View Sourceencode(Geo.geometry()) :: {:ok, map()} | {:error, Geo.JSON.Encoder.EncodeError.t()}
Takes a Geometry and returns a map representing the GeoJSON
See Geo.JSON.Encoder.encode/2
.
Takes a Geometry and returns a map representing the GeoJSON
See Geo.JSON.Encoder.encode!/2
.