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

no slot of name "ptr" for this object of class "SpatRaster" in function viewshed #13

Open
vincentwen001 opened this issue Oct 8, 2023 · 0 comments

Comments

@vincentwen001
Copy link

Hello. The code in examples runs error on my computer, it reports 'no slot of name "ptr" for this object of class "SpatRaster"'

#For this example, we first need to download the DSM, DTM and Green space layer from the following url (where we already uploaded the data)

#create a temp diractory to get the zip file
temp <- tempfile(fileext = "zip")
download.file("https://a35b3ff7-2e06-4a4f-a669-8681322e59a7.usrfiles.com/archives/a35b3f_c9ec6cb349d043f4b3b055d6dc984ed3.zip", temp)

#extract the zip file
out <- unzip(temp, exdir = tempdir())

#load the DSM, DTM, and GreenSpace (GS)
DSM <- terra::rast(out[1])
DTM <- terra::rast(out[2])
GS <-  terra::rast(out[3])

#let us fix an obersver location 
obersver_mp <- sf::st_sf(sfheaders::sf_point(c(4.882752, 52.358029)), crs = st_crs(4326))

#make sure the oberver location has same projection as the DSM/DTM/GS file. They all need to be in same projection
obersver_mp <- sf::st_transform(obersver_mp, sf::st_crs(DSM))

singleview <- GreenExp::viewshed(observer = obersver_mp, dsm_rast = DSM, dtm_rast = DTM,
                          max_distance = 200, observer_height = 1.7, plot = TRUE)

Results:

trying URL 'https://a35b3ff7-2e06-4a4f-a669-8681322e59a7.usrfiles.com/archives/a35b3f_c9ec6cb349d043f4b3b055d6dc984ed3.zip'
Content type 'application/zip' length 7365204 bytes (7.0 MB)
downloaded 7.0 MB

Error in GreenExp::viewshed(observer = obersver_mp, dsm_rast = DSM, dtm_rast = DTM,  :
  no slot of name "ptr" for this object of class "SpatRaster"

For recent terra package, it shows:

r$> getSlots("SpatRaster")
        pnt
"C++Object"

I'm not sure if the slot in terra SpatRaster was renamed from ptr to pnt. Thank you very much for your help.

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

1 participant