I am trying to use the nkde
function of spNetworks
to create a KDE of crashes in DC along its roadnetwork. In preparation for the function I am creating lixels for nkde
, but running lines_center(lixels)
always gives me an error.
lixels <- lixelize_lines(dc_lines,1000,mindist = 250)
samples <- lines_center(lixels)
Whenever I am trying to run lines_center(lixels)
I get the following error:
Error in maptools::SpatialLinesMidPoints(with_length) :
is.projected(sldf) is not TRUE
In addition: Warning message:
In RGEOSMiscFunc(spgeom, byid, "rgeos_length") :
Spatial object is not projected; GEOS expects planar coordinates
I tried looking up various techniques, such as turning the SpatialLinesDataFrame into a normal Dataframe, st_as_sf, and then projecting it, but nothing worked out thus far and I always get the same error.
I am loading the data like this:
dc <- readOGR("assessment/test/Roads_2013", "Roads_2013")
Since the uploaded file is a Large SpatialPolygonsDataFrame, I am transforming it into SpatialLines using this code:
dc_lines <- as(dc, "SpatialLinesDataFrame")
Any idea what I am doing wrong or how I can properly project the lines?
The shapefile used is here: https://opendata.dc.gov/datasets/roads