[D3.js getting started series-10.3] Difference and connection between GeoJSON and TopoJSON files, geojsontopojson

Source: Internet
Author: User

[D3.js getting started series-10.3] Difference and connection between GeoJSON and TopoJSON files, geojsontopojson

My personal blog is: www.ourd3js.com

The csdn blog is blog.csdn.net/lzhlzz.

Please indicate the source for reprinting. Thank you.

A friend left a message a few days ago asking about the relationship between the GeoJSON file and the TopoJSON file. I am not very clear about it. After some queries, I will sort them out as follows. I hope you can testify.

These two types of files are based on the JSON syntax. First, let's talk about the JSON syntax and the file.

1. JSON format

JSON (JavaScript Object Notation) is a lightweight data exchange language based on text and easy to read. Although JSON is a subset of Javascript, JSON is a language-independent text format and is similar to the C language family.

The JSON format [1] is as follows:

  • Object: data of an object is written in braces {...}
  • Name/value (collection): each object is composed of a series of Names/values (collection). Names/values are separated by commas. A name can be a string; a value can be a string, a value, a Boolean value, an ordered list, or a null value.
name:value

Because name must be a string, it must be written in double quotation marks.

  • Ordered list of values (Array): The list is written [...]
[collection, collection, collection, ...]
2. GeoJSON format

GeoJSON is a format used to encode geographical data structures. It is only a format that uses the preceding JSON format to describe geographical information. Its syntax is the same as that of JSON. It only regulates the names, as shown in [2]:

{ "type": "FeatureCollection",    "features": [      { "type": "Feature",        "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},        "properties": {"prop0": "value0"}        },      { "type": "Feature",        "geometry": {          "type": "LineString",          "coordinates": [            [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]            ]          },        "properties": {          "prop0": "value0",          "prop1": 0.0          }        },      { "type": "Feature",         "geometry": {           "type": "Polygon",           "coordinates": [             [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],               [100.0, 1.0], [100.0, 0.0] ]             ]         },         "properties": {           "prop0": "value0",           "prop1": {"this": "that"}           }         }       ]     }

Specific can participate in http://geojson.org/

3. TopoJSON format

TopoJSON is a simplified version of GeoJSON. It can be said that it is a child of GeoJSON. The author of D3.js believes that GeoJSON is not very good and he prefers TopoJSON format.

Compared with GeoJSON, TopoJSON reduces the file size by 80% because:

  • Only one line is recorded (for example, only one line is recorded between Guangxi and Guangdong)
  • Use only integers instead of floating-point numbers.

However, TopoJSON seems to be widely used only in D3.js and is not a globally accepted format.

 

Note that, whether GeoJSON or TopoJSON, they are essentially JSON-format files that follow the JSON syntax, except that the variable names are different.

In the http://mapshaper.org/can try to convert GeoJSON and TopoJSON data, we will see for the same geographic data file, TopoJSON file size is approximately equivalent to 20% of GeoJSON, this is quite simple and effective to solve the slow reading speed caused by the large amount of files.

[1] http://zh.wikipedia.org/wiki/JSON

[2] http://geojson.org/




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.