Last active
May 15, 2017 11:13
-
-
Save mdsumner/19b36c829ec1cbedabff1bf619b4ec18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## the projected extent | |
prj <- "+proj=sinu +a=6371007.181 +b=6371007.181" | |
ex <- extent(rgdal::project(cbind(c(-180, -180, 180, 180), c(90, 0, 0, -90)), prj)) | |
#the MODIS tiles | |
mtiles <- raster(ex, ncols = 35, nrows = 17, crs = prj) | |
## for real use you wouldn't actually populate the grid here | |
## raster's cell logic can be used without ever filling the data | |
mtiles[] <- seq(ncell(mtiles)) | |
#plot(setValues(mtiles, seq(ncell(mtiles)))) | |
library(sf) | |
pmtiles <- st_as_sf(as(mtiles, "SpatialPolygonsDataFrame")) | |
pmtiles$row <- rowFromCell(mtiles, seq(ncell(mtiles))) | |
pmtiles$col <- colFromCell(mtiles, seq(ncell(mtiles))) | |
plot(pmtiles[c("row", "col")], asp = "") | |
plot(st_geometry(pmtiles), asp = "") | |
data("wrld_simpl", package = "maptools") | |
plot(spTransform(wrld_simpl, prj), add = TRUE) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment