Search…
All processors

getFieldsFromData

Analyze field types from data in string format, e.g. uploaded csv. Assign type, tableFieldIndex and format (timestamp only) to each field
Parameters
  • data Array<Object> array of row object
  • fieldOrder Array array of field names as string
Examples
1
import {getFieldsFromData} from 'kepler.gl/processors';
2
const data = [{
3
time: '2016-09-17 00:09:55',
4
value: '4',
5
surge: '1.2',
6
isTrip: 'true',
7
zeroOnes: '0'
8
}, {
9
time: '2016-09-17 00:30:08',
10
value: '3',
11
surge: null,
12
isTrip: 'false',
13
zeroOnes: '1'
14
}, {
15
time: null,
16
value: '2',
17
surge: '1.3',
18
isTrip: null,
19
zeroOnes: '1'
20
}];
21
22
const fieldOrder = ['time', 'value', 'surge', 'isTrip', 'zeroOnes'];
23
const fields = getFieldsFromData(data, fieldOrder);
24
// fields = [
25
// {name: 'time', format: 'YYYY-M-D H:m:s', tableFieldIndex: 1, type: 'timestamp'},
26
// {name: 'value', format: '', tableFieldIndex: 4, type: 'integer'},
27
// {name: 'surge', format: '', tableFieldIndex: 5, type: 'real'},
28
// {name: 'isTrip', format: '', tableFieldIndex: 6, type: 'boolean'},
29
// {name: 'zeroOnes', format: '', tableFieldIndex: 7, type: 'integer'}];
Copied!
Returns Array<Object> formatted fields

processCsvData

Process csv data, output a data object with {fields: [], rows: []}. The data object can be wrapped in a dataset and pass to addDataToMap
Parameters
Examples
1
import {processCsvData} from 'kepler.gl/processors';
2
3
const testData = `gps_data.utc_timestamp,gps_data.lat,gps_data.lng,gps_data.types,epoch,has_result,id,time,begintrip_ts_utc,begintrip_ts_local,date
4
2016-09-17 00:09:55,29.9900937,31.2590542,driver_analytics,1472688000000,False,1,2016-09-23T00:00:00.000Z,2016-10-01 09:41:39+00:00,2016-10-01 09:41:39+00:00,2016-09-23
5
2016-09-17 00:10:56,29.9927699,31.2461142,driver_analytics,1472688000000,False,2,2016-09-23T00:00:00.000Z,2016-10-01 09:46:37+00:00,2016-10-01 16:46:37+00:00,2016-09-23
6
2016-09-17 00:11:56,29.9907261,31.2312742,driver_analytics,1472688000000,False,3,2016-09-23T00:00:00.000Z,,,2016-09-23
7
2016-09-17 00:12:58,29.9870074,31.2175827,driver_analytics,1472688000000,False,4,2016-09-23T00:00:00.000Z,,,2016-09-23`
8
9
const dataset = {
10
info: {id: 'test_data', label: 'My Csv'},
11
data: processCsvData(testData)
12
};
13
14
dispatch(addDataToMap({
15
datasets: [dataset],
16
options: {centerMap: true, readOnly: true}
17
}));
Copied!
Returns Object data object {fields: [], rows: []}

processGeojson

Process GeoJSON FeatureCollection, output a data object with {fields: [], rows: []}. The data object can be wrapped in a dataset and pass to addDataToMap
Parameters
  • rawData Object raw geojson feature collection
Examples
1
import {addDataToMap} from 'kepler.gl/actions';
2
import {processGeojson} from 'kepler.gl/processors';
3
4
const geojson = {
5
"type" : "FeatureCollection",
6
"features" : [{
7
"type" : "Feature",
8
"properties" : {
9
"capacity" : "10",
10
"type" : "U-Rack"
11
},
12
"geometry" : {
13
"type" : "Point",
14
"coordinates" : [ -71.073283, 42.417500 ]
15
}
16
}]
17
};
18
19
dispatch(addDataToMap({
20
datasets: {
21
info: {
22
label: 'Sample Taxi Trips in New York City',
23
id: 'test_trip_data'
24
},
25
data: processGeojson(geojson)
26
}
27
}));
Copied!
Returns Object dataset containing fields and rows

processKeplerglJSON

Process saved kepler.gl json to be pass to addDataToMap. The json object should contain datasets and config.
Parameters
Examples
1
import {addDataToMap} from 'kepler.gl/actions';
2
import {processKeplerglJSON} from 'kepler.gl/processors';
3
4
dispatch(addDataToMap(processKeplerglJSON(keplerGlJson)));
Copied!
Returns Object datasets and config {datasets: {}, config: {}}

processRowObject

Process data where each row is an object, output can be passed to addDataToMap
Parameters
  • rawData Array<Object> an array of row object, each object should have the same number of keys
Examples
1
import {addDataToMap} from 'kepler.gl/actions';
2
import {processRowObject} from 'kepler.gl/processors';
3
4
const data = [
5
{lat: 31.27, lng: 127.56, value: 3},
6
{lat: 31.22, lng: 126.26, value: 1}
7
];
8
9
dispatch(addDataToMap({
10
datasets: {
11
info: {label: 'My Data', id: 'my_data'},
12
data: processRowObject(data)
13
}
14
}));
Copied!
Returns Object dataset containing fields and rows
Last modified 1yr ago