package geojsone
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=3e44559e8eb8587a5cbcdcb508dd1464204b4e5f7a4c9819d4f91dd4f110cd9b
sha512=821d423219ccb27d446bdfa76404bbf4e03c4e68e78d66bff3a70bbc6dff9aebcf8c4844c89b2cc922b459767844c2195202790d0c9ca4eefb310e35ca315901
doc/geojsone/Geojsone/index.html
Module Geojsone
Source
A library for manipulating large GeoJson documents without reading the whole document into memory using the Jsonm
streaming, JSON parser.
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.
val 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.
val 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
fold_geometry f acc src
is much like map_geometry
but allows you to accumulate some result that is then returned to you.
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
iter_geometry f src
will apply f
to all GeoJson objects.
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