0

I've rerun some data and am now getting this cryptic error message when trying to transfer my sf object from long to wide table format.

Error in Ops.sfc(xi, xj) : operation > not supported

Does anyone know what this error means? (It was working before, but I used a slightly different method to create the polygon object and the object was smaller.)

UPDATE: This seems to be a problem with the geometry. The geometry still uses the geometry of the 25m grid, not of the aggregated 250m grid. So dropping the geometry and relinking to the new geometry should do the trick. (I will have to fix this really in the input file, but for the solution I'll stick with the same file.)


The data is Corine landcover data for the Helsinki region in polygon format and aggregated to a 250m grid and can be found here (it's 2.5Gb big) (original data from Syke can be found here):

# load packages
library(sf)
library(tidyverse)

# increase memory
memory.limit(size=56000)

# read data
# geometry of 250m grid is here
# hel.liiteri <- st_read("liiteri.grid.250m.HR.gpkg")
Clc2000.poly.250m <- st_read("Corine.testdata.gpkg", layer="Clc2000")

# change to wide table format
Clc2000.poly.250m.wide <- Clc2000.poly.250m %>%
                            mutate(Clc2000.25m = str_pad(Clc2000.25m, 2, pad = "0")) %>%
                            group_by(GRIDCODE) %>%
                            pivot_wider(names_from = Clc2000.25m, values_from = tot_area,
                                        names_prefix = "Clc_", names_sort = TRUE) %>%
                            na_if(0)

I'm running Microsoft R Open version 4.0.2 on Microsoft Windows 10 Pro

> version
               _                           
platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          4                           
minor          0.2                         
year           2020                        
month          06                          
day            22                          
svn rev        78730                       
language       R                           
version.string R version 4.0.2 (2020-06-22)
nickname       Taking Off Again 

Long table format:
Table in long format

Wide table format (example for first 10 rows): enter image description here

5
  • The error message happens if R tries to compare to sfc spatial objects, eg: st_sfc(st_point(c(1,1))) > st_sfc(st_point(c(1,1))) but to reproduce this in your context we need all your data (including sf_liiteri?). While I wait for a 2.5Gb download, can you make your example reproducible (ie source all data used) and also show the summary of the data so we can have a look before the download finishes?
    – Spacedman
    Aug 31, 2021 at 16:43
  • (I see sf_liiteri is only in the commented out code so maybe not needed)
    – Spacedman
    Aug 31, 2021 at 17:18
  • If you do it with names_sort=FALSE you get something. Its something with really stupidly long column names that you may need to replace in order to see it. It also works if you drop the geometry first (and then you can still use names_sort=TRUE). I worked on a subset of your geopackage with just the first 10 rows for clarity. What output are you expecting for the first ten rows, say?
    – Spacedman
    Aug 31, 2021 at 17:21
  • I changed to names_sort=FALSE and that leads to Error: Subscript 'i' is a matrix, it must be of type logical. Will try dropping the geometry next... Sep 1, 2021 at 6:26
  • @Spacedman, if you post the following I will accept is as the solution: Clc2000.poly.250m <- st_drop_geometry(Clc2000.poly.250m) (then code as above) Clc2000.poly.250m.wide <- hel.liiteri %>% right_join(Clc2000.poly.250m.wide, by="GRIDCODE", keep=FALSE) %>% dplyr::select(-c(1,3,4,5,6,7)) Sep 1, 2021 at 7:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.