package geojsone

  1. Overview
  2. Docs
Streaming GeoJSON library

Install

Dune Dependency

Authors

Maintainers

Sources

geojson-0.2.0.tbz
sha256=3e44559e8eb8587a5cbcdcb508dd1464204b4e5f7a4c9819d4f91dd4f110cd9b
sha512=821d423219ccb27d446bdfa76404bbf4e03c4e68e78d66bff3a70bbc6dff9aebcf8c4844c89b2cc922b459767844c2195202790d0c9ca4eefb310e35ca315901

doc/geojsone/Geojsone/index.html

Module GeojsoneSource

A library for manipulating large GeoJson documents without reading the whole document into memory using the Jsonm streaming, JSON parser.

Sourcemodule Err : sig ... end
Sourcemodule G : Geojson.S with type json = Ezjsone.value

Maps

Maps are functions that allow you to manipulate common structure in GeoJson objects. These will be written directly back to the destination that you provide.

Sourceval map_geometry : (G.Geometry.t -> G.Geometry.t) -> Jsone.src -> Jsone.dst -> (unit, Err.t) result

map_geometry f src dst will apply f to all GeoJson objects. This is essentially any geometry object.

The map will recurse into geometry collections. Note for the moment if you have a single geometry object as your document, this will not work.

Sourceval map_props : (Ezjsone.value -> Ezjsone.value) -> Jsone.src -> Jsone.dst -> (unit, Err.t) result

map_props src dst ~f will apply f to each feature's properties field. The properties field is decoded into an Ezjsone.value for convenience.

Folds

Folds are like maps except you can collect items into an accumulator which is returned to you.

For example, you might want to collect all of the names in the properties of features.

  let get_string_exn = function `String s -> s | _ -> failwith "err"

  let get_name = function
    | `O assoc -> List.assoc "name" assoc |> get_string_exn
    | _ -> failwith "err"

  let places src =
    Geojsonm.fold_props (fun acc p -> get_name p :: acc) [] src
Sourceval fold_geometry : ('a -> G.Geometry.t -> 'a) -> 'a -> Jsone.src -> ('a, Err.t) result

fold_geometry f acc src is much like map_geometry but allows you to accumulate some result that is then returned to you.

Sourceval fold_props : ('a -> Ezjsone.value -> 'a) -> 'a -> Jsone.src -> ('a, Err.t) result

fold_props f init src

Iterators

Iterators are similar to map functions except they take a function f that takes a single element from the data-structure as an argument and returns unit. In that sense, they tend to be functions with side-effects, such as print_endline.

For example, we might want to print the JSON value of every geometry object in a GeoJSON object.

  let print_geometry g =
    print_endline @@ Ezjsone.value_to_string (Geojsonm.G.Geometry.to_json g)

  let values src = Geojsonm.iter_geometry print_geometry src
Sourceval iter_geometry : (G.t -> unit) -> Jsone.src -> (unit, Err.t) result

iter_geometry f src will apply f to all GeoJson objects.

Sourceval iter_props : (Ezjsone.value -> unit) -> Jsone.src -> (unit, Err.t) result

iter_props f src will apply f to each feature's properties field.

Effect-based, non-blocking libraries

These libraries use effects to perform non-blocking parsing. They are currently a part of Geojsone and exposed for other libraries to use.

module Ezjsone : sig ... end
module Jsone : sig ... end
module Uutfe : sig ... end
OCaml

Innovation. Community. Security.