package topojson

  1. Overview
  2. Docs

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

Parameters

module J : Json

Signature

type 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
module 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.

module 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.

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

    The underlying TopoJSON datastructure.

    *)
type t

The TopoJSON object.

val topology_exn : t -> Topology.t

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

  • raises Invalid_argument

    if the data is a geometry.

val topojson : t -> topojson

Accessor for the TopoJSON data.

val bbox : t -> float array option

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

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

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

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

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

val to_json : t -> json

to_json t converts the TopoJSON object t to JSON.