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

cannot convert sptable dataframe to sf #48

Open
johnypark opened this issue Jul 17, 2019 · 2 comments
Open

cannot convert sptable dataframe to sf #48

johnypark opened this issue Jul 17, 2019 · 2 comments

Comments

@johnypark
Copy link

johnypark commented Jul 17, 2019

Hi @mdsumner,

Thanks for the amazing package. I am currently using it to conduct linear transform on coordinates. In the meantime, function sf does not seem to work.
Message I get:

Error in sfFromTable(x, attr_tab = attr_tab, crs = crs, ...) : 
  sf direct creation currently not available, please for now install sf and use 'library(sf); st::as_sf(sp(x, ...))'

I could convert sptable to sp and then to sf, but I just wanted to make sure that you are aware of this error.

Thanks,
John

@mdsumner
Copy link
Owner

Ah thanks yeah, sadly it's deliberate but also on the agenda to fix. Let me know about your workflows, it might help to get a better solution with the upcoming sfheaders package

@johnypark
Copy link
Author

johnypark commented Jul 17, 2019

You're welcome @mdsumner,

One of the task led me to use spbabel was to make grid on the boundary shapefile of the region of interest.

You could make grid with sf::st_make_grid, but it does not work for tilted rectangles, since it seems to divide bounding box instead of the actual extent of the polygon.

So I did a little workaround to extract coordinates using spbabel::sptable and then did matrix transformation to put back the rectangle in the tilted position after making grid with sf::st_make_grid. sf:st_coordinates could also extract coordinates, but putting back to sf object seems to be a daunting task after matrix transformation using sf:st_coordinates, since sf offers no method to store the structure of the spatial features (maybe it's just me since I'm still in a learning phase about spatial objectives).

Anyhow, my workflow was to make grids from sf object -> sptable to extract coordinates -> matrix transformation of coordinates -> put back to sp object using sp -> convert to sf object, and if using spbabel::sf is possible then it could save me one step in my workflow. Code specified on my github (https://github.com/johnypark/TutoR_ofTheDay/blob/master/R/ShapeFileMod_2.R) if you are interested to look at.

Cheers!

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

2 participants