Luis Miguel Agudo Bravo
GIS Developer
14-15 March 2019
MarSP: 2nd Capacity Building Workshop
What is a JSON file?
JSON stands for JavaScript Object Notation
JSON is a lightweight format for storing and transporting data
JSON is often used when data is sent from a server to a web page.
JSON is "self-describing" and easy to understand
Data is in name/value pairs
Separated by colons
Data is separated by commas
Curly brackets hold objects
Square brackets hold arrays
JSON Syntax Rules
{
"Song": {
"title": "Out Of Control",
"band": "Rolling Stones",
"players": [
"Mick Jagger",
"Keith Richards",
"Charlie Watts",
"Ron Wood"
]
}
}
Why use JSON?
Since the JSON format is text only, it can easily be sent to and from a server, and used as a data format by any programming language.
Why use JSON?
Easy to understand
Why use JSON?
JavaScript has a built in function to convert a string, written in JSON format, into native JavaScript objects:
JSON.parse()
So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.
Why use JSON?
let text = '{ "employees" : [' +
'{ "firstName":"John" , "lastName":"Doe" },' +
'{ "firstName":"Anna" , "lastName":"Smith" },' +
'{ "firstName":"Peter" , "lastName":"Jones" } ]}';
let obj = JSON.parse(text);
Why use JSON?
Most of Web Services and APIs send as result a JSON Object
//Function to get a short url with Google API
function shortURl (longURL) {
let url = {
"longDynamicLink": "https://example.page.link/?link=http://www.example.com/&apn=com.example.android&ibi=com.example.ios",
"suffix": {
"option": "UNGUESSABLE"
}
}
$.ajax({
url: 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?&key=AIzaSyCM8UYPSDicKI0Y1dCBG5TMCpB6xB9iotc',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data:JSON.stringify(url),
contentType:"application/json",
dataType:"json",
success: function(response) {
let result = JSON.parse(response);
console.log(result);
}
});
}
GeoJSON is a format (JSON) for encoding a variety of geographic data structures.
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}
GeoJSON supports the following geometry types: Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon.
Geometric objects with additional properties are Feature objects. Sets of features are contained by FeatureCollection objects.
ogr2ogr -f PostgreSQL PG:"dbname=gis user=alex" roads.geojson -nln roads
Online Tools (https://mapshaper.org/)
QGIS
APIs (GitHub)
OGR2OGR
SHP / GeoJSON
ogr2ogr -f GeoJSON -t_srs crs:84 [name].geojson [name].shp
The defined encodings are work-in-progress, and at this point, have not been endorsed by the OGC or any other standards organization. They may (and probably will) change in a backwards incompatible way during the drafting process.
There is an on-going discussion in leveraging the O&M encodings in the INSPIRE alternative encodings action (MIWP 2017.2) for a simplified encoding of the INSPIRE O&M datasets.
O&M Simple Features - GeoJSON encoding
{
"type": "Feature",
"id": "f-1",
"geometry": {
"type": "Point",
"coordinates": [ 24.96131, 60.20307 ]
},
"properties": {
"observationType": "MeasureTimeseriesObservation",
"phenomenonTimeStart": "2017-08-17T12:00:00Z",
"phenomenonTimeEnd": "2017-08-17T18:00:00Z",
"resultTime": "2017-08-17T12:11:20Z",
"usedProcedureName": "Meteorological surface observations",
"usedProcedureReference": "http://xml.fmi.fi/process/met-surface-observations",
"observedPropertyName": "air_temperature",
"observedPropertyReference": "http://vocab.nerc.ac.uk/collection/P07/current/CFSN0023/",
"samplingFeatureName": "Helsinki Kumpula weather observation station",
"ultimateFeatureOfInterestName": "Helsinki Kumpula",
"ultimateFeatureOfInterestReference": "http://sws.geonames.org/843429/about.rdf",
"timeStep": [
"2017-08-17T12:00:00Z",
"2017-08-17T13:00:00Z",
"2017-08-17T14:00:00Z",
"2017-08-17T15:00:00Z",
"2017-08-17T16:00:00Z",
"2017-08-17T17:00:00Z",
"2017-08-17T18:00:00Z"
],
"unitOfMeasureName": "Degree Celsius",
"unitOfMeasureReference": "http://www.opengis.net/def/uom/UCUM/degC",
"result": [12.5, 12.0, 11.0, 13.2, 13.5, 14.1, 14.1]
}
}
<omsf:MeasureTimeseriesObservation gml:id="f-1">
<omsf:phenomenonTimeStart>2017-08-17T12:00:00Z</omsf:phenomenonTimeStart>
<omsf:phenomenonTimeEnd>2017-08-17T18:00:00Z</omsf:phenomenonTimeEnd>
<omsf:resultTime>2017-08-17T12:11:20Z</omsf:resultTime>
<omsf:usedProcedure xlink:href="http://xml.fmi.fi/process/met-surface-observations" xlink:title="Meteorological surface observations" />
<omsf:observedProperty xlink:href="http://vocab.nerc.ac.uk/collection/P07/current/CFSN0023/" xlink:title="air_temperature" />
<omsf:samplingFeatureName>Helsinki Kumpula weather observation station</omsf:samplingFeatureName>
<omsf:geometry>
<gml:Point gml:id="p-1" srsName="http://www.opengis.net/def/crs/EPSG/0/4258" srsDimension="2">
<gml:pos>60.20307 24.96131</gml:pos>
</gml:Point>
</omsf:geometry>
<omsf:ultimateFeatureOfInterestName>Helsinki Kumpula</omsf:ultimateFeatureOfInterestName>
<omsf:ultimateFeatureOfInterestReference xlink:href="http://sws.geonames.org/843429/about.rdf"/>
<omsf:timeStep>2017-08-17T12:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T13:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T14:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T15:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T16:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T17:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T18:00:00Z</omsf:timeStep>
<omsf:unitOfMeasure xlink:href="www.opengis.net/def/uom/UCUM/degC" xlink:title="Degree Celsius"/>
<omsf:result>12.5</omsf:result>
<omsf:result>12.0</omsf:result>
<omsf:result>11.0</omsf:result>
<omsf:result>13.2</omsf:result>
<omsf:result>12.5</omsf:result>
<omsf:result>14.1</omsf:result>
<omsf:result>14.1</omsf:result>
</omsf:MeasureTimeseriesObservation>
<omsf:MeasureTimeseriesObservation gml:id="f-1">
<omsf:phenomenonTimeStart>2017-08-17T12:00:00Z</omsf:phenomenonTimeStart>
<omsf:phenomenonTimeEnd>2017-08-17T18:00:00Z</omsf:phenomenonTimeEnd>
<omsf:resultTime>2017-08-17T12:11:20Z</omsf:resultTime>
<omsf:usedProcedure xlink:href="http://xml.fmi.fi/process/met-surface-observations" xlink:title="Meteorological surface observations" />
<omsf:observedProperty xlink:href="http://vocab.nerc.ac.uk/collection/P07/current/CFSN0023/" xlink:title="air_temperature" />
<omsf:samplingFeatureName>Helsinki Kumpula weather observation station</omsf:samplingFeatureName>
<omsf:geometry>
<gml:Point gml:id="p-1" srsName="http://www.opengis.net/def/crs/EPSG/0/4258" srsDimension="2">
<gml:pos>60.20307 24.96131</gml:pos>
</gml:Point>
</omsf:geometry>
<omsf:ultimateFeatureOfInterestName>Helsinki Kumpula</omsf:ultimateFeatureOfInterestName>
<omsf:ultimateFeatureOfInterestReference xlink:href="http://sws.geonames.org/843429/about.rdf"/>
<omsf:timeStep>2017-08-17T12:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T13:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T14:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T15:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T16:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T17:00:00Z</omsf:timeStep>
<omsf:timeStep>2017-08-17T18:00:00Z</omsf:timeStep>
<omsf:unitOfMeasure xlink:href="www.opengis.net/def/uom/UCUM/degC" xlink:title="Degree Celsius"/>
<omsf:result>12.5</omsf:result>
<omsf:result>12.0</omsf:result>
<omsf:result>11.0</omsf:result>
<omsf:result>13.2</omsf:result>
<omsf:result>12.5</omsf:result>
<omsf:result>14.1</omsf:result>
<omsf:result>14.1</omsf:result>
</omsf:MeasureTimeseriesObservation>
GML vs GeoJSON
{
"type": "Feature",
"id": "f-1",
"geometry": {
"type": "Point",
"coordinates": [ 24.96131, 60.20307 ]
},
"properties": {
"observationType": "MeasureTimeseriesObservation",
"phenomenonTimeStart": "2017-08-17T12:00:00Z",
"phenomenonTimeEnd": "2017-08-17T18:00:00Z",
"resultTime": "2017-08-17T12:11:20Z",
"usedProcedureName": "Meteorological surface observations",
"usedProcedureReference": "http://xml.fmi.fi/process/met-surface-observations",
"observedPropertyName": "air_temperature",
"observedPropertyReference": "http://vocab.nerc.ac.uk/collection/P07/current/CFSN0023/",
"samplingFeatureName": "Helsinki Kumpula weather observation station",
"ultimateFeatureOfInterestName": "Helsinki Kumpula",
"ultimateFeatureOfInterestReference": "http://sws.geonames.org/843429/about.rdf",
"timeStep": [
"2017-08-17T12:00:00Z",
"2017-08-17T13:00:00Z",
"2017-08-17T14:00:00Z",
"2017-08-17T15:00:00Z",
"2017-08-17T16:00:00Z",
"2017-08-17T17:00:00Z",
"2017-08-17T18:00:00Z"
],
"unitOfMeasureName": "Degree Celsius",
"unitOfMeasureReference": "http://www.opengis.net/def/uom/UCUM/degC",
"result": [12.5, 12.0, 11.0, 13.2, 13.5, 14.1, 14.1]
}
}
GeoJSON vs GML
Easy to read
Easy to use in Javascript
Generally smaller in size then GML
It's not a official standard, but it is supported on both Leaflet, Openlayers and Geoserver and on many gis-desktop apps like QGIS.
Shapefile advantages :
Shapefile disadvantages:
Shapefile disadvantages:
5. Limited data types. Limited to float, integer, date and text with a maximum of 254 characters. There is no support for more advanced data fields such as blobs, images or arrays.
6. Unknown character set. There is no way to specify this in the file header. The support for Unicode characters is also very limited.
7. It is limited to 2 GB of file size.
8. No topology in the data.
Shapefile disadvantages:
9. Only can store one kind of geometry by file. There is no way to save mixed geometries.
10. 3D support is very limited. There is no way to store 3D data with textures or aspects.
What are the alternatives to the shapefile?
Why choose GeoPackage?
GeoPackage is one of the most hopeful SIG formats, designed for today's modern applications.
GeoPackage is published as standard by the OGC and has been built using SQLite as database management system (DBMS).
GeoPackage advantages :
GeoPackage advantages :
5. It is designed to store complex and massive data (up to 140 TB). In addition the attributes of the geometries can contain very long names.
6. GDAL supports GeoPackage entities. This open source library written in C serves to convert data formats. GDAL is the most widely used library.
GeoPackage advantages :
7. All reference GIS software can read GeoPackage files. For example ArcGIS or QGIS can read and write. Also can be used in ArcGIS Pro, GeoServer (importing and serving the data as OGC web standard), or Leaflet and Openlayers.
8. GeoPackages are particularly useful on mobile devices and places where there is limited connectivity and bandwidth.
GeoPackage disadvantages:
1. Relatively young (Encoding Standard (1.0) adopted by OGC in 2014). (But honestly, that’s not a real con…).
2. Raster support is relatively limited.
3. The SQLite database used is a complex binary format.
Import / Export Geopackage
Version ≥ 10.3
Import / Export Geopackage
Import / Export Geopackage
Luis Miguel Agudo
By Luis Miguel Agudo Bravo