GEO2311

GeoJSON

Hva er egentlig JSON?

{"employees":[
    {"firstName":"John", "lastName":"Doe"}, 
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
]}

JavaScript Object Notation

 

- det vil si: JSON ser ut som javascript-objekter i såkalt "literal notation"

var employees = [
    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter","lastName": "Jones"}
];

Fra json.org:

 

JSON is built on two structures:

 

  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
     
  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
{"employees":[
    {"firstName":"John", "lastName":"Doe"}, 
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
]}

JSON ble opprinnelig spesifisert av Douglas Crockford,

- kjent  javascript-guru

JSON er laget for å være et lettvekts datautvekslingsformat

JSON er en åpen standard,
spesifisert i   ECMA 404 /  IETF RFC nr. 7159

Gå igjennom W3Schools JSON tutorial for å lære litt mer.

Flere ressurser finnes på json.org

Noen fordeler med JSON

 

- lett å lese

- tar liten plass - sparer båndbredde

- lett å ta i bruk i på nettsider

- enkelt å konvertere JSON-tekst til javascript-objekter

  - se eksempel på W3Schools

JSON egner seg godt i AJAX-appikasjoner

Fra AJAX-tutorial på W3Schools:

 

AJAX = Asynchronous JavaScript and XML.

 

AJAX is not a new programming language, but a new way to use existing standards.

 

AJAX is the art of exchanging data with a server, and updating parts of a web page - without reloading the whole page.

GeoJSON

- uoffisiell standard: geojson.org

{
  "type": "FeatureCollection",
  "crs": {
    "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
    }
  },
  "features": [
    {
      "type": "Feature",
      "properties": {
        "title": "BEKKEFARET",
        "ogc_fid": 2,
        "i_alt_2008": 177,
        "i_alt_2009": 184,
        "menn_2009": 93,
        "kvinner_20": 91,
        "objtype": "Grunnkrets",
        "grunnkrets": 5010408,
        "gkretsnavn": "BEKKEFARET",
        "komm": 501
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              10.453684193506337,
              61.09958227201604
            ],
  
            [
              10.465148818845291,
              61.09854161547057
            ],

............

            [
              10.453684193506337,
              61.09958227201604
            ]
          ]
        ]
      }
    }
  ]
}
Made with Slides.com