Convert tables to geojson

This article shows how to convert tables to geojson data

Editing straight into the geojson file might work well for some, but for a lot of people it is probably more intuitive to work on a spreadsheet. You might also find data in a spreadsheet format. It does not matter if you use google sheets, excel or Open Office. Here are some hints for making it work:

You must have two columns with headers named lat and lon for geographical coordinates. As long as you have those two you can add as manu extra columns as you want. This is a datafile I used in a news map while working at nyhetsgrafikk. This file has a mix between norwegian and english, but for the purpose of learning the technique that does not matter.

https://docs.google.com/spreadsheets/d/1YGmpAlhoLHj9CYTM6mZcTKLRWxeE5WopcnjArC0v0rw/edit?usp=sharing

You must save the file as .csv. CSV is short for comma separated values and is a very common data format on the web and elsewhere. In google sheets choose download as csv and save it locally. You can also save as csv from excel.

If your document looks like a mess upon opening in a spreadsheet there is a high probability that the spreadsheet software has not recognized the separator in your file. If your data is not spread across different columns this is probably happening. There is a simple fix for that. Close the csv file again in your spreadsheet and open the same csv file in a code edior such as Visual studio code. You should see a bunvh of text with commas in between. Place your marker at the very start of the document, line 1 before the text and press enter so you have a blank line on line 1. Then type:

sep=,

This specifies to the spreadsheet editor what separates the data in this file. In this case it is a comma, if the separator was a semicolon you would write

sep=;

Now save it and reopen it in your spreadsheet editor. Hopefully you can now see the data spread across columns.

So if this looks ok you can navigate to geojson.io

Now click on the tab that says ‘table’ next to the ‘<>JSON’ tab. Find your csv file in the file browser and drag in into geojson.io. You should now see features on the map and if you click back to the ‘<>JSON’ tab you can see that your csv data has been converted to geojson.