Geojsonm
A library for manipulating large GeoJson documents without reading the whole document into memory using the Jsonm
streaming, JSON parser.
module Err : sig ... end
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.
val map_geometry : (G.Geometry.t -> G.Geometry.t) -> Jsonm.src -> Jsonm.dst -> (unit, Err.t) Stdlib.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.
val map_props : (Ezjsonm.value -> Ezjsonm.value) -> Jsonm.src -> Jsonm.dst -> (unit, Err.t) Stdlib.result
map_props src dst ~f
will apply f
to each feature's properties field. The properties field is decoded into an Ezjsonm
.value for convenience.
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
val fold_geometry : ('a -> G.Geometry.t -> 'a) -> 'a -> Jsonm.src -> ('a, Err.t) Stdlib.result
fold_geometry f acc src
is much like map_geometry
but allows you to accumulate some result that is then returned to you.
val fold_props : ('a -> Ezjsonm.value -> 'a) -> 'a -> Jsonm.src -> ('a, Err.t) Stdlib.result
fold_props f init src