I am new to geospatial data and I am trying to convert a csv to GEOJSON using geojsonio and sf packages. I want my output to be in this format
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "vendor": "A",
"vol":20},
"geometry": {
"type": "LineString",
"coordinates": [
[-74.20986, 40.81773, 0, 1564184363],
[-74.20987, 40.81765, 0, 1564184396],
[-74.20998, 40.81746, 0, 1564184409]
]
}
}
]
}
As you note, here the co-ordinates have 4 dimensions : lat,long, elevation / altitude , Timestamp
My code is as follows
library(geojsonio)
library(sf)
library(tidyverse)
sf_data <- st_as_sf(Master_GPX, coords = c("lon", "lat","ele","timestamp"),dim="XYZM")
sf_data %>%
group_by(Msisdn) %>%
summarise(geometry = st_combine(geometry)) %>%
st_cast("LINESTRING") -> res_sfdata
geojson_write(res_sfdata,geometry = "LINESTRING", file = "C:/Project/checks/res_sfdata.geojson")
Master_GPX file as shown below
However,While writing the geojson file using geojson_write, I get a warning suggesting that it drops dimension M (which is timestamp) from the geojson file
> geojson_write(res_sfdata,geometry = "LINESTRING", file = "C:/Project/checks/res_sfdata.geojson",)
removing M dimension as not supported in GeoJSON format
Success! File is at C:/Project/checks/res_sfdata.geojson
I would need the dimension "M" which is timestamp in the geojson file for the visualization that I am building. How can I have all four values : latitude, longitude, elevation and timestamp written back to the geojson file?. Are there any alternative packages/functions which can achieve the same result? As am new to this space, any help would be much appreciated.
The {sf} library can read and write directly to geojson. Here's a simple working example
And a slightly more detailed example to show it handles the Z & M dimensions as well.