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

srs.polygon and sss.polygon not accepting SpatialPolygons object #13

Open
tmcd82070 opened this issue Jun 6, 2018 · 1 comment
Open
Assignees
Labels

Comments

@tmcd82070
Copy link
Owner

srs.polygon and sss.polygon are not accepting a SpatialPolygons object, and aborts with an error. They both accept SpatialPolygonsDataFrame objects.

@tmcd82070 tmcd82070 added the bug label Jun 6, 2018
@tmcd82070 tmcd82070 self-assigned this Jun 6, 2018
@jcarlis3
Copy link

jcarlis3 commented Jun 6, 2018

This might be a bandaid, but you could insert some code to check for SpatialPolygons objects and convert them to SpatialPolygonsDataFrame objects on the fly. This chunk simply adds an attribute table (@data slot) with an ID column numbered 1:length(x).

# Function to convert SpatialPolygons to SpatialPolygonsDataFrame
makeSpatialPolygonsDataFrame <- function(x) {
  x <- SpatialPolygonsDataFrame(x, data.frame(ID=1:length(x)), match.ID=FALSE)
  return(x)
}

# Check for SpatialPolygons and convert if needed
if(class(x) == "SpatialPolygons") {
  makeSpatialPolygonsDataFrame(x)
  return(x)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants