PredictiveEcology / reproducible

A set of tools for R that enhance reproducibility beyond package management
https://reproducible.predictiveecology.org/
41 stars 14 forks source link

prepInputs failing with shapefile when studyArea is passed #182

Closed tati-micheletti closed 1 year ago

tati-micheletti commented 3 years ago
studyArea <- prepInputs(url = "https://drive.google.com/open?id=1LUxoY2-pgkCmmNH5goagBp3IMpj6YrdU",
                   destinationPath = tempdir(),
                   filename2 = NULL)

roads <- Cache(prepInputs, targetFile = "NRN_NT_10_0_ROADSEG.shp",
                       archive = "NRN_RRN_NT_10_0_SHAPE.zip",
                       alsoExtract = "similar",
                       url = "https://geo.statcan.gc.ca/nrn_rrn/nt/NRN_RRN_NT_10_0_SHAPE.zip",
                       studyArea = studyArea,
                       destinationPath = tempdir(),
                       filename2 = "majorRoads_BCR6NWT")
> Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'x' in selecting a method for function 'addAttrToGeom': empty geometries are not supported by sp classes: conversion failed

I suspect it is not reprojecting the file before cropping, resulting in an empty geometry, but didn't have time to debug. Works without a problem if studyArea is omitted.

# Installed version of reproducible:
> remotes:::local_sha("reproducible")
> [1] "e8e1a726c3ae6ceae9233dc51195d5e51d1c7211"
tati-micheletti commented 3 years ago

Problem is happening in maskInputs()

> roadsCropped <- maskInputs(roads , studyArea = studyArea)
maskInputs with sf class objects is still experimental
    intersecting ...
Checking for errors in SimpleFeature
Found errors in SimpleFeature. Attempting to correct.
  ...(Object to retrieve (d211e11599de967e.qs))
       loaded memoised result from previous FUN call, 
  Some or all of the errors fixed.
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'x' in selecting a method for function 'addAttrToGeom': empty geometries are not supported by sp classes: conversion failed
tati-micheletti commented 3 years ago

Failing also on latest CRAN version

tati-micheletti commented 3 years ago
# Not working properly either
roadsCropped <- cropInputs(roads, studyArea) # Doesn't fail, but doesn't crop
# But the raster version works
roadsCropped_raster <- raster::crop(roads, studyArea) # works fine
eliotmcintire commented 3 years ago

Looks like it is an issue with the roads being lat/long ... I have started a PR with a fix... see if it passes all tests.

As a work around, run it in steps: preProcess, then sp::transform the roads obj, then postProcess

eliotmcintire commented 3 years ago

The PR is passing the automated tests, but am running the more strict local tests.

The second problem is incorrect, I believe. I don't think raster::crop will work on objects with 2 different crs... However, the cropInputs doesn't crop indeed.

tati-micheletti commented 3 years ago

Sorry, what I meant is that if you do the raster::crop after doing prepInputs without the studyArea (which works and sets the crs of the object to the crs of the study area) and then apply raster::crop, it works.

*Tatiane Micheletti, *Ph.D. Phone: +1 250 298 2510 Postdoctoral Fellow - UBC / Pacific Forestry Center, Canada Ph.D. in Forest Zoology - TU Dresden, Germany Master in Sustainable Tropical Forest Management TRÍADE - Brazilian Institute for Conservation Medicine

On Fri, Dec 4, 2020 at 7:42 AM Eliot McIntire notifications@github.com wrote:

The PR is passing the automated tests, but am running the more strict local tests.

The second problem is incorrect, I believe. I don't think raster::crop will work on objects with 2 different crs... However, the cropInputs doesn't crop indeed.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/PredictiveEcology/reproducible/issues/182#issuecomment-738854200, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH7S3GNJNJNZEEZBBNSOFADSTD7N5ANCNFSM4UM3IA6A .

eliotmcintire commented 1 year ago

No longer relevant