Questions tagged [r]

Statistical computing language and software environment.

Filter by
Sorted by
Tagged with
0 votes
1 answer
25 views

Array transformation: RasterStacks of time-series into Array of matrices

I have 9 RasterStacks with 65 layers containing time-series of satellite imagery. Each stack contains a time-serie of each Sentinel-2 band (B2, B3, B4, B5, B6, B7, B8, B11 and B12). The shape of the ...
  • 479
0 votes
1 answer
50 views

Choropleth of world countries showing microstates

I'm trying to create a choropleth of world countries that also shows microstates - but the issue I have is that they're too small to be seen at the scale. Wikimedia projects sometimes use this ...
  • 103
-1 votes
1 answer
26 views

Change the number of the legends manually or function in R

I created a map with the following code tm_shape(data) + tm_borders("grey") + tm_fill("Greenspace",style = "quantile", legend.reverse = TRUE, title = "% green&...
's user avatar
0 votes
0 answers
38 views

Terrain Ruggedness index to polygon

I need to calculate ruggedness for a circular region extending x meters away from a central point. The TRI function in Terrain uses Wilson (2007) equation to calculate TRI for an entire raster TRI <...
  • 9
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
1 vote
1 answer
54 views

Extracting variables from grid cells using R

I am trying to extract bioclimatic variables from individual grid cells. So i started loading my shapefile: # I used the Admin 0 - Countries (1:10) dataset from Natural Earth shp <- sf::st_read(&...
0 votes
0 answers
20 views

Average altitude when DEM is just partially covering some areas

I have a shapefile regarding the centroids of Europe and a raster related to the Euro DEM: the aim of my analysis was to compute non-overlapping buffers and extract the average altitude from them with ...
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
0 votes
1 answer
59 views

Adding an ID column to a SpatVector in R?

I've been rewriting an R script so it uses terra instead of raster and other packages, and I've managed to do it all except for one painfully simple task - adding an ID column to a SpatVector. My code ...
0 votes
1 answer
33 views

Remove ("erase") polygons by shared attribute

I need to do a pair-wise removal of a set of polygons within a larger set of polygons. pt<-data.frame("x"= c(0,0),"y"= c(0,5),pair= c("a","b")) pt<- ...
  • 9
0 votes
0 answers
27 views

R SQL importing Polygon errors System.FormatException: 24119

Any advice here from you all. I am converting a .kml file in R and uploading the data to SQL. I am pulling data from here: https://www2.census.gov/geo/tiger/GENZ2021/kml/cb_2021_08_tract_500k.zip ...
1 vote
1 answer
43 views

Why do dist2Line and st_nn give slightly different distances?

I have some points and am finding the distance to the nearest state border. My question is: why do dist2Line and st_nn give slightly different answers for the distances? The code below is based on ...
  • 115
1 vote
1 answer
57 views

How to associate point to nearest state boundary outside of the state the point is in

I have a point within a state and I want to find 1) the distance to the nearest state border and 2) the bordering state's name. I am able to do 1). For 2). I am able to get the state name ...
  • 115
0 votes
1 answer
33 views

How to export(writeRaster) single raster from multi-band stack/brick/spatraster one by one using R?

library(terra) a=rast(nrows=10,ncols=10,vals=1:100) b=rast(nrows=10,ncols=10,vals=1:100) c=rast(nrows=10,ncols=10,vals=1:100) test <- c(a,b,c) for (i in 1:3) { r=test[[i]] writeRaster(r,...
  • 103
0 votes
1 answer
33 views

R paste polygon coordinates for SQL

Everyone, I am new to this GIS data and SQL, but have pretty decent R knowledge. I am looking to extract the Polygon coordinates from a list so that I can paste into a SQL input query. I am pulling ...
1 vote
2 answers
126 views

R - Finding closest point to each point and filtering which points to consider

I'm a beginner in R. I am working in R with a dataset of bird nest locations and am interested in the distribution of said nests. Specifically, I'd like to find the closest neighbor to each nest as ...
  • 13
0 votes
1 answer
40 views

Can't put the city name in a better position in tmap

I would like to create a map with the cities in Spain. I gave that code which I got from a programming book. tm_shape(es) + tm_borders("white", lwd = 1) + tm_fill("migrationratio&...
's user avatar
0 votes
1 answer
134 views

R terra: [crop] SpatRaster has no values

I am attempting to use terra::crop() to crop 30 meter NLCD raster data to a bounding box. The final error that R returns is: Error: [crop] SpatRaster has no values despite the raster data containing ...
0 votes
1 answer
26 views

Trouble overlaying plots in R

I've produced a raster using IDW to make predictions across California, and now I'm trying to overlay the raster image with the border/shapefile of California. I've ensured the CRS projections are the ...
1 vote
0 answers
38 views

Recursively mosaic rasters by directory (year) in R

I have hundreds of rasters spanning 10 years, files are stored by year (e.g., 2020, 2019, 2018, etc.). I would like to mosaic all the raster files within a directory, move to the next directory and ...
  • 1,268
0 votes
3 answers
57 views

Calculating distance of point on line from the start of line

I have a line and points placed on this line. I am looking for a solution that allows to determine the distance of each point from the beginning of the line using R (preferably sf packet). This ...
  • 48
0 votes
0 answers
38 views

How do I get the proper data format for creating a tilegram -- from MULTIPOLYGONS to POLYGONS

I want to create a cartogram(specifically a tilegram like this) using data from GADM and population figures as the subject variable. Step 1: Get a json data file from GADM germany_1 <- read_sf(&...
  • 13
1 vote
1 answer
47 views

Retain spatial points outside of multiple polygons

We can use st_intesection to retain points that intersect with one or more polygons. tmp1 = st_intersection(st_as_sf(track_sp), st_as_sf(cols.buf_sp)) pts1 = as(tmp1, "Spatial") plot(pts1) ...
0 votes
1 answer
46 views

Distance between nearest neighbors R GIS

I am using nngeo to identify for each town the nearest city. Library nngeo is available here. I want to also report the distance between each town and its nearest city. I wanted to use gDistance but ...
1 vote
1 answer
37 views

Move points to different location

I have a group of points for London's train stations I've found through OSMdata: library(osmdata) library(tidyverse) osm_points <- opq ('greater london uk') %>% add_osm_feature("...
1 vote
1 answer
58 views

Append more variables to a SpatialPolygonsDataFrame using R

I would like to generate a SpatialPolygonsDataFrame that I can use to plot a cartogram whose polygons are proportional to a variable. A clear example is how FiveThirtyEight created a hex cartogram ...
  • 13
1 vote
1 answer
56 views

Create a grid for more than one country in R

Some time ago I posted my own answer to create a grid inside a country to be used in kriging interpolation: 0........0.kriging error messages, grid file problem ? (automap, gstat) This grid was for ...
0 votes
0 answers
18 views

How to join the values shown in the ggplot legend as an added column to the spatial data frame/shapefile?

I have a dataset filled with points. The image assigns the points a value based on clusters. Is there a way to assign those values shown in the image onto the dataset itself as a new column? This ...
  • 193
1 vote
4 answers
104 views

Normalize raster in R

I'm a noob in R. I want to normalize all imported rasters (0-1) through R, I use the scale function but the range of the results is not between 0-1. I would like to know if there is any way to ...
0 votes
1 answer
47 views

Treat NA as 0 in custom function for lapp in {terra} R library

I am trying to use the lapp function from the terra rstats library to do some raster-math. But when cells have NA in them, it is giving me the 'wrong' result. Here is my current function and result. a ...
1 vote
2 answers
44 views

Keep a factor field (or a RAT in general) when buffering a raster in R

I am trying to select pixels from a MODIS raster (with a 250 meters resolution and covering all Europe) based on their location. For that I am using a shapefile that contains ca. 200 points (also ...
0 votes
3 answers
66 views

Define extent of asc file

I downloaded the soilAtlas2M zip file, uploaded the .shp to arcgis, created a raster and clipped to my area of interest and made the map to show each soil type(map unit) to be a different colour, ...
  • 11
1 vote
3 answers
132 views

How to subset a raster stack by year with a loop in R?

So I have a folder with loads of .tif files showing NDVI. What I want to do is read them into a rasterStack, then subset that stack by year. I've been able to do this manually, but I'd really like to ...
0 votes
1 answer
41 views

How to create a non-overlapping buffer with a 50km radius having the RasterLayer file and centroids [closed]

I have a RasterLayer file and the relative shapefile showing the centroids of every cell. My goal is to compute a buffer with a 50 km radius starting from the centroids and then calculate the average ...
0 votes
1 answer
60 views

NAs when calculating the mean of raster values per polygon using R (stars & sf)

I am trying to get the mean NDVI value for tree clusters (I've calculated them using DBSCAN) using stars and sf but, I'm getting a lot of NA values, which they don't appear if I use the Zonal ...
  • 115
0 votes
0 answers
51 views

r-Mapview not loading background map unless I am online

Looked around but am quite lost. I am new to mapping a set of coordinates that a dataset will provide me. I am using R because it is the only approved program that I can use in my workplace. While I ...
0 votes
1 answer
35 views

Identify overlapping polygons within a single MULTIPOLYGON

I have a multipolygon shapefile that contains thousands of records with a spatial and temporal component. I'd like to be able to identify records that overlap (the amount of overlap doesn't really ...
  • 1,268
1 vote
0 answers
31 views

Understanding Mean +/- 1.5 SD in QGIS Symbology [closed]

I'm trying to automate a process that is now being made in QGIS, but I'd like to "transfer" the same operations to an R (or other language) code. What I have is NDVI images for a given ...
  • 11
0 votes
0 answers
42 views

Getting OSM Data (e.g. maxSpeed) for route that is returned from OSM Routing

Is there any way to use the Openstreetmap Routing Service and use the returned route to get access to all the tags that the OSM data has for this route? Specifically, I am thinking about querying the ...
  • 717
1 vote
1 answer
39 views

focalMat weights adjustment

I'm trying to calculate a spatially weighted focal function using terra::focal() and focalMat(). library(terra) r <- rast(ncols=10, nrows=10, ext(0, 10, 0, 10)) values(r) <- 1:ncell(r) w <- ...
  • 3,507
2 votes
1 answer
159 views

Mask a (raster) stars object in R with a vector (sf) object

In this question an stars object is masked with a raster object. But it is not clear to me how the masking can be done with a vector object using the stars pkg. Consider the following example in terra....
0 votes
1 answer
39 views

Define raster resolution in UTM or Lambert Azimuth Equal Area projection

I want to create a raster grid in Lambert Azimuth Equal Area projection. I need to work within the raster and sp packages, and I need to work in LAEA projection. However, when creating my raster, my ...
0 votes
2 answers
52 views

SpatialPolygonDataFrame to raster while keeping categorical values

I have a SpatialPolygonDataFrame which I need to convert to raster in R while keeping the categorical values of the polygon. I have tried various approaches but I have always either lost the values or ...
  • 3
1 vote
1 answer
116 views

Finding which region is nearest to which stations in R

I have a point dataset of 16 places in Switzerland that looks like these and is called stations stations <- read_csv("station.csv) view(stations) Cityid x y 1 611285.549 267664.109 2 600454....
's user avatar
5 votes
2 answers
294 views

Can't reverse the legend of tm_bubbles

I created a dot map with that code map = st_as_sf(map) tm_shape(map) + tm_fill("ratio",style = "cont") I also tried function rev() but nothing work
's user avatar
1 vote
1 answer
99 views

Create dot map in R

I would like to create a dot map in R. I have a shapefile called shp: And a csv file called sch and a water shapefile called water_shp I gave that code map <- inner_join(sch,shp,by="Region&...
's user avatar
0 votes
0 answers
34 views

Why is terra::resample() failing on this remote environment but working on my laptop?

When I run terra::resample() on land cover data taken from NLCD using this code library(terra) lc <- rast("path/to/lc_data") test_match_crs <- rast(crs = crs(lc), res = 80, ext = .1*...
0 votes
1 answer
66 views

Integrating raster images in a scatter plot via R

I'm trying to plot a graph of a linear profile with integrated pictures of drilling cores at certain points and hights in the profile. I have a directory with 22 .png images of the drilling cores, ...
1 vote
0 answers
21 views

Error while downloading MODIS data using runGDAL

I am new to GIS and spatial analysis. I am trying to download MODIS vegetation index data using runGDAL from the ‘MODIS’ version 1.1.5 package (https://rdocumentation.org/packages/MODIS/versions/1.2.3)...
0 votes
1 answer
154 views

Reclassify rasters in R using terra package

I have several rasters with values from 0 to 7, and I want to reclassify pixels using 3 different areas and different conditions. I want to reclass rc1 pixel value of (1 or 3 or 5 or 7) to 1 rc2 pixel ...
  • 15