The csv export from that site gives the extent of the bounding box in the order (xmin,ymin,xmax,ymax) so you can create a data frame with the vertices of that box, turn it into a spatial object, and then transform to your desired CRS:
bbox = c(5.9559,45.818,10.4921,47.8084)
vertices = as.data.frame(rbind(bbox[c(1,2)],
ifelse(ndvi<0.2,0.92,ifelse(ndvi >= 0.2 & ndvi <= 0.5,0.004 * pv + 0.986,ifelse(ndvi >0.5,0.99,NA)))
res <- overlay(r, fun = recalc)
As per updated comment the solution that worked was instead using calc:
The recalc function is basically ...
There's a couple of things going on here, I think. First, fasterize doesn't have ... enabled so you can't pass na.rm = TRUE through your summarising function, and all of those default to FALSE.
The other issue is that as the documentation warns, the output of st_combine() is often not valid under the simple features spec so may perform unexpectedly. If you ...
I was prompted to have a look closer at the GPS time stamps which the code uses to assign pulse IDs and then thin when use_pulse=TRUE. Out of my 5,000+ tiles, it turns out a few tiles had the GPS time stamps removed from the whole tile and thus, wasn't thinning because it only assigned one pulse for the whole tile (4+million points!).
I ended up writing a ...
I finally used rf<-writeRaster(px, filename="predict.tif", datatype="INT1U", format="GTiff", overwrite=TRUE) to export a integer type tiff file. And then I imported it in ArcGIS, shut down the background processing, and then I can create an attribute table for this raster layer using Arctool :)
You can just use raster::extract to extract values for a polygon (buffer), or an area around a point, and then pass the values to a table function to tabulate.
Create some data
r <- raster::raster(nrows=180, ncols=360, xmn=571823.6, xmx=616763.6, ymn=4423540,
ymx=4453690, resolution=270, crs =...
Simplest way is to extract coordinates for the set of cells over the threshold:
> r = raster(matrix(runif(50*50),50,50))
> coords = coordinates(r)[r>0.9,]
This should show the raster with some dots on the greenest points:
so I played around a little creating an sp objet
rs <- raster(file_path, band=2)
sp <- SpatialPoints(rs)
res <- extract(rs, sp,
then kept those with high intensity
res <- res[res$All_Cells > 0.9,]
coord <- xyFromCell(rs, cell=res$ID)
plot(coord, cex=0.05, col="...
Here's one approach that will give you the coordinates of each pixel that meets a criteria:
# Generate a raster to play with
mat = matrix(c(1,2,4,4),nrow=2,ncol=2)
# Use ggplot2::fortify() to turn it into a data.frame
ras.fort = ggplot2::fortify(ras)
# Select the raster values you're interested in (here, ...
If these values:
bbox: xmin: 313368.6 ymin: 4832795 xmax: 314211.3 ymax: 4833629
(which are the range of the data location values) are latitude-longitude:
proj4string: +proj=longlat +ellps=clrk66 +no_defs
then something is terribly wrong with the shape of the earth.
Lat-long coordinates should only ever be (-180,180),(-90,90) - your ...
To calculate the product (or any in-formula calculation) use the I() function:
mod <- lm(A ~ B + C + I(B*C))
B and C should be included by themselves (as noted above). If they are not significant and the interaction term is, still leave them in.
Firstly, you need them to be the same CRS and resolution in order to stack them. For this. Assuming your 5k raster also has a bigger extent for the purposes of this example, you can use raster::projectRaster():
bigger_raster <- projectRaster(raster5k, smaller_raster)
Now, if your extents are still off - you'll need to use raster::crop() to fix this.
The lidR package relies on the rlas package to read and write las file. The rlas package has a recent support of LAS 1.4 files (v1.3.0 release date: 2019-02-03). Moreover the point record formats >6 are a bit different than former point formats. Your code is correct and you actually found a bug in function write.las from rlas that occurs with point format 6 (...
In order to answer this question, I first had to understand the output of sf::st_coordinates which returns a matrix with the following rows: X,Y,L1, L2, L3.
L1: differentiates between convex hull and hole coordinates for each polygon
L2: differentiates between polygons in multipolygon
L3: differentiates between ...
There isn't an assignment for x in the code above so I can't generate your exact output, but you should be able to plot non-0 entries in your histogram by using hist(r[r!=0]).
Here's an assignment for x (just a placeholder) and some artificially-crafted 0's for the raster values that demonstrate the difference between hist(r) and hist(r[r!=0]):
x = seq(-1,...
In addition to @Spacedman's answer, you can set up a loop in R to compress tiffs using LZW with the writeRaster function in the raster package, which still uses GDAL. The options argument allows you to apply LZW compression.
In this example, the file is not overwritten but rather has an "_LZW" appended to the original name. To just overwrite the original ...
You can do this using the command line tool gdal_translate. This is available for Windows, Linux, and Mac OSs (you don't state your OS).
will show the info on the file, including the compression type and the locations:
Size is 204, 228
Coordinate System is:
It is also possible you don't have even read permissions over the folder you are trying to open a layer from. This problem is especially pesky if running stuff from a docker container. In order to give yourself permission just type:
chmod -R 777 /path/to/folder
Use the extract() function to find all values associated with a particular location, and visualize with hist(). Your raster's projection and extent will determine what points you want to use for PointOfInterest. A reproducible example:
r1 = raster(matrix(c(1:25),
r2 = raster(matrix(rep(5, 25),
The addLayer function works by stacking all its arguments - to add a layer to an existing raster or stack make it the first argument. This is shown in the help:
file <- system.file("external/test.grd", package="raster")
s <- stack(file, file, file)
r <- raster(file)
s <- addLayer(s, r/2, r*2)
Running with only one argument produces that ...
To find the countries of a data.frame with lat-long coordinates, convert them to an sf object with sf::st_as_sf(mydf, coords=c("lon","lat"), crs=4326).
Then intersect it with a map of polygons. This is vectorized, so no loops are needed.
Here's a complete working example:
# Dataframe with latlong coordinates:
d <- read.table(sep=",", header=TRUE, text=
Your terminology is bit unclear but I think it boils down to you trying to save spatial features vectors and expecting each element to have some attributes. You can't do that with vectors, you have to make spatial features data frames.
If you have an object that is an sfc class:
 "sfc_GEOMETRY" "sfc"
then saving it as a ...
As Spacedman sujested, you should share with us more than that, almost a piece of your tibble data. In any case, and without knowledge about your data sources, projection, etc, you could find those "cells" where your points are just by searching the closest cell center. This is just valid (and logic) if you tibble represents a regular raster grid. As I said, ...
First I'll set up some data like yours:
Extents and coordinate systems:
> eland = extent(-79.39998, -79.32998, 43.61302, 43.63498)
> cland = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"
> ewater=extent(-79.39958, -79.32958, 43.61292, 43.63458)
> cwater = "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
Make land ...
It is possible if done via LandViewer. Once you locate an area of your interest you will have an option to filter the images based on cloudiness level on the top right and download them with ease via download button on the right. An example of such imagery can be seen here or you can view It on the platform directly here.
Have you tried using alternative software to download those images? For example, MODIS data can be accessed via LandViewer. All you need to do is locate an area of your interest and select MODIS imagery in the filter section. Once done you will have the option to download the data on the right.
An example of such imagery can be seen HERE or view this ...
in your particular context, your point divides the original line in the longitude axis. Thus, you could create two other lines, each of which would have all points of the original one to the left and right of the longitude of the point of interest. A clumsy way of doing so is to filter the coordinates of the SpatialLinesDataFrame out of a data frame
You can read in irregular data if you know the max number of columns by giving column names and a fill argument:
> data = read.table("./lines.txt",col.names=c("x","y"),fill=TRUE, stringsAsFactors=FALSE)
1 ID1 NA
2 3285.48 -63.32
3 3285.14 -64.14
4 3284.67 -63.56
5 3285.00 -62.77
6 ID2 NA
7 3299.84 -76.82
R and raster crops to a bounding box so you will need to also mask to only retain the area of interest. Mask works by setting values inside or outside of a shape to a value usually NA in this context.
See raster::mask command
Your data must be projected to WGS84 before plotting:
adm_proj <- spTransform(adm, ‘+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs’)
addPolygons(data=adm_proj, weight = 2, fillColor = "yellow", popup=popup)
a good and fast way to start is to create your fishnet using the raster package to create your grid as a raster and then transform it into a polygon.
fishnet <- raster() # this creates a raster with the extent of the whole world.
res(fishnet) <- .5 # sets the resolution of your grid -- here .5 x .5 degrees
crs(fishnet) <- CRS("+...
Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:
> s_gis = data.frame(long=runif(5), lat=runif(5))
that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:
> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = ...
Thanks a lot, @Spacedman and @JepsonNomad for your comments. The comment by @Spacedman was very helpful. This line of code worked for me:
soil_raster2 <- rasterFromXYZ(moisture_data,res = 0.125,
crs = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0",
digits = 3)
Use SpatialPointsDataFrame with data.frame to coerce into the desired object.
x <- SpatialPoints( rbind(c(1.5, 2), c(2.5, 2), c(0.5, 0.5), c(1, 0.25),
c(1.5, 0), c(2, 0), c(2.5, 0), c(3, 0.25),
Here we create a data.frame within the call to SpatialPointsDataFrame ...
Given x a SpatialPoints object:
class : SpatialPoints
features : 50
extent : 0.0006317429, 0.9926516, 0.02675848, 0.9901886 (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
...you can convert to SpatialPointsDataFrame with as:
There is now a sf::st_crop function available but, you may need the development github version of sf. You can download the development version using the devtools/remotes package(s).
For specific irregular geometries, the raster::intersect function can clip data, and retain attributes, ...
Luckily, I was able to figure this out. It is necessary to set the GDAL_DATA directory in the same terminal session, open R, then install rgdal.
Set the GDAL_DATA environmental variable:
Location will vary by system; another good guess is /usr/local/share/gdal/. You should use find to locate your directory.
Then, in the same ...
The following code works including the load_output option. Just out of curiosity, are you running RQGIS3 from within RStudio? Because in my case running RQGIS3::open_app() crashes the RStudio R session. This was also confirmed by several other users (see the github issue tracker of RQGIS3). Since RQGIS3 works when run from the CLI, I am not really sure what ...
geom_polygon() is what you are looking after. The line
ggplot(Coordinates) + geom_polygon(aes(long, lat, group = grid))
should do the trick.
ps: next time, make your data available so that we can be more precise on addressing you issue :)
There's no mention of what happens with layer names in the documentation for calc so I suspect the answer is "just because". If you rely on layer names in your code then you should probably explicitly set them any time you think they might change.
Note that arithmetic can change layer names - even though both operands here have the same name, the output is ...
For me, run_qgis creates a bundle of .sdat files in the working directory:
 "aspect.sdat" "crossSectionalCurvature.sdat"
 "flowLineCurvature.sdat" "generalCurvature.sdat"
 "longitudinalCurvature.sdat" "maximalCurvature.sdat"
 "minimalCurvature.sdat" "...
Only half an answer: maxent() returns an object of the class MaxEnt. The fact that this is an S4-type object doesn't matter much here, but if you want top know more about that you can read on here. The actual "problem" is that the MaxEnt class does not provide a method for the generic residuals() function (resid() is just a shortcut for residuals()). I other ...
Convert the bnd object to an sp object using bnd2sp from the R2BayesX package.
Join data from the LeukSurv data frame using the region variable as the row number in the sp object.
You don't need to do anything with coordinate systems. The data are scaled to an approximate unit square and there's no need to georeference them for an analysis.
There's more ...