Closed Maschette closed 4 years ago
what's the error? I'd expect this work work since this is ok:
sf::st_as_sf(SOmap::SOmap_data$fronts_park)
probably the fronts should be sp though, rather than add logic - I was hoping to refactor this stuff at some point soon
[1] "Error in (function (classes, fdef, mtable) : \n unable to find an inherited method for function ‘xmin’ for signature ‘\"NULL\"’\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in (function (classes, fdef, mtable) { methods <- .findInheritedMethods(classes, fdef, mtable) if (length(methods) == 1L) return(methods[[1L]]) else if (length(methods) == 0L) { cnames <- paste0("\"", vapply(classes, as.character, ""), "\"", collapse = ", ") stop(gettextf("unable to find an inherited method for function %s for signature %s", sQuote(fdef@generic), sQuote(cnames)), domain = NA) } else stop("Internal error in finding inherited methods; didn't return a unique method", domain = NA)})(list("NULL"), new("standardGeneric", .Data = function (x) standardGeneric("xmin"), generic = structure("xmin", package = "raster"), package = "raster", group = list(), valueClass = character(0), signature = "x", default = NULL, skeleton = (function (x) stop("invalid call in method dispatch to 'xmin' (no default method)", domain = NA))(x)), <environment>): unable to find an inherited method for function ‘xmin’ for signature ‘"NULL"’>
for the specific case that I had to use it I used:
fronts<-sf::st_crop(SOproj(SOmap_data$ACC_FRONTS,source = projection(SOmap_data$ACC_FRONTS), target=map$projection), xmin = raster::xmin(map$target), xmax = raster::xmax(map$target), ymin = raster::ymin(map$target), ymax = raster::ymax(map$target))
which worked
Actually I think it is two different errors. The first is the one above where map is a SOgg automap and SOauto_crop can't get the extent out (looks at the wrong spot). The second is that even when you use a normal automap you get this error:
[1] "Error in h(simpleError(msg, call)) : \n error in evaluating the argument 'x' in selecting a method for function 'addAttrToGeom': list item(s) not of class sfg\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'addAttrToGeom': list item(s) not of class sfg>
Personally I think having an option so it can just take sf polygons would be nice, people seem to send them to me more and more.
Because SOauto_crop() uses this code internally:
It falls over for the park fronts which are already an sf object. Unless others have a better suggestion I think the solution is adding an if statement to check if the layer is an sf class and then use: