The GeoJSON Format
General notes and remarks
Abreviations of interest,
- WKB - Well Known Binary.
- WKT - Well Known Text.
Introduction
GeoJSON is a geospatial data interchange format based on JavaScript Object Notation (JSON). It defines several types of JSON objects and the manner in which they are combined to represent data about geographic features, their properties, and their spatial extents. GeoJSON uses a geographic coordinate reference system, World Geodetic System 1984, and units of decimal degrees.
It is specified by the technical note RFC7946[1][3]
Summary of representations
Encodes a variety of geographic data such as,
Geometry
: A region of space. The geometry types are, *Point
LineString
Polygon
MultiPoint
MultiLineString
MultiPolygon
GeometryCollection
Feature
: A spatially bounded entity. Features containGeometry
objects as defined above.FeatureCollection
: A list ofFeature
s. FeatureCollection containsFeature
objects defined above.ForeingMembers
: GeoJSON allows the inclusion of extra object members not specified in [1]
The Geometry
Core concept: the positon
Fundamental geometry construct consisting of an array of numbers that we will call coordinates
. There must be at lest two elements in the array: longitude and latitude or easting and northing. The third optional element is elevation or altitude.
All GeoJSON coordinates must be in the geographic coordinate reference system, using the World Geodetic System 1984 (WGS 84)[1].
The positions are core concepts in building,
- One position for a
Point
geometry. - Array of positions for a LinearString or
MultiPoint
geometry. - Array of
LinearString
in case of aPolygon
, orMultiLineString
geometry - Array of
Polygon
coordinates in case ofMultiPolygon
.
A line between two positions is a straight Cartesian line.
Examples of Geometries
Point
The template is as follows,
{
"type": "Point",
"coordinates": [lon, lat]
}
Remember that lon and lat are in the WGS84 coordinate system. The following is a valid point,
{
"type": "Point",
"coordinates": [100.0, 0.0]
}
LineString
{
"type": "LineString",
"coordinates": [
[100.0, 0.0],
[101.0, 1.0]
]
}
Polygon
Consider the concept of linear ring. A linear ring is a closed LineString
with four or more positions,
- The first and last positions are equivalent, and they MUST contain identical values; their representation SHOULD also be identical.
- A linear ring is the boundary of a surface or the boundary of a hole in a surface
- A linear ring MUST follow the right-hand rule with respect to the area it bounds, i.e., exterior rings are counterclockwise, and holes are clockwise.
For type Polygon
, the coordinates
member MUST be an array of linear ring coordinate arrays.
No holes:
{
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
}
With holes:
{
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
],
[
[100.8, 0.8],
[100.8, 0.2],
[100.2, 0.2],
[100.2, 0.8],
[100.8, 0.8]
]
]
}
MultiPolygon
For type MultiPolygon
, the coordinates
member is an array of Polygon coordinate arrays.
Crossing the antimeridian
In representing Features
that cross the antimeridian[2] , it is adviced to split the geometries so that neither of them cross the antimeridian. For example like the following MultiLineString
{
"type": "MultiLineString",
"coordinates": [
[
[170.0, 45.0], [180.0, 45.0]
], [
[-180.0, 45.0], [-170.0, 45.0]
]
]
}
Feature
A Feature
object represents a spatially bounded thing. Every Feature
object is a GeoJSON object no matter where it occurs in a GeoJSON text.
- A
Feature
object has a"type"
member with the value"Feature"
. - A
Feature
object has a member with the name"geometry"
whose value SHALL be either aGeometry
object as defined above or, in the case that theFeature
is unlocated, a JSONnull
value. - A
Feature
object has a member with the name"properties"
. The value of the properties member is an object (any JSON object or a JSON null value).
The following example illustrates the way a Feature
object is specified [3],
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}
Foreing Memebers
For the Feature
below, we can specify a foreing member called title
and the GeoJSON will still be valid[1].
{
"type": "Feature",
"id": "f1",
"geometry": {...},
"properties": {...},
"title": "Example Feature"
}
Libraries that deal with GeoJSON
- https://github.com/frewsxcv/python-geojson.
- https://github.com/project-open-data/esri2open.
- https://github.com/makinacorpus/django-geojson.
- Github search for python repositories
Another interesting resource for GeoJSON is geojson.io