getFieldsFromData
Analyze field types from data in string
format, e.g. uploaded csv. Assign type
, tableFieldIndex
and format
(timestamp only) to each field
Parameters
fieldOrder
Array array of field names as string
Examples
Copy import {getFieldsFromData} from '@kepler.gl/processors' ;
const data = [{
time : '2016-09-17 00:09:55' ,
value : '4' ,
surge : '1.2' ,
isTrip : 'true' ,
zeroOnes : '0'
} , {
time : '2016-09-17 00:30:08' ,
value : '3' ,
surge : null ,
isTrip : 'false' ,
zeroOnes : '1'
} , {
time : null ,
value : '2' ,
surge : '1.3' ,
isTrip : null ,
zeroOnes : '1'
}];
const fieldOrder = [ 'time' , 'value' , 'surge' , 'isTrip' , 'zeroOnes' ];
const fields = getFieldsFromData (data , fieldOrder);
// fields = [
// {name: 'time', format: 'YYYY-M-D H:m:s', tableFieldIndex: 1, type: 'timestamp'},
// {name: 'value', format: '', tableFieldIndex: 4, type: 'integer'},
// {name: 'surge', format: '', tableFieldIndex: 5, type: 'real'},
// {name: 'isTrip', format: '', tableFieldIndex: 6, type: 'boolean'},
// {name: 'zeroOnes', format: '', tableFieldIndex: 7, type: 'integer'}];
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
Copy import {processCsvData} from '@kepler.gl/processors' ;
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
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
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
2016 - 09 - 17 00 : 11 : 56 , 29.9907261 , 31.2312742 , driver_analytics , 1472688000000 , False , 3 , 2016 - 09 - 23T00 : 00 : 00 .000 Z ,,, 2016 - 09 - 23
2016 - 09 - 17 00 : 12 : 58 , 29.9870074 , 31.2175827 , driver_analytics , 1472688000000 , False , 4 , 2016 - 09 - 23T00 : 00 : 00 .000 Z ,,, 2016 - 09 - 23 `
const dataset = {
info: {id: 'test_data', label: 'My Csv'},
data: processCsvData(testData)
};
dispatch(addDataToMap({
datasets: [dataset],
options: {centerMap: true, readOnly: true}
}));
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
Copy import {addDataToMap} from '@kepler.gl/actions' ;
import {processGeojson} from '@kepler.gl/processors' ;
const geojson = {
"type" : "FeatureCollection" ,
"features" : [{
"type" : "Feature" ,
"properties" : {
"capacity" : "10" ,
"type" : "U-Rack"
} ,
"geometry" : {
"type" : "Point" ,
"coordinates" : [ - 71.073283 , 42.417500 ]
}
}]
};
dispatch ( addDataToMap ({
datasets : {
info : {
label : 'Sample Taxi Trips in New York City' ,
id : 'test_trip_data'
} ,
data : processGeojson (geojson)
}
}));
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
Copy import {addDataToMap} from '@kepler.gl/actions' ;
import {processKeplerglJSON} from '@kepler.gl/processors' ;
dispatch ( addDataToMap ( processKeplerglJSON (keplerGlJson)));
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
Copy import {addDataToMap} from '@kepler.gl/actions' ;
import {processRowObject} from '@kepler.gl/processors' ;
const data = [
{lat : 31.27 , lng : 127.56 , value : 3 } ,
{lat : 31.22 , lng : 126.26 , value : 1 }
];
dispatch ( addDataToMap ({
datasets : {
info : {label : 'My Data' , id : 'my_data' } ,
data : processRowObject (data)
}
}));
Returns Object dataset containing fields
and rows