Everything about GeoJSON

Krishna G. Lodha
SpatialOps
Published in
4 min readNov 22, 2020

As the name suggests, GeoJSON is a combination of two words, Geographical and JSON, but if we try to understand it in more depth, the simple definition can be A JSON object accomodating information about the specific geometry (e.g. Point, Line, Polygon, etc.) along with optional metadata (e.g. id, etc.)
In a world full of APIs, developers rely on information communicated mostly through JSON or XML most of the time. Thus to talk smoothly with existing logics and standards, GeoJSON was introduced.

What is a GeoJSON file?

GeoJSON file is written in the same way JSON is written. the extension for GeoJSON file is (well no surprise here! ) .geojson

GeoJSON file follows a pattern, which is pretty standard and if broken, might week the geojson file. A standard GeoJSON file looks like this

{
"type": "FeatureCollection",
"features": [
// GeoJSON features goes here
],
// Extra optional metadata
"crs": {
"type": "name",
"properties": {
"name": "EPSG:3857"
}
}
}

It is a Javascript Object or Python Dictionary, with certain keywords that must be there and certain optional

"type" : "FeatureCollection"

this must be available in the GeoJSON file as it indicated that the file contains features.

"features" : [ 
// Here we add all the features
]

A typical example of GeoJSON Point feature is

{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [21.22,71.23]
},
"properties": {
"Cafe_name": "Central Perk",
"Owner": "Gunther"
}
}

A typical example of GeoJSON LineString feature is

{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[8816056.117179131,2807009.212192692],
[8829495.514106864,2610747.6742997607],
[8942180.802355455,2644853.040425635]
]
},
"properties": {
"Street_name": "Wall street"
}
}

A typical example of GeoJSON Polygon feature is

{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[9816056.117179131,2807009.212192692],
[9829495.514106864,2610747.6742997607],
[9942180.802355455,2644853.040425635],
[9816056.117179131,2807009.212192692]
]
]
},
"properties": {
"City": "Pasadena"
}
}

Apart from these standard geometries, we can also draw MultiPoint, MultiLineString, MultiPolygon, etc.

Apart from "type" and "features" , you can add certain metadata properties to GeoJSON which will be optional and will serve just the informational purpose. e.g.

"crs": {
"type": "name",
"properties": {
"name": "EPSG:3857"
}
}

An example of complete GeoJSON is as follow

{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [1421881.6001608493,87787.9269855246]
},
"properties": {
"Cafe_name": "Central Perk",
"Owner": "Gunther"
}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[2377382.6722396947,1196468.8037478637],
[2440022.8169193966,721756.6395827765],
[1864031.5902764509, 590093.8583615604],
[2377382.6722396947,1196468.8037478637]
]
]
},
"properties": {
"City": "Pasadena"
}
}
],
"crs": {
"type": "name",
"properties": {
"name": "EPSG:3857"
}
}
}

*Quick Note: Make sure that you remove all the comments from GeoJSON, as it is not allowed to write comments

Saving GeoJSON with .json

Technically, Yes. GeoJSON is also at the end of the day JSON, you can save it as a .json file as well, given that you follow the standard mentioned earlier

How to Create GeoJSON

GeoJSON can be created with variety of online tools or using the software as well. Coordinates for the geometry are coordinate reference systems (CRS), dependant. That means different CRS will have different coordinates.

You can try my tool anyGeoJSON 😁 (anygeojson.com)

This tool allows users to select the CRS of their choice (3857, 4326, 32643, etc.) and then draw geometry. GeoJSON for that geometry is created in realtime.

AnyGeoJSON.com current Setup

You can also use software such as QGIS, ArcMap, etc. for the same purpose

How to View GeoJSON

GeoJSON is a vector file, hence it doesn't have a sense of style in itself. Tools such as QGIS, or anyGeoJSON has a default style feature which will enable you to visualize the data on the map, it is important to set the map in the same CRS of GeoJSON, otherwise, it might create false results.

What are the alternatives of GeoJSON

Geospatial Data can be stored in various ways, some of them are as follows:
1. ESRI Shapefile
2. KML/KMZ
3. GML

How to generate GeoJSON

You can use tools such as https://quickmaptools.com/ to convert your data from various formats to GeoJSON within browser itself.

About me 🤠

Hi, I’m Krishna Lodha, I’m a full-stack Web GIS developer. I’m really enthusiastic about the power of locations and what story it tells us. Read more about me at http://krishnaglodha.com, to get more information about this code or suggest a better way to do it. ping me on LinkedIn 💼 , Twitter 🐦 , and Youtube📺

I write most of my post for the ‘Random GIS Talks’, which is dedicated to posts regarding GIS installations, inventions, technologies, etc. make sure to hit the subscribe button to stay updated for further posts 👉🏻 here 👈🏻

Adios!

--

--