rast | Globally optimal geometric matching
kandi X-RAY | rast Summary
kandi X-RAY | rast Summary
This is a distribution of some of the RAST family of algorithms for branch-and-bound feature matching. Please see the doc/ subdirectory for more information. Please see the LICENSE file for details on the license under which you can use this code.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of rast
rast Key Features
rast Examples and Code Snippets
Community Discussions
Trending Discussions on rast
QUESTION
I need to create some new rasters by assigning values using z <- rast(x, vals = y)
. I would like the new raster (z) to have NA values at the same location as the old raster (x), but with the newly assigned value(s) (y) in the non-NA cells.
What is the most efficient way to create a new raster with a matching NA pixels but with new values assigned to the non-NA pixels?
I don't see any argument to handle NA values listed in the documentation for rast()
, so do I need to do a two step process where the value is first assigned to all cells and then NAs are transfered from the old raster to new?
In the following example I would like s
to have the same outline as r
but have a uniform value of 10 in the non-NA cells.
ANSWER
Answered 2022-Apr-15 at 01:00Here are four ways to do that:
QUESTION
I have used many times the same process of rasterization, which works fairly well:
...ANSWER
Answered 2022-Apr-11 at 14:17If I understand your question well (a reproducible example would have been appreciated), you want that all pixels in the rasterized polygons sum up to the harvested values ("my_variable" in your code).
Here I create a toy example to show you my reasoning:
first load the libraries
create toy data with an example total and harvested area
calculate the fraction of each pixel covered by the polygon
divide each cover fraction by the total area of the polygon and multiply it by the harvested area
QUESTION
I am using the focal function in the terra package to fill holes in a DEM raster. However, after running focal(m, w=19, fun=mean, na.policy="only", na.rm=TRUE)
my DEM is moved ~11cm relative to it's original position (see images below). This problem does not occur when I simply read in the raster using rast()
and then write it using writeRaster()
, but it happens when I use focal()
regardless of whether I save the output using writeRaster()
or using the filename =
argument within focal()
.
I have also noticed that the larger the window size used, the greater the movement of the output raster. A window size of 9 produced ~5cm error. Raster pixels are ~1.2cm in size so focal()
appears to be causing a movement of ~1/2 the width of the window used. As far as I can tell the movement is straight up/north.
Any idea why this might be occuring and how it could be avoided?
This the correctly aligned raster:
And this is after running focal (w = 19):
...ANSWER
Answered 2022-Apr-09 at 04:44That is a bug that, I believe, has been fixed in the development version of terra
available at https://github.com/rspatial/terra (and that is also the best place to report bugs). Can you please try it?
QUESTION
I am trying to count the non-NA values in a spatRaster using the global()
function from the terra package. All the functions (mean, max, sd, etc.) seem to work except for "isNA"
and "notNA"
. For these two functions it returns this error: Error in fun(values(x[[i]]), ...) : could not find function "fun"
, which is the same error it returns for a misspelled/non-existent function.
ANSWER
Answered 2022-Apr-04 at 17:43When I run your code, it actually works:
QUESTION
I want to crop a raster using a bbox or a known extent, i.e., 10 pixels in row and col.
Below you can see a reproducible example:
...ANSWER
Answered 2022-Apr-03 at 16:57Using terra
data, by your approach, which I like:
QUESTION
I want to select a group of pixels from a raster.
The user should enter an n value for selecting the number of columns and rows (or window size).
A window would fetch the number of pixels defined.
Would return a raster with the values.
Below is a piece of reproducible example:
...ANSWER
Answered 2022-Mar-31 at 20:00You can use standard indexing
QUESTION
PREFACE
My error is a simple "Mathematical operation applied to non-numeric argument" error, but I think this arise from how I create a suite of user defined functions and use them within the terra::app()
function. I am going to describe the full workflow to elucidate what I am after, so please bare with me.
ISSUE
I am trying to apply a statistical-empirical topographic correction to Sentinel 2A data in R. To apply the topographic correction, I have appended rasters of solar azimuth, solar zenith, and slope and aspect to the multiband scene. I am first taking a random sample of each band within a scene to get its intensity value as well as the corresponding solar zenith, aspect, and slope values. From there, I calculate the cosine of the solar incident angle for each sampled cell using the zenith, azimuth, slope and aspect using a user-define function. Then, I run a linear regression between the cosine of solar incident angle and the respective intensity value for each band. I then apply a user-defined function that calls the solar incident function above using the terra::app()
function to finalize the topographic information from these linear regressions. This works on one core just fine with fake data, but is painfully slow with real Sentinel data, so I want it to work on multiple cores. When I try to run on multiple cores I get the error:
ANSWER
Answered 2022-Mar-24 at 20:38It dawned on me after a good night's sleep that the answer might have been much simpler than I realized. I just needed to run the cos_i()
function using terra::app()
, but everything else would work fine and quickly using standard raster algebra provided by the terra::
package. Therefore, I could eliminate the RAST_CORR()
function and make the extra steps basic raster algebra.
QUESTION
I want to perform a neighborhood analysis in R to smooth the layer I have but keeping all the NAs of the input raster intact.
However, when I do, for instance, the following, the calculation "propagates" over the NA values - what it is an undesiderable behavior, in my case.
...ANSWER
Answered 2022-Mar-23 at 13:12With terra
the focal
method has an argument na.policy
that can be set to one of "all", "only" or "omit".
QUESTION
I am very new to R and programming in general, please forgive my forthcoming ineptitude.
I am working with a large categorical raster. Essentially, every pixel shallower than 10 meters on the Great Barrier Reef is assigned a value: 11,12,13, or 15. (Original file here). My end goal is to create a histogram showing the frequency of the "rubble" category (which is the given by the value 12) by latitude. It would look very similar to the third panel of this figure, but where they show "coral habitat" I would be showing rubble.
I thought the best way to do this would be to try to convert the original raster into a data frame where each row represents what was a pixel and there are three columns: categorical value (11,12,13, or 15), latitude, and longitude. I could then use this data frame to create any number of basic plots.
Ideally I would like to omit NAs in the process of creating this data frame because the raster is 152,505 by 112,421, but over 99% of pixels are empty (due to the shape of the Great Barrier Reef).
I can easily read in the raster and plot it using the Raster or Terra packages:
...ANSWER
Answered 2022-Mar-22 at 13:49I think the easiest way is to aggregate the raster so that you get one column, with the value of interest. That is, one cell for each latitude (row). Here is an example:
QUESTION
With terra
I would like to place the legend horizontally below the map.
From help
it seems that this can be done by either passing a character to legend
(e.g. legend = "bottomleft"
) or by passing a list to plg
with arguments from the base-R legend function. However, for me none of these work. Please, see code sample below.
Thanks!
...ANSWER
Answered 2022-Mar-17 at 13:46You could use the package raster
and spplot
which gives you the option to plot the legend below the plot. You can use this code:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install rast
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page