Closed bcamper closed 6 years ago
@matteblair this is almost assuredly a JS-only feature like scripts
and transform
for the medium-future, but you may have thoughts on it nonetheless.
Also cc @meetar @burritojustice @thisisaaronland
This would be a fair bit of work to implement in Tangram ES, though not impossible. We could also pursue a data source model that allows users to implement on-the-fly transformations like this in the native language for their platform. Let's see how it shakes out in JS first!
Yeah, it's also part of the same family of functionality as the JS-only
transform
and scripts
features. So there are already ES considerations
generally for how/if we want to support this kind of processing.
On Sun, Mar 4, 2018 at 6:35 PM, Matt Blair notifications@github.com wrote:
This would be a fair bit of work to implement in Tangram ES, though not impossible. We could also pursue a data source model that allows users to implement on-the-fly transformations like this in the native language for their platform. Let's see how it shakes out in JS first!
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/tangrams/tangram/pull/635#issuecomment-370275118, or mute the thread https://github.com/notifications/unsubscribe-auth/AABBXd5FhE0k4lZm8NW6rTgg6vLFHdHnks5tbHpcgaJpZM4SNETN .
To enable support for formats that may contain geographic data, but not be formatted in the commonly supported formats (GeoJSON, MVT, etc.), this PR adds a data source
preprocess
option. This parameter can define a JS function to mutate the raw network response fetched by a data source, before it is processed further. This is similar to the existingtransform
function, with the difference thattransform
is called after initial response parsing (e.g. decoding TopoJSON and MVT to GeoJSON-style data).The
preprocess
function should return data in the format expected by the data source type, e.g. iftype: GeoJSON
, thenpreprocess
should return a GeoJSON object.For example, given a Who's On First CSV export (which contains geographic data in the form of census interior points) formatted like this:
We can use the
preprocess
function to remap those columns into a GeoJSON collection of points:Additional notes:
preprocess
has access to the same externally loadedscripts
as thetransform
function.preprocess
can return an immediate response, or aPromise
which resolves with a response, allowing for the potential use of async operations (while the initial tests are with CSV files, theoretically the functionality could be applied to shapefiles and other format parsing as well).preprocess
andtransform
functions in a single data source (if both are defined, both will execute), in practice there are probably few cases where it would be useful.