Code Monkey home page Code Monkey logo

ocaml-topojson's Introduction

ocaml-topojson

A collection of libraries in pure OCaml for parsing, constructing, and manipulating TopoJSON objects.

Contents

Introduction

TopoJSON is an enhanced format for encoding GeoJSON geospatial data. In addition to the GeoJSON geometry types, viz. "Point", "LineString", "Polygon", "MultiPoint", "MultiLineString", "MultiPolygon", and "GeometryCollection", TopoJSON instigates a new type "Topology", which comprises of GeoJSON objects. A topology has a field objects mapped with one or more geometry objects by its name type.

TopoJSON Vs GeoJSON

TopoJSON has an arcs member which consists of the coordinates of the geometry types (except "Point" and "MultiPoint"). The value of the "arcs" member is an array of arrays of positions. This is a primary advantage over GeoJSON objects where each individual geometries have their own separately defined coordinates. See TopoJSON Format Specification to know more.

Motivation

TopoJSON helps to reduce the size of the geospatial data file in a way by eradicating the redundancy and eliminating the duplicate topology that is being shared by one or more geometries. For example, a common boundary that is being shared between two states/countries can be represented only once and can be referenced multiple times. To know more about TopoJSON and its related advantages.

Current status

Feature Status

  1. This library is capable of parsing a TopoJSON file as a whole.

  2. It supports both the TopoJSON objects - Topology and Geometry

  3. It underpins all the mandatory members of the Topology object - types and arcs.

  4. Other than the requisite fields to be supported by all the Geometry Objects i.e., the type and the coordinates/ arcs fields, it also supports the following members:

  • Properties : A geometry object can also additionally have a member with the name “properties”. The value of the properties field is an object (any JSON object or a JSON null value).
  1. Additional members/ fields that are upholded by both the modules:
  • Bounding Box : To consist of information on the coordinate range for a TopoJSON object may also have a member named “bbox”.

  • Foreign Members : Members or field that are no longer defined in the specification but are used in the TopoJSON document. Semantics do not apply to these foreign members and their descendants, irrespective of their names and values.

  1. Tranformation and Quantization are yet to be implemented.

Structure of the Code

  1. src : This directory consists of all the related implementations to parse TopoJSON objects including all the interfaces with types and signatures being required by the objects.
  2. test : Provides the test cases in the form of X.json file as well as modules to test them.

Examples

The first thing to do is initialise the Topjson module with a JSON parsing implementation. For these examples we'll use Ezjsonm, the parser can be found in doc/prelude.txt.

module Topojson = Topojson.Make (Ezjsonm_parser);;

Reading

A small example how this library is efficient in reading a json file (more particulary a TopoJSON file). This illustration depicts a TopoJSON object with type "Topology" which itself consists of a Geomtery object "Polygon".

# Topojson.of_json ( `O [ 
  ("type", `String "Topology"); 
  ("objects" , `O [  ("Instance" , `O [("type", `String "Polygon"); ("arcs", `A [ `A [`Float 0.]]) ]) ])  ; 
  ("arcs", `A [ `A [ `A [`Float 100.;`Float 0.]; `A [`Float 101.; `Float 0.]; `A [`Float 101.; `Float 1.]; `A [`Float 100.; `Float 1.]; `A [`Float 100.; `Float 0.]]] );
  ]);;    
- : (Topojson.t, [ `Msg of string ]) result = Ok <abstr>

ocaml-topojson's People

Contributors

iiitm-jay avatar patricoferris avatar mimi-tech avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.