Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

6.5 KB
Raw Blame

Table of Contents

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

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

processArrowTable

Process a loaders.gl ArrowTable ({shape: 'arrow-table', data}) and return a data object that can be passed to addDataToMap. Load arrow files with GeoArrowLoader and {arrow: {shape: 'arrow-table'}}.

Parameters

  • arrowTable Object ArrowTable to parse, see loaders.gl/schema

Examples

import {addDataToMap} from '@kepler.gl/actions';
import {processArrowTable} from '@kepler.gl/processors';
import {load} from '@loaders.gl/core';
import {GeoArrowLoader} from '@loaders.gl/arrow';

const arrowTable = await load(url, GeoArrowLoader, {arrow: {shape: 'arrow-table'}});

dispatch(addDataToMap({
  datasets: {
    info: {id: 'arrow_dataset', label: 'My Arrow'},
    data: processArrowTable(arrowTable)
  }
}));

Returns Object dataset containing fields and rows or null

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

  • rawData string raw csv string

Examples

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.000Z,,,2016-09-23
2016-09-17 00:12:58,29.9870074,31.2175827,driver_analytics,1472688000000,False,4,2016-09-23T00:00:00.000Z,,,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

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

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

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