Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

Takes CSV or tab-delimited data from Excel and converts it into several web-friendly formats, include JSON and XML.
View it in action here: http://shancarter.github.com/mr-data-converter/

__GEOJSON (POI) render__
GEOJSON render takes coordinates of the POI from the column called "lat" or "lattitude" and "long" or "longitude". The rest of the columns will be converted to properties of the POI.
__Sample__
`team,type,city,latitude,longitude`
83 changes: 83 additions & 0 deletions js/DataGridRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,89 @@ var DataGridRenderer = {

return outputText;
},

//---------------------------------------
// GEOJSON properties
//---------------------------------------

geojson: function (dataGrid, headerNames, headerTypes, indentStr, newLineStr) {

// utils
var repeat = function(s,n) {
return new Array(n + 1).join(s);
}

//inits...
var commentLine = '//';
var commentLineEnd = '';
var numRows = dataGrid.length;
var numColumns = headerNames.length;
var outputText = '{' + newLineStr +
indentStr + '"type": "FeatureCollection",' + newLineStr +
indentStr + '"features": [';

//begin render loop
for (var i=0; i < numRows; i++) {
var row = dataGrid[i];
var coordinates = [];

outputText += ((i > 0) ? ", " : "") +
'{' + newLineStr +
repeat(indentStr,2) + '"type": "Feature",' + newLineStr +
repeat(indentStr,2) + '"properties": {';

for (var j=0; j < numColumns; j++) {

if ((headerNames[j] == "lat")||(headerNames[j] == "latitude")) {

coordinates[1] = row[j] || null;

} else if ((headerNames[j] == "long")||(headerNames[j] == "longitude")) {

coordinates[0] = row[j] || null;

} else {

if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {

var rowOutput = row[j] || "null";

} else {

var rowOutput = '"' + ( row[j] || "" ) + '"';

};

outputText += ((j > 0) ? "," : "") + newLineStr +
repeat(indentStr,3) + ('"'+ headerNames[j] +'"' + ":" + rowOutput );

};

if (j >= (numColumns-1)) {

outputText += newLineStr + repeat(indentStr,2) +"}";

};

if (coordinates[0] && coordinates[1]) {

outputText += "," + newLineStr +
repeat(indentStr,2) + '"geometry": {' + newLineStr +
repeat(indentStr,3) + '"type": "Point",' + newLineStr +
repeat(indentStr,3) + '"coordinates": [' + coordinates[0] + ',' + coordinates[1] + ']' + newLineStr +
repeat(indentStr,2) + '}';

};

};

outputText += newLineStr + indentStr + "}";
};

outputText += "]" + newLineStr + "}";

return outputText;
},

//---------------------------------------
// JSON Array of Columns
Expand Down
1 change: 1 addition & 0 deletions js/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function DataConverter(nodeId) {
{"text":"Actionscript", "id":"as", "notes":""},
{"text":"ASP/VBScript", "id":"asp", "notes":""},
{"text":"HTML", "id":"html", "notes":""},
{"text":"GEOJSON (POIs)", "id":"geojson", "notes":"Fields others than lat long go to properties. {lat} or {latitude} and {long} or {longitude} are the geocoordinates of the POI."},
{"text":"JSON - Properties", "id":"json", "notes":""},
{"text":"JSON - Column Arrays", "id":"jsonArrayCols", "notes":""},
{"text":"JSON - Row Arrays", "id":"jsonArrayRows", "notes":""},
Expand Down