epix-project / sptools Goto Github PK
View Code? Open in Web Editor NEWA collection of functions to extend the sp and rgeos packages
License: Other
A collection of functions to extend the sp and rgeos packages
License: Other
The function make_grid()
returns a SpatialPointsDataFrame
object with the coordinates as variables. It doesn't make much sense and contains the coordinates informations twice. It would make more sense if make_grid()
returned a SpatialPoints
object instead.
That should probably be a method in order to deal with SpatialPoints
, SpatialPointsDataFrame
, SpatialPolygons
, SpatialPolygonsDataFrame
, etc...
Can you check the new function rescale_raster please?
Including trying the run the example?
(I know... I should have made a branch for that... Next time!)
The function gadm
download the last version of gadm file, is it possible to remove it after reading the file?
Would it be interesting to add a buffer
arguments in the split_on_poly
and crop_on_poly
functions, to be able to select all the value of the raster even the cells that overlap with the polygon?
As the package imhen
has been updated and the output stations
is now an sf
class object. The examples using this package are not working anymore and need to be updated.
For resample_from_grid
, split_on_poly
and add_from_raster
, what happens if the Raster*
and the Spatial*
objects do not superpose? Does it returns an error? (I guess so). Should we include a test on that in these functions?
Here is a demonstration of the bug. For that, we need the following packages:
# devtools::install_github("choisy/srtmVN")
# devtools::install_github("choisy/worldpopVN")
library(magrittr)
library(sp)
The data we need:
country <- sptools::gadm("vietnam", "sp", 0)
elevation <- srtmVN::getsrtm()
popdensity <- worldpopVN::getpop()
Let's make a grid:
grid <- country %>%
sptools::make_grid(100) %>%
sptools::add_from_raster(elevation, "elevation")
Let's make a second version of this grid, where we remove the variable longitude
:
grid2 <- grid
grid2@data[, "longitude"] <- NULL
So, the only difference between grid
and grid2
is that grid
contains the variable longitude
that grid2
does not have. We can check that the coordinates are the same:
identical(coordinates(grid), coordinates(grid2))
The bug is due to the fact that
sptools::resample_from_grid(popdensity, grid)
works just fine whereas
sptools::resample_from_grid(popdensity, grid2)
fails with the following message:
Error in .intersectExtent(x, y, validate = TRUE) :
Objects do not intersect
Can we use the add_from_raster()
function on a SpatialPoints
object instead of a SpatialPointsDataFrame
object? If no, should we update this function so that it can deal with SpatialPoints
objects as well as with SpatialPointsDataFrame
objects? (I think we should).
Let's consider the climatic stations in the province of Hanoi:
library(sp)
provinces <- sptools::gadm("vietnam", "sp", 1)
hanoi <- subset(provinces, VARNAME_1 == "Ha Noi")
stations <- as(imhen::stations, "Spatial")
From the plot, we can see that there are 3 stations in the province of Hanoi:
plot(hanoi)
plot(stations, add = TRUE)
Yet, the function points_in_polygons
fails to return 3 points:
length(sptools::points_in_polygon(stations, hanoi))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.