GeoJSON

Earlier this day, while I was viewing a github repository I saw something new

geojson-example.png

What heck was this, the file extension was .geojson. I began wondering if it was some image, viewing the raw file it seemed to be a json file. Then why it was getting rendered as a map. Googling about geojson landed me to a rfc stating :

GeoJson is a format for encoding a variety of geographic data structures. It is a geospatial data interchange format which is based on JSON.

So what actually is geojson ?

It is a data interchange format which represent data about geographic features, their properties and their spatial extents. It may represent a region of space(a Geometry), a spatially bounded entity(a Feature), or a list of features(a Feature Collection).

Example

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature"
      "geometry": {
        "type": "Point",
        "coordinates": [102.0, 0.5]
      },
      "properties": {
        "marker-color": "#000000" ,
        "name": "My_Marker",
        "marker-symbol": "my_marker"
      }
    },
    ...
    ...
    ...
  ]
}

So using geojson we write the geometries we want to draw, point we want to mark etc in the map as a json object and they can be easily rendered in maps. GeoJSON is supported by numereous mapping packages including OpenLayers, Leaflet, MapServer etc. Bing Yahoo and Google maps also supports GeoJSON in their API services.

Github out of the box supports GeoJSON rendering.

Geometries we want to draw are not just limited to Points. GeoJSON includes geometries including

  • Point
{ 
  "type": "Point", 
  "coordinates": [30, 10]
}

  • LineString
{ 
  "type": "LineString",
  "coordinates": [
    [30, 10], [10, 30], [40, 40]
  ]
}

  • Polygon
{ 
  "type": "Polygon", 
  "coordinates": [
    [
      [35, 10], [45, 45], [15, 40], [10, 20], [35, 10]
    ], 
    [
      [20, 30], [35, 35], [30, 20], [20, 30]
    ]
  ]
}

Along with these single part geometries geojson also supports multipart geometries where type in geometries includes a prefix Multi(as in MultiPoint, MultiLineStrings) in which co-ordinates can be provided as an array of co-ordinates provided earlier.

GeoJSON

Resources for further Read