package topojson

  1. Overview
  2. Docs

Module Topojson.MakeSource

A functor that takes a Json parsing implementation and returns a TopoJSON parser and constructor.

Parameters

module J : Json

Signature

Sourcetype json = J.t

The internal representation of JSON

Geometries

TopoJSON objects are primarily made up of geometry primitives that are the same as those used in Geojson. For example you can have a single Point or Linestring.

These are grouped under the Geometry module and in particular the Geometry.geometry type. These can be accessed and pattern-matched against using the Geometry.geometryfunction. For example:

  let is_linestring t =
    let open Topojson in
    match Geometry.geometry t with
    | Geometry.LineString _ -> true
    | _ -> false
Sourcemodule Geometry : sig ... end

Topologies

The Topology.t is the most common TopoJSON object for the main document. This contains a map of geometry objects along with other important components of the topology including the arc index and transform information.

Sourcemodule Topology : sig ... end

TopoJSON Objects

Finally we have the main TopoJSON object. Most frequently this will be a Topology.t but could technically be a standalone Geometry.t according to the specification.

Sourcetype topojson =
  1. | Topology of Topology.t
  2. | Geometry of Geometry.t
    (*

    The underlying TopoJSON datastructure.

    *)
Sourcetype t

The TopoJSON object.

Sourceval topology_exn : t -> Topology.t

Accessor for the TopoJSON data. This will try to access a Topology.t.contents

Sourceval topojson : t -> topojson

Accessor for the TopoJSON data.

Sourceval bbox : t -> float array option

Accessor for the optional bounding-box for the entire TopoJSON object.

Sourceval v : ?bbox:float array -> topojson -> t

Construct a new TopoJSON object, optionally with a bounding-box.

Sourceval of_json : json -> (t, [ `Msg of string ]) result

of_json json converts the JSON to a topojson object (a type t) or an error.

Sourceval to_json : t -> json

to_json t converts the TopoJSON object t to JSON.

OCaml

Innovation. Community. Security.