123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354moduletypeJson=sigtypet(** The type your parser uses to represent a parsed JSON object. *)valfind:t->stringlist->toptionvalto_string:t->(string,[`Msgofstring])result(** Convert the JSON to a string. *)valstring:string->t(** Create a JSON string. *)valto_float:t->(float,[`Msgofstring])result(** Convert the JSON to a float. *)valfloat:float->t(** Converts a float to JSON *)valto_int:t->(int,[`Msgofstring])result(** Convert the JSON to an integer. *)valint:int->t(** Converts an integer to JSON *)valto_list:(t->'a)->t->('alist,[`Msgofstring])result(** [to_list f] converts the JSON array to a list and applies [f] to each
element to convert them too. *)vallist:('a->t)->'alist->t(** Make a JSON array from a list *)valto_array:(t->'a)->t->('aarray,[`Msgofstring])result(** Like {!to_list} except to an array. *)valarray:('a->t)->'aarray->t(** Like {!list} except for OCaml arrays *)valto_obj:t->((string*t)list,[`Msgofstring])result(** Convert the JSON object to an association list *)valobj:(string*t)list->t(** A JSON object from an association list *)valnull:t(** Null value *)valis_null:t->bool(** Test for null *)end(* {2 Json Conversion} *)moduletypeJson_conv=sigtypettypejsonvalto_json:t->json(** Convert a [t] to a JSON representation. *)valof_json:json->(t,[`Msgofstring])result(** Attempt to deserialise a [t] from JSON.*)end(** {2 topojson Geometry Objects}
The basic primitives for building geometrical shapes in topojson. *)moduletypeGeometry=sigtypejsonmodulePosition:sigtypet=floatarray(** A position - a longitude and latitude with an optional altitude *)vallng:t->float(** The longitude value of the position *)vallat:t->float(** The latitude value of the position *)valaltitude:t->floatoption(** Optional altitude/elevation value of the position *)valequal:t->t->bool(** Whether two positions are equal by comparing each value *)valv:?altitude:float->lng:float->lat:float->unit->t(** A position constructor *)endmodulePoint:sigtypet(** A point is a single {!Position.t} *)valposition:t->Position.t(** Convert a point to a position *)valv:Position.t->t(** Create a point from a position. *)endmoduleArc_index:sigtypet(** An array of indexes into the arcs field. *)valv:intlist->t(** A constructors for building an arc-index from an integer array. *)endmoduleMultiPoint:sigtypet(** A multipoint is an array of positions. *)valcoordinates:t->Position.tarray(** Get the positions that make up this multipoint object. *)valv:Position.tarray->t(** Create a multipoint object from an array of positions. *)endmoduleLineString:sigtypet(** A line string is two or more points *)valv:Arc_index.t->t(** Creates a line string from an arc index. *)endmoduleMultiLineString:sigtypet(** A collection of line strings *)valv:LineString.tarray->t(** Create a multiline string *)endmodulePolygon:sigtypet(** A close loop with optional rings *)valrings:t->LineString.tarray(** [rings t] returns the linear rings contained in [t] (a Polygon object) *)valexterior_ring:t->LineString.t(** [exterior_ring t] returns the first linear ring contained in [t] (a
Polygon object). This ring bounds the surface *)valinterior_rings:t->LineString.tarray(** If [t] (a Polygon object) contains more than 1 linear ring,
[interior_rings t] returns the rest of the linear rings apart from the
first. These rings (if present), bound the holes. *)valv:LineString.tarray->t(** Create a polygon object from an array of close line strings *)endmoduleMultiPolygon:sigtypet(** A multi-polygon object *)valpolygons:t->Polygon.tarray(** Access the polygons *)valv:Polygon.tarray->t(** Create a multi-polygon object from an array of {!Polygon.t}s *)endtypegeometry=|PointofPoint.t|MultiPointofMultiPoint.t|LineStringofLineString.t|MultiLineStringofMultiLineString.t|PolygonofPolygon.t|MultiPolygonofMultiPolygon.t|Collectionoftlistandproperties=[`None|`Null|`Objof(string*json)list](** The properties associated with a Geometry object can be left out
([`None]), could be specifically a null value ([`Null]) or an object. *)andt(** {2 Constructors} *)valpoint:Position.t->geometryvalmultipoint:Point.tarray->geometryvallinestring:Arc_index.t->geometryvalmultilinestring:LineString.tarray->geometryvalpolygon:LineString.tarray->geometryvalmultipolygon:Polygon.tarray->geometryvalcollection:tlist->geometry(** {2 Conversion functions}*)valget_point:geometry->(Point.t,[>`Msgofstring])resultvalget_point_exn:geometry->Point.tvalget_multipoint:geometry->(MultiPoint.t,[>`Msgofstring])resultvalget_multipoint_exn:geometry->MultiPoint.tvalget_linestring:geometry->(LineString.t,[>`Msgofstring])resultvalget_linestring_exn:geometry->LineString.tvalget_multilinestring:geometry->(MultiLineString.t,[>`Msgofstring])resultvalget_multilinestring_exn:geometry->MultiLineString.tvalget_polygon:geometry->(Polygon.t,[>`Msgofstring])resultvalget_polygon_exn:geometry->Polygon.tvalget_multipolygon:geometry->(MultiPolygon.t,[>`Msgofstring])resultvalget_multipolygon_exn:geometry->MultiPolygon.tvalproperties:t->properties(** [properties t] returns the properties associated with a given object. If
there aren't any this returns [`None]. The empty list is the empty object
[{}]. *)valgeometry:t->geometry(** [geometry t] returns the geometry associated with the object. *)valforeign_members:t->(string*json)list(** [foreign_members t] will extract the name-value pairs from an object that
are not a part of the TopoJSON specification. *)valid:t->jsonoption(** [id t] returns the id associated with a given object. If there aren't any
this returns [None]s. *)valv:?id:json->?properties:properties->?foreign_members:(string*json)list->?bbox:floatarray->geometry->t(** Creates a new Geometry object. *)valto_json:t->jsonvalof_json:json->(t,[`Msgofstring])resultendmoduletypeS=sigtypejson(** The internal representation of JSON *)(** {2 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.geometry function}. For example:
{[
let is_linestring t =
let open Topojson in
match Geometry.geometry t with
| Geometry.LineString _ -> true
| _ -> false
]}*)moduleGeometry:Geometrywithtypejson=json(** {2 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. *)moduleTopology:sigtypet(** A topology object *)typetransform={scale:float*float;translate:float*float}(** A transform object *)valobjects:t->(string*Geometry.t)list(** The underlying objects of the topology object. *)valarcs:t->Geometry.Position.tarrayarray(** The database of linestrings used by other geometries. *)valforeign_members:t->(string*json)list(** The extra fields that were in the topology object. *)valtransform:t->transformoption(** Get the transform object of a Topology object. *)valv:?foreign_members:(string*json)list->?transform:transform->arcs:Geometry.Position.tarrayarray->(string*Geometry.t)list->t(** Construct a new topology object getting the arcs and the geometry
objects. *)valto_json:?bbox:floatarray->t->jsonvalof_json:json->(t,[`Msgofstring])resultend(** {2 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.*)typetopojson=|TopologyofTopology.t|GeometryofGeometry.t(** The underlying TopoJSON datastructure. *)typet(** The TopoJSON object. *)valtopology_exn:t->Topology.t(** Accessor for the TopoJSON data. This will try to access a
{!Topology.t}.contents
@raise Invalid_argument if the data is a geometry. *)valtopojson:t->topojson(** Accessor for the TopoJSON data. *)valbbox:t->floatarrayoption(** Accessor for the optional bounding-box for the entire TopoJSON object. *)valv:?bbox:floatarray->topojson->t(** Construct a new TopoJSON object, optionally with a bounding-box. *)valof_json:json->(t,[`Msgofstring])result(** [of_json json] converts the JSON to a topojson object (a type {!t}) or an
error. *)valto_json:t->json(** [to_json t] converts the TopoJSON object [t] to JSON. *)endmoduletypeTopojson=sigmoduletypeS=S(** Types for TopoJSON objects *)moduletypeJson=Json(** Types for the JSON parser. A user must provide a JSON parser to the
{!Make} functor in order to have a working TopoJSON library. *)(** A functor that takes a Json parsing implementation and returns a TopoJSON
parser and constructor. *)moduleMake(J:Json):Swithtypejson=J.tend