Questions tagged [r]

Statistical computing language and software environment.

1,097 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
10 votes
0 answers
2k 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/...
8 votes
1 answer
858 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 ...
  • 1,302
7 votes
1 answer
3k views

Setting CRS of raster to EPSG 3035 using R

I am trying to set the CRS of a raster file with the following code: library(raster) r<-raster(xmn=0,xmx=10,ymn=0,ymx=10) crs(r)<-CRS("+init=epsg:3035") The warning message is: ...
7 votes
0 answers
918 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 ...
  • 89
7 votes
1 answer
2k views

Crop raster based on another raster R

library(raster) How can one clip one raster based on another raster? RasA: class : RasterLayer dimensions : 459, 533, 244647 (nrow, ncol, ncell) resolution : 10000, 10000 (x, y) extent ...
  • 325
6 votes
0 answers
187 views

Creating a seamless vector dataset from raster with gdal, R or Python

I'm trying to create a seamless vector dataset from an integer raster. "Seamless" as in: not gaps between features and no overlapping features. The tools gdal_polygonize, pkpolygonize, terra:...
  • 873
6 votes
2 answers
236 views

Generate a stars object from tabular spatial temporal data?

I have tabular data with columns longitude, latitude, time, and intensity, like so: library(lubridate) ## mock example data ex <- tibble(longitude = 1:10, latitude = 10:1, ...
  • 161
6 votes
0 answers
261 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 ...
  • 3,344
6 votes
0 answers
745 views

Circular focal means with raster and NAs

I am trying to understand circular focal means using rasters having NA values. I made a couple of scenarios to better understand how to combine weight matrices and functions to summarize values. I am ...
6 votes
0 answers
700 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 ...
  • 29.3k
6 votes
2 answers
211 views

Calculating accumulated walking pace from starting location outwards using R?

Goal In R, I would like to calculate an accumulated cost surface around a starting location, with the cost representing the time (say, hours) to walk from the location outwards in all directions (say,...
  • 1,484
6 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 ...
  • 165
6 votes
0 answers
103 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 ...
  • 61
6 votes
0 answers
745 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)...
  • 61
6 votes
0 answers
1k views

Can extracting raster values work in polygons' CRS without raster resampling?

I am trying to extract raster values using polygon layer with different CRS. Raster is in WGS84 (EPSG:4326) and the polygons in UTM (EPSG:23031). 1. If I want to work in the projection of the ...
  • 1,113
6 votes
1 answer
596 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
960 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
678 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 ...
  • 85
4 votes
0 answers
103 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 ...
  • 41
4 votes
2 answers
332 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=...
  • 1,078
4 votes
0 answers
510 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 ...
4 votes
1 answer
386 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, ...
  • 1,484
4 votes
1 answer
216 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....
  • 85
4 votes
0 answers
432 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
653 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
1k 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. ...
  • 249
4 votes
0 answers
259 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 ...
  • 116
4 votes
1 answer
445 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
1k 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
436 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 ...
  • 2,072
3 votes
0 answers
126 views

How to compute weighted mean centroid of lat+lon points taking into account spheroid

I have a bunch of points (lat+lon coordinates). Each one has a weight. I would like to get a weighted mean centroid of the points, taking into account the spheroid (as my points are scattered across ...
  • 115
3 votes
0 answers
36 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 ...
  • 2,291
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
0 answers
238 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, ...
  • 41
3 votes
1 answer
73 views

Convert long datframe in R with each band being in one column to stars object with band as dimension

So I have a dataframe that looks like this: x y band val <dbl> <dbl> <int> <dbl> 1 12.5 48.7 1 0 2 14.3 47.3 1 0 3 10.3 48.0 1 0 4 ...
3 votes
0 answers
197 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 ...
  • 163
3 votes
0 answers
691 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)...
  • 165
3 votes
1 answer
384 views

Exporting geodatabase using R-Bridge with ArcGIS Pro

I am trying to export a spatial points data frame as a Arc geodatabase using arc.write function in the R-bridge (arcgisbinding) in R. I'm working in R v3.6.1, ArcGIS Pro v2.4.0 Advanced License, and ...
  • 31
3 votes
0 answers
201 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
1 answer
130 views

How to use sf:gdal_utils with extent option (-te)?

I want to build a Gdal VRT dataset with several bands and cropped to a specific region. For that, I'm using sf::gdal_utils but somehow I can't get the option -te to work. It either complains about an ...
  • 2,291
3 votes
0 answers
430 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
213 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 ...
3 votes
0 answers
100 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 ...
  • 1,503
3 votes
0 answers
74 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. ...
3 votes
0 answers
113 views

Remediating path that crosses international dateline

I'm trying to plot the paths of multiple ships on a world map using R and a series of Lat/Lon points. All is well until the ship crosses the international dateline (-180/180) when the path jumps ...
  • 153
3 votes
1 answer
828 views

Is it possible to query a geopackage (.gpkg) for features within a given bounding box?

I have GIS data with a very large layer stored within a geopackage from where I want to select features that fall within a bounding box calculated in my R session. I begin by creating a query string: ...
  • 335
3 votes
0 answers
178 views

R raster / rasterize creating GeoTIFF with Null Value "grid lines"

I am attempting the seemingly simple task of converting a .csv with lat, lon and population values into a .tif (raster). Here's my R code: geoName <- read.csv("/pathToData/geoName.csv") ...
3 votes
0 answers
161 views

Extracting values from rasters with different size in R

I have 10,000 raster files with different sizes. I need to extract values based on a list of points. I have used the following using the raster pckg: library(raster) library(ncdf4) library(data....
  • 39
3 votes
1 answer
814 views

runGdal returns "gdalinfo failed - unable to open" [...] ".hdf" file

I'm trying to use the function runGdalin R on a Mac and it seems that gdalinfo is not able to open the file. In the terminal, when I entered gdalinfo /MODIS/MCD12Q1.006/2009.01.01/MCD12Q1.A2009001....

1
2 3 4 5
22