1

Recently, I want echarts , and I came across a map data format GeoJSON , Geo means geographic coordinates, and then JSON refers to a data format of type json

We can quickly obtain a map above the county level Cloud DataV If you want to draw a map at the county level, you need to think of something yourself.

For example, go to geojson site to draw. After the drawing is completed, you will finally get a JSON , and the format is GeoJSON exact.

And this article is to explain the specific meaning of each item in the data format GeoJSON

In addition to echarts, other map components are basically based on GeoJSON, such as Leaflet

Prepare

Before we formally understand GeoJSON , let's download the formed file. Taking Shangyi County, which is currently studied by the author, as an example, we download a file

Then use sublime open this file and format it. Finally found
A basic GeoJSON file has a main keyword: type :

{
    "type": "FeatureCollection",
    "features": [
    {
        "type": "Feature",
        "properties":
        {
            "adcode": 130725,
            "name": "尚义县",
            "center": [113.977713, 41.080091],
            "centroid": [114.147607, 41.123316],
            "childrenNum": 0,
            "level": "district",
            "acroutes": [100000, 130000, 130700],
            "parent":
            {
                "adcode": 130700
            }
        },
        "geometry":
        {
            "type": "MultiPolygon",
            "coordinates": [
                [
                    [
                        [114.35286, 40.73159],
                        [114.356768, 40.73224]
                    ]
                ]
            ]
        }
    }]
}
Note: Most of the basic data is omitted from the above file.

type

Root level type respectively FeatureCollection and Feature , represent set of feature values and eigenvalues.

Query rfc7946 white paper to get: when type is FeatureCollection , it must also have a features value, the type of the value is an JSON , and the type of each data is an Feature .

The white paper also gives an Feature characteristic value of 061c1b03e60171:

  • It has a geometry attribute whose value type is object , and its function is to describe (define) its graph type. If the current feature value has not been confirmed, it will be assigned a value of null.
  • Has a properties attribute. The type of the value of this attribute is object or null . It defines the relevant attributes of the map.
  • If the characteristic value needs to specify an identifier (ID), then the identifier should be in the form of a string or a number.

After reading the white paper, we probably learned: a map is composed of one or more Feature , and each Feature will define some attributes ( properties ) and the boundary data of the map ( geometry ).

Geometry

Geometry is translated into geometric figures. It is the core of the entire map. The data in it determines what the map looks like.

The types of geometric shapes are Position , Point , MultiPoint , LineString , MultiLineString , Polygon , MultiPolygon , GeometryCollection , 061c1b03e602a9, 061c1b03e602a9. Respectively represent: position, single point, multipoint, line, multiple lines, polygon, multiple polygonal collections,

This kind of type be defined keywords, such as our map to download the file type value MultiPolygon :

        "geometry":
        {
            "type": "MultiPolygon",

Indicates that the geometric shape is composed of multiple polygons.

The specific map data is defined in coordinates . When type is different, the type of coordinates

Interpretation

Through studying the white paper, combined with the map file we downloaded, we probably learned:

  1. A map file is composed of one or more feature values Feature . If we wish, we can give each feature value a name.
  2. A geometric shape can be specified for each specific value.
  3. When one geometric shape is not enough to meet the requirements, the type of the geometric shape can also be declared as GeometryCollection to define multiple geometric shapes.
  4. You need to specify a type for each geometric shape, the type is: point, line, polygon, etc.

With the above data format, other map software can draw maps based on the read data.

Hollow map

General maps can be obtained through the polygon selection provided by ali, but hollow maps will not work.
At this time, we need to select the outer circle first, then the inner circle, and then the next two files, and finally join together to make this look.

{
    "type": "Polygon",
    "coordinates": [
        [[1,2], [3, 4]],
        [[5,6], [7, 8]]
    ]
}

coordinates is the outer ring, and the second item is the inner ring.
It must be noted that the outer ring should be
The type of the hollow figure is Polygon, the first coordinate array is the outer circle coordinates in counterclockwise order, and the second coordinate array is the inner circle in clockwise order;

Reference documents (tools)

http://www.thingjs.com/guide/cn/tutorial_city_builder/Data_description/Online_tools.html
https://datav.aliyun.com/portal/school/atlas/area_generator
https://geojson.org/
http://geojson.io/
rfc7946 white paper


潘杰
3.1k 声望241 粉丝

引用和评论

0 条评论