Skip to content

Error when generating BAUs from SpatialPolygonsDataFrame #11

Description

@agila5

Dear package authors,

I created this issue since, for some reason, I'm not able to create a BAU object using auto_BAUs() when then input data is a SpatialPolygonsDataFrame. For example:

library(sp)
library(FRK)
#> 
#> Attaching package: 'FRK'
#> The following object is masked from 'package:stats':
#> 
#>     simulate
library(sf)
#> Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE

nc <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
nc <- st_transform(nc, 32119)
nc_sp <- as(nc, "Spatial")
class(nc_sp)
#> [1] "SpatialPolygonsDataFrame"
#> attr(,"package")
#> [1] "sp"

auto_BAUs(
  manifold = plane(), 
  cellsize = c(10000, 10000), 
  type = "grid", 
  data = nc_sp, 
  convex = -0.05, 
  nonconvex_hull = FALSE
) -> tmp
#> Error:
#> ! unable to find an inherited method for function 'coordnames<-' for signature 'x = "SpatialPoints", value = "NULL"'

while equivalent code with SpatialPointsDataFrame works perfectly.

nc_centroid <- nc |> st_centroid()
#> Warning: st_centroid assumes attributes are constant over geometries
nc_centroid_sp <- as(nc_centroid, "Spatial")
class(nc_centroid_sp)
#> [1] "SpatialPointsDataFrame"
#> attr(,"package")
#> [1] "sp"

auto_BAUs(
  manifold = plane(), 
  cellsize = c(10000, 10000), 
  type = "grid", 
  data = nc_centroid_sp, 
  convex = -0.05, 
  nonconvex_hull = FALSE
) -> tmp

Created on 2026-01-26 with reprex v2.1.1.9000

Just to be clear, this is not a real issue since I can easily fix my real-data problem just by taking the centroids of the polygons, but I was wondering whether I was misinterpreting the docs or there is a real issue in the code. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions