Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Artifact ID: | 2c5eed193c4b1282fe1c3120b1b8bcc340667de3 |
---|---|
Page Name: | Supporting GeoJSON |
Date: | 2019-01-21 15:24:02 |
Original User: | sandro |
Parent: | 680b5f8ea26cfdade55a6f7b3a693aebaf735957 (diff) |
Next | fe965f3f2f8f06d0e43df717327b8de9b75896b4 |
Content
Introduction
GeoJSON is an open standard data format based on JSON (JavaScript Object Notation), a very popular data format widely adopted by many web-apps as a replacement for XML.The specific scope of GeoJSON is extending the basic capabilities of JSON so to adequately support geographic features including both Geometries and non-spatial attributes.
GeoJSON exists since many years being based on a loose and informal data specification.
Only very recently (2016) it has finally become a respectable standard format based on a formal specification, that is RFC 7946 released by IETF (Internet Engineering Task Force).
Note: RFC 7946 introduced several relevant requirements and restrictions, so that pre-RFC and post-RFC GeoJSON files are not mutually interoperable.
A very remarkable feature of RFC 7946 is that it's explicitly declared to be a fixed and immutable specification.
There will never be updated versions of GeoJSON; even the slighter change will inexorably require changing the name from GeoJSON to some else.
Such a restrinction is obviosly intended to ensure a very strong stability during the time.
The most obvious competitors of GeoJSON are the ESRI Shapefile and GML
The following chart will quickly summarize the main differences between them.
Topic | Shapefile | GML | GeoJSON | Remarks |
---|---|---|---|---|
File organization | At least three independent files sharing the same name and respectively identified by suffixes .shp, .shx and .dbf
|
GML is based on XML, and conseguently just requires a single, monolithic text file. As any other XML file, GML too can be strongly constrained to verbatim respect a formally defined XML Schema |
Single monolithic text file. Similar in this to XML, but explicitly intended to be by way simpler and less verbose. |
The three-files layout of Shapefile is clearly obsolete, and it frequently poses many headaches causing unexpected troubles. The single-file layout adopted by both GML and GeoJSON is clearly better and safer, and being text files they can be easily inspected and eventually debugged just using any generic text editor without requiring any specific tool. |
Geometry classes |
Notes:
|
GML allows many different ways for defining the same Geometry, and the specifications radically changed from version to version. GML has a really impressive flexibily (e.g. each single Geometry can freely declare its own SRID), but at the cost of imposing an overwhelming complexity. |
Notes:
|
|
Dimensions |
|
|
Note: RFC 7946 just supports 2 or 3 coordinates, and the third value (when declared) is always expected to correspond to an Elevation (Z axis). Supporting XYM or XYZM is not technically unfeasible. Both writers and readers could support such options, but all this is surely outside the standard and will surely impair the universal portability of any non canonical file. |
GeoJSON lacks the capability to support XYM and XYZM, if not by adopting vicious tricks. May well be it's not a forbidding limitation in many common cases, but it's indisputably a limitation. |
SRID |
Not internally declared by the Shapefile itself. Deploying a further .prj file describing the intended SRID is the usual solution adopted by ESRI itself, but correctly parsing these extra files is an usually flimsy process falling outside real capabilities of many third party readers. |
Each single Geometry is allowed to freely define its own SRID; and is also possible to define the SRID for a whole layer. |
Accordingly to RFC 7946 all coordinates are always expeted to be expressed as longitues and latitudes (in this exact order). So any canonical GeoJSON file is always expected to reference SRID=4326 WGS 84. Using any other SRID is technically possible, but requires a conventional agreement between writers and readers, but all this is surely outside the standard and will surely impair the universal portability of any non canonical file. |
The unique effective solution is the one adopted by GML. Both Shapefile and GeoJSON are clearly inferior under this peculiar aspect. |
Non-spatial attributes |
Note: all attribute names are limited to a length of max. 10 bytes. There is no safe way for declaring NULL values. |
Any possible datatype you can imagine. And defining further derived datatypes is an option supported by XML Schema. Note: attribute names and text values can have any arbitrary unconstrained length. |
Note: attribute names can have any arbitrary unconstrained length. |
|
Charset encoding |
Not internally defined by the Shapefile itself. Attempting to guess the appropriate charset encoding required by some Shapefile is more a magic art than rational science. |
Always internally defined by the GML/XML file itself. |
RFC 7946 strictly requires that all GeoJSON files must be encoded as UTF-8 In pure theory both UTF-16 and UTF-32 could be used for encoding a legitimate GeoJSON file, but such options seems to be very rarely (if never) adopted in real world. |
|
Skeletal GeoJSON anathomy
{ "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"} } }] }As you can easily notice, GeoJSON has a plain regular structure and is decisely most concise and less verbose than GML/XML:
- Every GeoJSON file must contain a FeatureCollection object.
- A FeatureCollection contains one or more individual Feature objects.
- Each Feature is expected to declare a Geometry and a properties array.
- Each property coresponds to an attribute with a name and a value .
- Each Feature is expected to declare a Geometry and a properties array.
- A FeatureCollection contains one or more individual Feature objects.
Short conclusions
GeoJSON is widely adopted by many web-apps; being a notation directly based on JavaScript it has a natural integration in popular client-side JS libraries such as OpenLayers and Leaflet.It's adequately supported by GDAL, and consequently by many others free/libre sw components (as e.g. MapServer and GeoServer).
Outside the web-gis arena GeoJSON still has limited adoption, and it's a real pity because under many aspects it's a very valid full replacement for the nowadays irremediably obsolete Shapefile.
Starting since version 5.0.0 SpatiaLite offers full supports to GeoJSON as defined by RFC 7946.
The implementation strongly resembles the one supported by all previous versions for Shapefile, and this isn't at all surprising because both them cover the same functional area.
back