Skip to content

Instantly share code, notes, and snippets.

@hansthen
Created January 22, 2024 20:02
Show Gist options
  • Save hansthen/149a6e1ba20a79d2678705ce696cc5b2 to your computer and use it in GitHub Desktop.
Save hansthen/149a6e1ba20a79d2678705ce696cc5b2 to your computer and use it in GitHub Desktop.
jq for converting timedimension format to timeline format
cat track_bus699.geojson | jq '[([.geometry.coordinates, .properties.times] | transpose | .[] | {"coordinates": .[0], "start": .[1]}) as $features | del(.geometry.coordinates, .properties.times) | .geometry += {"coordinates": $features.coordinates} | .properties += {"start": $features.start, "end": ($features.start | (gsub("\\s"; "T") + "Z") as $date | $date | fromdate | . + 2)}]
@hansthen
Copy link
Author

cat track_bus699_iso.geojson | jq --arg duration 3 '.features[] |= [([.geometry.coordinates, [.properties.times[] as $times | $times | try (fromdate) catch $times]] | transpose | .[] | {"coordinates": .[0], "start": .[1]}) as $features | del(.geometry.coordinates, .properties.times) | .geometry += {"coordinates": $features.coordinates} | .properties += {"start": $features.start, "end": ($features.start | . + ($duration | fromjson) )}]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment