Questions tagged [r]
Statistical computing language and software environment.
1,270
questions with no upvoted or accepted answers
14
votes
0
answers
3k
views
How to prevent cross-world lines in ggplot world map?
I'm having issues displaying 'great circles' paths and polygons in ggmap, an extension of ggplot2. Please enter the following code to replicate my issues:
https://gist.github.com/Robinlovelace/...
9
votes
2
answers
1k
views
commuteDistance in gdistance package in R giving error
I am currently trying to run a function that "calculates the expected random-walk commute time between nodes in a graph. It is defined as the effective distance (resistance distance) between the ...
8
votes
0
answers
1k
views
Cellular Automata Markov for forecast LULC in R software
I would like to forecast land use changes by implementing the Cellular Automata (CA) Markov Chain models in R software.
I have the classified LULC maps from 3 times periods (1992,2003,2014), and also ...
7
votes
0
answers
1k
views
R sf package - link to GDAL
Is it possible to ask R {sf} package to use a GDAL installation I prefer?
So far I found how to check external software it uses:
library(sf)
sf_extSoftVersion()
# GEOS GDAL ...
7
votes
0
answers
1k
views
Correctly handling climate projection data with R
EDIT: An example setup can be found here: The main file is extract_cordex.R
I need to analyze climate data as part of my thesis, however I am not particularly trained in working with climate data and ...
6
votes
0
answers
323
views
Implementing PostGIS query using sf in R to make ST_Intersection faster
I'm trying to implement this query that speeds up st_intersections by using faster functions, namely ST_Contains and ST_Within, to do ST_Intersection only where absolutely necessary, from PostGIS to R
...
6
votes
0
answers
117
views
Using euclidian distances as spacing for regular points grid in QGIS?
As a means of checking spatial autocorrelation in the selection of training samples for image classification, I am trying out semivariance analysis. I have managed to generate variograms from image ...
6
votes
0
answers
820
views
How to interpolate within defined boundaries of a deformed mesh using R?
My goal is to create an interpolation map of some output model results that are mapped on a deformed mesh (from a numerical simulation). The model results are in an x-y plane (representing coordinates)...
6
votes
1
answer
828
views
Cokriging: zero distance cross-semivariance in undersampled cases [gstat error]
Trying to cokrige two variables that are not perfectly colocated (one has sparser measurements than the other), I faced an issue that I'll illustrate with the following MRE.
With the meuse dataset, ...
5
votes
0
answers
530
views
Optimising use of st_within for parallelisation
I'm trying to use st_within() to calculate points within polygons on a fairly complex shapefile. This operation tends to take 4-5 hours which is a bummer for debugging the code. I have access to a ...
5
votes
0
answers
1k
views
Rotate coordinates from climatic data in raster format (cordex-EU domain 11) to usual coordinate systems
I am trying to create a dataset that shows future climatic condition in Europe aggregates to NUT2 administration level in R. To do so, i work with cordex data (domain EU 11), that is coming ...
5
votes
0
answers
869
views
Split a tmap legend and display in two locations
I would like to split the legend of a tmap object, so that one of the two elements is in the top left, and one in the top right. I have been through the documentation of tm_legend, but could not find ...
5
votes
0
answers
2k
views
Selecting and deselecting markers in leaflet under R shiny?
I would like to write a script that selects a marker on the map whenever I click on it and then deselect it when I click/select another marker (that is, so that no more that one marker is selected on ...
5
votes
1
answer
560
views
Working out travel time from gdistance's conductance values in R?
Introduction
This question is indirectly related to a previous post of mine (Calculating accumulated walking pace from starting location outwards using R?), but asks guidance about a different aspect, ...
5
votes
0
answers
745
views
Determining areas on a Voronoi Diagram around a point
I currently have two data sets concerning the Netherlands, one containing longitudes and latitudes of population cores (Hubs) along with other information, such as average house price, and the other ...
5
votes
0
answers
2k
views
Clustering of events within a space-time window (R)
I am relatively new to clustering methods and am trying to determine the best method for clustering (or merely grouping) events that fall within a space-time window using preferably R. My goal is to ...
5
votes
0
answers
2k
views
How to avoid "Unable to compute a transformation between pixel/line"?
I am trying to re-project from Equi-rectangular to the NASA global EASE grid (Equal Area Scalable Earth) grid 1383 586 with a ~25 km cylindrical projection (ESPG=3410). The file is provided as HDF5.
...
4
votes
0
answers
462
views
Choosing the right coordinate system to measure area all over the world
I'm kind of new to GIS, I have a background in physics, but I'm pretty confused with all the projection available and how to use them.
I have a dataset of 133 coordinates around the world. I am using ...
4
votes
0
answers
247
views
Spatial regression: general nesting spatial model using splm package in R
I have a shapefile of panel data (multiple years of observations for each polygon). I am estimating fixed effects spatial regression models with this data. I used one year of this data to generate a ...
4
votes
2
answers
599
views
Extract pixel values in raster stack using shp
I am using the following code to extract mean pixel values over an area represented by a polygon:
mean<-lapply(S2_stack, FUN=function (S2_stack) {data.frame(mean=extract(S2_stack, polygons2, fun=...
4
votes
1
answer
1k
views
Split a polylines according to a specific point in R
I have 2 distinct spatial objects:
on one hand I have a SpatialLinesDataFrame
on the other hand I have a SpatialPointsDataFrame
Considering one line and one point that intersects that line, I ...
4
votes
0
answers
1k
views
Possible to drop NA geomType in readOGR?
I have a gdb file which is giving me trouble.
f = '/path/to/folder.gdb'
layers = ogrListLayers(f)
geom_list = lapply(layers, readOGR, dsn = f)
Gives an error on one of the layers:
Source: "f&...
4
votes
0
answers
1k
views
Sentinel 2 preprocessing with R
I need to transform Sentinel 2 L1C imagery to preprocessed Level 2A data.
Ideally this should happen in R, as the remaining processing stack is already done in R.
Are there ready preprocessing ...
4
votes
1
answer
287
views
Loading raster to R from PostgreSQL via pgGetRast takes a lot of time
I wrote R code in R Studio to load a raster (stored in PostgreSQL) to R. The database is stored here: C:\Program Files\PostgreSQL\
The following versions are installed on the computer:
R version 3.4....
4
votes
1
answer
13k
views
Error in compareRaster(c(x, rasters)) : different extent
I have a RasterStack that I want to add two rasters to. I am using this code
library(rgdal)
library(raster)
#original rasterstack
rasterfiles <- list.files("C:\\path_to_rasters", "*.tif$", ...
4
votes
0
answers
534
views
Keys for merging US state/county ANSI's with GADM Unique identifiers?
I've got county-level data from USDA NASS, and I want to merge it with gridded climate data. A preliminary step is the associate the counties with the coordinates of their centroids. If I merge by ...
4
votes
0
answers
709
views
Spatial weight matrix with boundary effects in R?
I need some help to finalize code for a spatial weight matrix that uses a nearest neighbor definition within regions, but does not allow neighbors from across a political border. For example, ...
4
votes
0
answers
270
views
How to set m parameter of clusterR function in R?
I want to manage a clustered computation on raster and thus use the "clusterR" function in R (package 'raster').
However, there's a tuning m parameter to set, but the only explanation about this ...
4
votes
1
answer
478
views
Plotting Bare Soil Line on landsat data in RStudio?
I am using RStudio with landsat package for computing and plotting the Bare Soil Line (BSL) on landsat tif image running on my HP Pavilion i7 laptop. The codes for running the BSL() function is as ...
4
votes
0
answers
2k
views
Fortifying re-projected shapefile for ggplot2 in R
I have a shapefile of US county boundaries which I got from the NHGIS. I can load the file using the rgdal package and see information about it:
library(rgdal)
shp_1860 <- readOGR("shp", "...
4
votes
2
answers
710
views
Calculate the travel time from locations to the closest N points
I want to calculate the travel time (based on walking time) from locations to the closest N points of another dataset. Then I want to create a hull around those N closest points per location
Is this ...
3
votes
0
answers
813
views
How to force single value terra::rast to plot as continuous
I have a couple of raster in R. Some have a range of values while others have a single value (all 0, for instance). I want to plot all rasters with the same color scale and legend so I can visually ...
3
votes
1
answer
556
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 ...
3
votes
0
answers
294
views
Issues downloading soil organic carbon data from SoilGrids
I am trying to use R to download soil organic carbon data for a specific region from SoilGrids, using their example code as a start. The code I wrote based on this worked fine to download the sand and ...
3
votes
0
answers
256
views
Error while using "wbt_conditional_evaluation" in R from WhiteboxTools package "whitebox"
When I try to perform the conditional tools "wbt_conditional_evaluation" in R, I get this message error :
Error running WhiteboxTools (conditional_evaluation)
whitebox.exe_path: "C:/R/...
3
votes
1
answer
501
views
R: rotated raster is cropped when terra:rectify() is applied
I have a geotiff that I read with
rastertif <- terra::rast(x = tif)
This produces the following warning:
[rast] the data in this file are rotated. Use 'rectify' to fix that
So I use rectify like ...
3
votes
0
answers
348
views
Rasterize polygon shapefile giving cells average value of overlapping geometries
I want to rasterize a polygon shapefile in r - loaded as an sf. Using stars, I can do st_rasterize to create a stars object snapped to a template raster, which is great because I the next step I want ...
3
votes
1
answer
632
views
How do I change my x and y axes from a range of 0-1 to -180-180 in R? I'm using netndf datasets
I have temperature anomaly arrays for the months of February 2008-2021 that I have turned into a raster brick. I am now plotting these in ggplot2. See below code:
febanomaly_raster <- brick(anomaly....
3
votes
2
answers
1k
views
Retrieving raster layer names from a raster stack R
I have a raster stack with many layers and I want to compare the layers that contain the maximum value using cell by cell comparison and finally retrieve the layer names from the raster stack on each ...
3
votes
0
answers
894
views
Parallelizing calculations on large SF object in Windows environment
I have a large SF object, containing 1 km x 1 km grid cells, where I need to aggregate the area of polygons within the grid cells, i.e. grouping by grid cell, but also grouping by a second variable, ...
3
votes
0
answers
604
views
Can I resample a raster in R using "max" as function?
With a raster and a reference raster, I'd like to do something like this:
# resample raster to ref_raster to match resolution/origin using max as aggregate
raster = resample(raster, ref_raster, 'max')
...
3
votes
0
answers
568
views
Extracting point data from WMS using R. Is it possible?
I am collecting traffic accident data on European countries and the Austrians pointed me to this WMS metadata page.
https://data.statistik.gv.at/web/meta.jsp?dataset=OGDEXT_UNFALLSRV_1
which has the ...
3
votes
1
answer
737
views
Rendering three-composition raster map with ternary colormap using R
Say there are three raster maps, representing percentages of sand, silt and clay respectively. The three values for each cell are hence summed up to 1. I want to use one raster map to characterize the ...
3
votes
0
answers
526
views
Merge single- and multi-band rasters with stars
I can easily use c() to merge two single band rasters or two multi-band rasters using the R package stars, however, when I try merging a single band raster with a multi band raster, I get the error ...
3
votes
0
answers
389
views
Finding the nearest distance between points in a grid cell
I'm trying to find the distance between the nearest points in a grid-cell, such that there is no equivalence relation between these points. Meaning if there are three points {a, b, c}, then a = b; not ...
3
votes
0
answers
1k
views
Downloading SoilGrids data from WCS in R
I am trying to download SoilGrids GeoTIFF data in R using WCS. I have followed the tutorial set up by ISRIC (https://git.wur.nl/isric/soilgrids/soilgrids.notebooks/-/blob/master/markdown/wcs_from_R.md)...
3
votes
0
answers
397
views
How to create a hexbin polygon over a world map with a geom_sf object in R?
I have global data with over 180,000 data points. For every pair of coordinates I have a value, and many times I have multiple values at the same coordinates (see example of the dataframe df). I want ...
3
votes
0
answers
732
views
Spatial interpolation of climate data using latitude, longitude and elevation in r
I have downloaded E-OBS gridded daily climate data on 0.1-degree grid. For each grid point, I have longitude, latitude, elevation and climate data, i.e. precipitation sum / mean temperature. Now, I ...
3
votes
0
answers
116
views
Proj4 string missing datum information for SAGA outputs loaded into R
I've produced a set of topographic derivatives using both SAGA and ArcGIS. They are all in the same CRS.
When I load them into R, however, the proj4 strings are different:
>arcRaster
class ...
3
votes
0
answers
82
views
Difference in raster pixels between Windows x86 and Windows x64
I have a huge problem and I can not find a reason for it. I have two PCa, one in my house and the other in my workplace. The first one is an old notebook with Windows x86 and the other is Windows x64. ...