Questions tagged [r]

Statistical computing language and software environment.

Filter by
Sorted by
Tagged with
1 vote
1 answer
207 views

Object name not found in R

I have created following map for disaster by district as shown below. The code I used is:- install.packages("cartography") install.packages("sf") install.packages("tidyverse&...
  • 165
0 votes
1 answer
31 views

Looping to do cloud mask for several raster files in R [closed]

I have over 200 land surface temp (LST) rasters and I want to mask each LST raster using the corresponding cloud Mask raster. The working directory has two folders one for LST and one for cloud Mask. ...
  • 9
0 votes
1 answer
153 views

Adding attribute to SpatialPolygonsDataFrame in R

I have a SpatialPolygonsDataFrame with 14 different polygons. Each polygon currently has an attribute column "id", which is a single string that identifies the original colony, year, and ...
0 votes
1 answer
51 views

Zero-width buffer trick makes the Caspian Sea disappear (using R)

I am new to plotting with coordinate systems. I am trying to generate a Pacific-centered map, and am using this wonderful code as a starting point. I have a bunch of data points from databases I'm ...
0 votes
1 answer
103 views

R: Cannot create a RasterLayer object from this file

I need to download the climate data from CHELSA in form of GeoTIFF file. I need many layers, for which I downloaded them successfully but failed to load them as raster. For simplicity here is how to ...
0 votes
1 answer
379 views

Invalid argument to unary operator in R

I want to calculate the rate of change in Maximum Temperature (of 2 yrs) for a spatial data. The rate of change of maximum temperature for the 2 years data (say 2021 & 2019) is calculated as:- [{(...
  • 165
0 votes
0 answers
31 views

Classify which cells were uphill and which were downhill when calculating Tobler's Hiking Function

I am using the ArcGIS Desktop (10.7.1) Path Distance tool and a table and DEM to calculate the cumulative time to reach locations. Is there a way to track and map which cells were downhill and which ...
  • 83
1 vote
1 answer
74 views

Plotted shapefile doesn't lie on base map

I am working on choropleth map showing particulate matter by some district of an area. The attribute table is as shown below (with geometry):- The code I used is:- library(mapview) library(dplyr) ...
  • 165
2 votes
1 answer
52 views

Dividing square into smaller squares by using their shapes rather than their bounding boxes in R

I want to divide a square into 25 smaller squares. The square layer has a UTM coordinate system, so when plotted, it doesn't have flat bottoms and tops. When I try st_make_grid() function to overlay a ...
  • 55
2 votes
1 answer
90 views

Changing color ramp in R

I am trying to plot water quality by 3 districts of a nation. I have plot the map according to Biological Oxygen Demand value from the table as shown below:- The code I used is as shown:- install....
  • 165
0 votes
0 answers
70 views

Error while using readOGR to import shapefiles

I am using a Mac System and unable to read shape file. states12 <- readOGR(dsn = ".", layer= "cb_2018_us_state_500k", verbose=TRUE) The Error I am getting RStudio is Quitting ...
0 votes
1 answer
87 views

How to export arguments for terra's app function when using multiple cores?

Suppose the following example: library(terra) r <- rast() r1 <- setValues(r, rnorm(ncell(r))) r2 <- setValues(r, rnorm(ncell(r))) r3 <- setValues(r, rnorm(ncell(r))) rs <- c(r1,r2,r3) ...
  • 12.3k
0 votes
0 answers
75 views

Export the map plotted in R to QGIS

I want the map plotted in R to be export in QGIS. The data source that I used for coding in R is as follows:- For Raster:-https://download.hermes.com.np/land-cover-map-of-nepal-2010/. For Vector :-...
  • 165
0 votes
1 answer
47 views

Problem with LidR an Macbook m1 2021 library(lidR) lidR 4.0.1 using 1 threads

I am trying to use the LidR package but I get the following error when installing the package. library(lidR) lidR 4.0.1 using 1 threads. Help on <gis.stackexchange.com>. Bug report on <github....
0 votes
2 answers
83 views

Change KMZ embedded symbols in R

EDIT: This question was originally posed for QGIS. However, since I found a way to solve it in R, the title and tags have been changed accordingly. I have got a Google Earth KMZ file with points. The ...
  • 1
0 votes
2 answers
220 views

Calculate area for raster in R

I want to calculate area for each different class of landuse for raster image as shown below:- The dimension of the raster image is as follows: class : RasterLayer dimensions : 16366, 29848, ...
  • 165
0 votes
1 answer
313 views

How to mask raster based on vector shape file

For this work Data are obtained from:- For Raster:-https://download.hermes.com.np/land-cover-map-of-nepal-2010/. For Vector :-https://cellapp.co/download-nepals-new-map-vector-image/. Rupandehi ...
  • 165
1 vote
1 answer
43 views

Connecting presence point to nearest raster (brick)

I am currently trying to run the maxent modelling in R on a dataset of moon jellyfish in the north east Atlantic waters. I have environmental variables datasets from Copernicus ocean monitoring ...
0 votes
1 answer
61 views

Rasterise a point pattern in R

I have a set of georeferenced points within an area for which I want to know the spatial distribution (sparse/clustered) according to a regular grid. I thought to describe the pattern using the Clark-...
  • 153
0 votes
1 answer
34 views

Construct neighbors list based on condition

I am trying to build a neighbors list based on regions with contiguous boundaries, conditional on if a neighboring region has a policy implemented. For example, say I have census tracts in New York ...
  • 3
0 votes
1 answer
54 views

Changing spatialpolygonsdataframe to default longitude/latitude (degrees) using R

I am trying (and failing) to convert the coordinates in a spatial object (Spatialpolygonsdataframe) form easting/northing to latitude/longitude. The zone is 35S. I know it can be achieved with ...
1 vote
1 answer
30 views

R RStoolbox not picking up a SpatialPolygonDataFrame as a Polygon

I am trying to perform a supervised classification via RStoolbox. I am using a SpatialPolygonDataFrame as the training data. Now, even though rgdal picks up the polygon, RStoolbox returns an error. ...
2 votes
2 answers
230 views

Calculate area weighted mean values of polygons for raster cells using R

Problem I want to rasterize polygon values and assign their weighted mean to raster cells. Weighting should be done based on the polygons' cell coverage. Problem visualized Calculation for grid cell ...
  • 184
0 votes
2 answers
97 views

Delete single pixels (noise) from raster

I have a raster layer (based on Landsat (30x30m)) of newly emergent lakes after spring snowmelt and subsequent runoff. These are stored in a raster layer. When I look at it, there is a lot of noise (...
  • 798
1 vote
2 answers
79 views

Calculate area of adjacent pixels

I have a raster layer of seasonal lakes created from snowmelt runoff. I would like to calculate the size of the lakes that are created. So I want to basically calculate the area of pixels clustered ...
  • 798
3 votes
0 answers
46 views

How to apply mean/min/max merge functions on a vector layer to create a stars raster?

Problem I would like to stars::st_rasterize a vector layers of an sf object using aggregation functions such as mean/median/max/min. raster::rasterize lets me use mean, min etc. and even define ...
  • 184
3 votes
1 answer
203 views

Parallelize raster area calculation per class in R

I am trying to get crop area for admin units of whole African continent using the data available here at 30-m spatial resolution globally (raster value 1 = crops). I've tried both terra and raster ...
0 votes
1 answer
84 views

Select and save as shapefile feature in R using sf

How can I select the shapefile feature there is, "D3" in "New.Code" columns using sf packages in R Here is the attribute table of my shapefile:
0 votes
0 answers
54 views

Merge spatial polygon with panel data

I have a grid shapefile with a total number of 10667 polygons (gid) dput(head(grid.sp)) new("SpatialPolygonsDataFrame", data = structure(list(gid = c("183253", "183254",...
  • 39
1 vote
1 answer
45 views

LiDAR derived Canopy Height Differencing extent variability

I am using classified LiDAR to create a canopy height model (CHM) for two LiDAR data sets over time. When I create the CHM I use a filter, -keep_class 5 so the output raster exactly outlines the trees ...
0 votes
2 answers
224 views

Clipping dataframe (spatial data) to area of interest using R

I have Global Fishing Watch data for the whole world in a dataframe with columns being Lon, Lat, fishing_hours, gear type. How do I crop the data to my area of interest? I have tried the following: # ...
0 votes
1 answer
67 views

Ordinary Kriging: "Warning message: In fit.variogram(data.var, vgm("Mat")) : No convergence after 200 iterations: try different initial values?"

I am trying to fit a variogram for kriging using the sp and gstat packages in r, but when I fit the variogram using a mattern fit, I get this warning message: Warning message: In fit.variogram(data....
1 vote
1 answer
166 views

R Terra: Write multiple time series variables to NetCDF

I have multiple variables in a timeseries which I want to save as NetCDF. But when I combine all variables with terra::sds() the time information disappears. I tried the following: library("terra&...
  • 199
0 votes
1 answer
41 views

Enlarging gBuffer width changes polygon shape

I am having some issues with spTransform and the gBuffer function. I basically have a polygon that I want to buffer with gBuffer (not with st_buffer for other reasons). For some reason the shapefiles ...
  • 9
0 votes
2 answers
78 views

Applying Moran's I across columns

So I find myself needing to apply global Moran's I across ~20 variables (as in ~20 instances of univariate autocorrelation for each variable, not attempted multivariate spatial autocorrelation). I'm ...
0 votes
0 answers
87 views

Incorrect number of dimensions in creating multiple plots using a for loop with ggplot2

I'm trying to map out all these different "solutions" from the prioritize model using ggplot. (To preface I'm very new to R so perhaps my code/methods are extremely rudimentary and why I'm ...
  • 1
2 votes
1 answer
139 views

QGIS reads blank cells as "nan" instead of "NULL"

I use QGIS to visualise my data but I use R when I have to do many treatments on my attribute tables. (package terra) But when I write vector data with R, the Na's appear in QGIS attribute table as &...
  • 133
1 vote
1 answer
130 views

Creating regular sampling grid, with specific distance between points using R

I wish to create a regular sampling grid within m spatial polygon. Similar question is answered as Creating regular soil sampling grids using QGIS but I wish to use R. In terra package, I can create ...
  • 3,276
0 votes
0 answers
79 views

How to remove banding artifact in R after reprojecting sf with st_transform

I have several global map layers I am plotting using ggplot() + geom_sf() + etc. All data is "+proj=longlat +datum=WGS84 +no_defs". My goal is to have Eurasia be a contiguous land mass. This ...
  • 1
0 votes
0 answers
68 views

Error with lidR::normalize_height

I am making a code for my master's thesis, in a part of the code I seek to obtain the normalization of the DSM of some municipalities of Galicia. The LiDAR files used come from the CNIG, they are the ...
  • 1
1 vote
1 answer
50 views

Which point lies on which linestring? [closed]

Using the {sf} package, I have two sf objects: one containing linestrings (edges), which form a linear network; one containing points, which are restricted to lie on the network. My goal ist to ...
  • 123
0 votes
0 answers
73 views

Area weighted average of wind speed gridded data using R

I have wind speed gridded data at a particular longitude and latitude. I want to calculate an area-weighted average of wind speed in R. I'm using the package "ClimProjDiags" for area-...
  • 1
0 votes
1 answer
33 views

How to export result of point_metrics() in lidR?

I have las files along coastal areas which include multiple flights. Usually I use both water and ground when normalizing but this data has 2 things to overcome. The first has ground at a lower level ...
  • 427
0 votes
1 answer
91 views

'union' between spatial polygons and spatial points in R

I have a gridded map shapefile with grid identifier cells (gid). dput(head(grid)) structure(list(gid = c("183253", "183254", "183255", "183256", "183258&...
  • 39
1 vote
1 answer
42 views

Aggregating and projecting soilgrids rasters giving NaNs using R

Working with the latest soilgrids data, I'm finding that when I aggregate and project the rasters as follows: soil_ocs = terra::rast('ocs_0-30cm_mean_5000.tif') aggregated <- terra::aggregate(...
1 vote
0 answers
64 views

Writing R code to convert rotated netCDF file to regualar grid and dataframe

I am looking for R code to extract/convert data from netCDF file to dataframe or CSV file. But, the netCDF is a rotated file in longitude and latitude (rlon and rlat slot). I searched many codes from ...
1 vote
1 answer
33 views

grid_canopy() fails when chunk has 1 veg return

grid_canopy() fails in catalog_apply() when chunk has only 1 vegetation return. (In the case of this file (see code), not dropping the overlap will allow the script to complete, but I don't think this ...
  • 427
0 votes
1 answer
106 views

R stars read_ncdf returns "vector memory exhausted (limit reached?)" when proxy = TRUE

My question involves an error when trying to read a large dataset, so I'm not sure of the best way to provide a reproducible example. I am trying to read a large netcdf file into R as a stars proxy ...
0 votes
2 answers
104 views

How to treat NAs using a custom function in the lapp function of {terra} in R

I am using the {terra} package of R-Stats. I have some quite complicated conditional maths to run on a set of rasters; a different formula depending on the value in the cell. I have tried to make a ...
0 votes
1 answer
309 views

Converting points to latitude and longitude values in R

I have a .tiff file with some coordinate data associated with temperatures that I need to convert into latitude and longitude, using R. I used the following code to read the original file: testlat<-...