JeremyGelb / spNetwork

An R package to perform spatial analysis on networks.
GNU General Public License v2.0
34 stars 2 forks source link

Any example using some external data sets "shapefiles" from working directory #4

Closed Janjua1991 closed 2 years ago

Janjua1991 commented 2 years ago

Hi, I am facing some issues and the code is not working for me. Can you guide me by using an example in which you load data from the working directory? I am getting the following error during the making of samples points. I am using the projected coordinate system NAD1983 UTM Zone 14N for both network and event data files.

Warning message: In proj4string(sldf) : CRS object has comment, which is lost in output

JeremyGelb commented 2 years ago

Hello,

First of all, thank you for reporting your bug here.

""" Warning message: In proj4string(sldf) : CRS object has comment, which is lost in output """

This is a warning message, not an error. This means that the code was executed but a detail require your attention. Here, the warning is raised by the package sp (I guess, or raster maybe) and means that the coordinate reference system (CRS) of your shapefile contains a comment string that has been dropped when loading the data in R. I am having this warning too when I build the package and when I work with other datasets. You can safely ignore it.

Let me know if you can continue your analysis. In that case, I will close this issue.

Janjua1991 commented 2 years ago

Hi, I am providing below the error which I got:

adding a road network in R

Roads<- readOGR("ND_NETWORK_PROJECTED.shp") OGR data source with driver: ESRI Shapefile Source: "D:.................................\projected\ND_NETWORK_PROJECTED.shp", layer: "ND_NETWORK_PROJECTED" with 252437 features It has 57 fields Integer64 fields read as strings: OBJECTID A B Warning message: In OGRSpatialRef(dsn, layer, morphFromESRI = morphFromESRI, dumpSRS = dumpSRS, : Discarded datum D_North_American_1983 in Proj4 definition: +proj=utm +zone=14 +ellps=GRS80 +units=m +no_defs

adding a road network in R

Crashes <- readOGR("All_Crashes.shp") OGR data source with driver: ESRI Shapefile Source: "D:.................................\projected\All_Crashes.shp", layer: "All_Crashes" with 19162 features It has 33 fields Warning message: In OGRSpatialRef(dsn, layer, morphFromESRI = morphFromESRI, dumpSRS = dumpSRS, : Discarded datum D_North_American_1983 in Proj4 definition: +proj=utm +zone=14 +ellps=GRS80 +units=m +no_defs

plot(Roads) plot(Crashes, col=2, pch=19)

lixels <- lixelize_lines(Roads,200,mindist = 50)

generating sampling points along lixels

samples <- lines_center(lixels) Warning messages: 1: In proj4string(sldf) : CRS object has comment, which is lost in output 2: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) : Discarded datum Unknown based on GRS80 ellipsoid in Proj4 definition

then applying the NKDE

densities <- nkde(Roads,

  • events = Crashes,
  • w = rep(1,nrow(Crashes)),
  • samples = samples,
  • kernel_name = "quartic",
  • bw = 300, div= "bw",
  • method = "discontinuous",
  • digits = 2, tol = 0.1,
  • grid_shape = c(3,3),
  • max_depth = 8,
  • agg = 20, sparse = TRUE,
  • verbose = FALSE) Error: cannot allocate vector of size 3.5 Gb In addition: There were 23 warnings (use warnings() to see them)
JeremyGelb commented 2 years ago

Thank you for the mode detailed example.

The error is now a real error : "Error: cannot allocate vector of size 3.5 Gb".

This means that the function is trying to create a vector too large for you computer memory. How big is the dataset you are using?

I would try to increase the grid_shape like grid_shape = c(15,15) or c(20,20) if you are analyzing accidents for a whole city. This will not impact the results but only split the calculus in smaller chunks (reducing the risk of memory issue). Also, you could try to download the last version of the package (devtools::install_github("JeremyGelb/spNetwork")) which has improved algorithms.

JeremyGelb commented 2 years ago

It has been 12 days since the last message, I hope that the problem is solved now. I close the issue, but feel free to reopen it if needed.