How to convert a string of coordinates to a readable polyline for export as a geojson

by k.renee   Last Updated March 29, 2018 00:22 AM

I need to take an xls file which has multiple columns of data, and a column called coordinates which is a string of coordinates (ex. 147.775364306,-20.49918551,0 147.776402476,-20.500021717,0 147.778202959,-20.5015774579999,0), and convert it to a geojson file. How can I do this easily?

Answers 1

Your coordinates look as though they are in the format x,y,z and are space separated. This is already pretty close to GeoJSON format. Presuming your Excel sheet looks like this:

      A       B       C                             D       
  1 | data1 | data2 | coordinates                 | geoJson |
  2 | foo   | bar   | x1,y1,z1 x2,y2,z2, x3,y3,z3 |         |  
  3 | other | line  | xa,ya,za xb,yb,zb, xc,yc,zc |         |  

You could easily use the following Excel function to create a column of GeoJSON compatible points under the "geoJSON" heading above (cell D2):

=CONCATENATE("{ 'type':'LineString','coordinates':[[",SUBSTITUTE(C2, " ", "],["), "]]}")

This will give you the result

{ 'type':'LineString','coordinates':[[x1,y1,z1],[x2,y2,z2],[x3,y3,z3]]}

For each of your rows you will have the GeoJSON representation of the LineString, which you can then save as a file as you please. Please comment if this is not what you are looking for and I will adjust my answer!

July 25, 2016 14:19 PM

Related Questions

Get my x, y, z position as 0,0,0

Updated November 10, 2017 09:22 AM

Representing Time in GeoJSON?

Updated September 12, 2017 09:22 AM

Fetch lat lon from eachLayer that uses coordinates

Updated January 11, 2018 07:22 AM