Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terra::intersect crashes R if object contains POSIXct #1273

Closed
DaveDixon opened this issue Sep 10, 2023 · 3 comments
Closed

terra::intersect crashes R if object contains POSIXct #1273

DaveDixon opened this issue Sep 10, 2023 · 3 comments

Comments

@DaveDixon
Copy link

DaveDixon commented Sep 10, 2023

R version 4.3.1
terra version 1.7.46

If a SpatVector contains a POSIXct field, terra::intersect crashes R with a segmentation fault.

Code to reproduce:

library(terra)

road_mtx <- cbind(
  rep(1, 5),
  rep(1,5),
  c(612999.4, 612775.8, 612521.5, 612507.6, 612511.6),
  c(3598976, 3599332, 3599748, 3599785, 3599817),
  rep(0,5))

utm_crs <- crs("+proj=utm +zone=13 +north +ellps=GRS80 +datum=WGS84 +units=m +no_defs")
colnames(road_mtx) <- c("geom", "part", "x", "y", "hole")
sample_road <- vect(road_mtx, "polygons", crs = crs(utm_crs))

point_frame <- data.frame(
  date = as.POSIXct("2020-03-01"),
  fatalities = 1,
  people = 1,
  latitude = 3682990,
  longitude = 548047.3
)
sample_point <- vect(point_frame, geom = c("longitude", "latitude"), utm_crs)

xx <- intersect(sample_road, sample_point)
@DaveDixon
Copy link
Author

Also fails if the field is Date. Workaround is to convert the date to character, e.g. as.character(date_field)

@rhijmans
Copy link
Member

Thank you very much for reporting this. Fixed.

@DaveDixon
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants