We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [r]

Statistical computing language and software environment.

Filter by
Sorted by
Tagged with
9
votes
4answers
5k views

animated map in R

everybody, sorry for disturb, but I am being quite new with r faced a crucial difficuty: I want to create an animated map of Russin with changes in unemployment with differnt years, like. On the image ...
9
votes
2answers
22k views

How to overlay map layers (shp and csv) in R?

This is a crosspost from stackoverflow. I know very little about GIS software and am doing all my mapping in R. Apologies in advance if this is too basic question. Let's say I have two shapefiles from ...
9
votes
1answer
3k views

Processing vector to raster faster with R

I am converting vector to raster in R. However the process was too long. Is there possibility to put the script into multithread or GPU processing in order to do it more faster? My script to ...
9
votes
1answer
10k views

Replace NA's with 0 for raster data using R?

I am new in R. How can I replace NA's with 0 for my raster data which have spatial information?
9
votes
3answers
768 views

Making county-level shapefile from set of points at 30 x30 km spacing using ArcGIS for Desktop?

I have a data set in csv form, like: latitude, longitude, value -45, 45, 10 .... I would like to calculate county level means from these data, using either ArcGIS or R+grass. I have the ArcGIS USA ...
9
votes
1answer
14k views

Using R to extract data from WorldClim? [closed]

I have a data set with 1000 different latitudes-longitudes. I wish to extract average annual temperature and annual precipitation for each of these coordinates. These data can easily be obtained from ...
9
votes
2answers
14k views

Create a raster with georeferenced information in R

Referring to my previous question, how do I "geocode"/convert - using R - a generated raster image to a format that can be shown as a layer on a map? In short, I'm aiming to recreate the results of ...
9
votes
1answer
2k views

R gstat krige() - Covariance matrix singular at location [5.88,47.4,0]: skipping

When I want to perform the kriging it only works sometimes, depending on what values I use in my datatable. As a result of the krige function I get for var1.pred: NA NA NA ... and var1.var: NA NA NA .....
9
votes
1answer
4k views

R fortify causing polygons to tear

I'm am having some trouble plotting my spatial data using ggplot2. The map looks fine when plotted using spplot, so I'm assuming that the tearing occurs at the fortify stage. The code is as follows: ...
9
votes
1answer
10k views

Convert coordinates from readShapePoly in R to long-lat coordinates

I'm trying to find some centroids of a shapefile for Danish municipalities and afterwards find the driving time between them. I use R's readShapePoly function from maptools combined with the ...
9
votes
2answers
3k views

How to implement bivariate Ripley's K function?

The attached image shows a forest gap with red pine represented as circles and white pine represented as crosses. I am interested in determining if there is a positive or negative association between ...
9
votes
2answers
9k views

Convert several SpatialPointsDataFrames to raster

There are 100 SpatialPointsDataFrames in my Workspace. I loaded them on this way: filenames <- list.files(path="", pattern="XYhectareTravelTimes_ez+.*shp") for(i in ...
9
votes
2answers
5k views

Removing intersect of one polygon from another using R?

I am trying to remove the intersect from Poly2 onto Poly1. Below are the coords of the 2 polygons. > coords1 [,1] [,2] [1,] 992.0161 7462.531 [2,] 950.1962 7413.532 [3,] 902.3632 ...
9
votes
2answers
1k views

How to create a solar intensity map for a garden plot?

I'm interested in creating a raster surface that depicts the average solar intensity per unit area for a small garden plot. I imagine the inputs into the model would be the following: Plot area--for ...
9
votes
2answers
11k views

ggmap: plot polygon from shapefile

Using ggmap, I want to include municipality borders (polygon) from a shapefile on a map containing some location points. This script does everything except plotting the polygon: library(rgdal) ...
9
votes
3answers
839 views

Creating large amount of random points in binary raster?

I want to create a point vector dataset of 10000 points (or larger) within a binary raster, where the points should be constrained to areas where the raster value is 1. I tried the following steps. ...
9
votes
1answer
9k views

How do I create a SpatialLinesDataFrame from a dataframe?

I have created a data.frame in R . I want to get SpatialLinesDataFrame as a result so I understand that I have to convert the data.frame into lines, the lines into SpatialLines and the SpatialLines ...
9
votes
3answers
1k views

How to measure similarity of SpatialLines objects

I created two SpatialLines objects in R: . These objects were created this way: library(sp) xy <- cbind(x,y) xy.sp = sp::SpatialPoints(xy) spl1 <- sp::SpatialLines(list(Lines(Line(xy.sp), ID="...
9
votes
1answer
6k views

Importing multiple stacked raster images in R?

I would like to import all multiple mosaic rasters (each mosaic is composed by 7 layers) from indicated folder into my R. Then access them as single multilayers rasters. So I did: # read all mosaics ...
9
votes
1answer
3k views

Difference between gdalwarp and projectRaster

I am trying to project a Raster. In R there is the projectRaster() function to to this (below a fully reproducibly example) : # example Raster require(raster) r <- raster(xmn=-110, xmx=-90, ymn=40,...
9
votes
2answers
7k views

buffer and union in R without reducing to a multi-polygon

I would like to perform a spatial overlay to identify the polygon within which a set of points fall. However I first want to buffer and dissolve the polygons, such that points falling anywhere within ...
9
votes
2answers
4k views

Unsupervised classification with kmeans in R

I have a time series of satellite images (5 bands) and want to classify them by kmeans in R. My script is working fine (loop through my images, convert the images to data.frame, cluster them, and ...
9
votes
1answer
376 views

How to find the most spread out locations?

Probably a very simple question. I have a list of about a thousand potential geographical locations (lat lon), and of those I need to select the 200 locations that are "most spread out". I think that ...
9
votes
1answer
5k views

calculate {minimal} distance between polygons in R

I have calculated the surface area of species distributions (merging polygons from shapefiles), but since this area can be comprised of quite distanced polygons, I would like to calculate some measure ...
9
votes
3answers
855 views

Read only part of an ESRI shapefile into R

I have a very large ESRI shapefile (>8000 polygons, .shp file is >32MB), which I want to read into R on Windows 7. I am familiar with rgdal and readOGR(). However, with this size of shapefile, ...
9
votes
1answer
8k views

Max cell value from a stacked raster

How can I find a max cell value from a stacked raster. Rmax <- maxValue(RAD1998.all[[1]]) works fine but Rmax <- maxValue(RAD1998.all[[2]]) gives NA. Of course not in a stacked raster. ...
9
votes
3answers
2k views

Spatio-temporal block kriging with R package gstat?

In the documentation of sp I saw that the coords argument of the SpatialPolygons function only accepts 2 columns. Is it not possible to create 3-dimensional polygons? I am doing spatio-temporal ...
9
votes
1answer
5k views

How to assign colors to specific raster values using R

I am using the levelplot function of the awesome rasterVis package to create a map whose values diverge around zero. I am plotting a raster file using a red to blue palette, but I am trying to assign ...
9
votes
1answer
1k views

Writing multiple layers to GeoPackage using writeOGR() in R?

I'm trying to write multiple layers to the same GeoPackage in R, but I get an error, Creation of output file failed. I have tried to search for documentation of reading and writing to .gpkg files with ...
9
votes
1answer
5k views

Interactive and dynamic map with wind data in R leaflet?

I have some data like this : longitude latitude speed direction 1 6.10722222 46.23639 4 360 2 6.95416667 43.54694 4 360 3 7....
9
votes
1answer
1k views

Euclidean and Geodesic Buffering in R

In Understanding Geodesic Buffering, The Esri Geoprocessing Development Team distinguish between Euclidean and Geodesic Buffering. They conclude with "Euclidean buffering performed on projected ...
9
votes
1answer
5k views

Decreasing distance between legend's items in R?

I'm trying to create correct choropleth() map in R using GISTools package. I use choro.legend() to display my legend. However I can't create either correct legend placement, AND/OR I don't understand ...
9
votes
1answer
6k views

How to read *.adf files into R?

I want to load .adf files into R. The data is from this page: http://www.fao.org/geonetwork/srv/en/metadata.show?id=14057 I tried the following code that I found after some research in the internet. ...
8
votes
4answers
4k views

How to compute max and min coordinates for multiple polygons?

I would like to calculate the maximum, median and minimum latidudinal coordinates for a large set of polygons, using QGIS or R. So the highest and lowest points reached by each polygon across a ...
8
votes
4answers
5k views

Create an inset map in R

I need to create a map of my sampling site, and the journal requested to make an inset map showing where in the world this map is, this is my map code. library(maps) library(GISTools) map('state', ...
8
votes
1answer
20k views

Calculate area for each polygon in R

I am working with a shapefile that has many polygons. How do I add one more field named "area_sqkm" and calculate area for each polygon in the shapefile?
8
votes
3answers
5k views

Efficiently reading and reclassifying many rasters in R?

I've been tasked to create a suitability analysis of wave conditions in the Gulf of Mexico. I have 2 thousand or so raster files that are about 8 MB each (2438 columns, 1749 rows, 1km cell size). ...
8
votes
2answers
770 views

Selecting features “above” or “below” a line using R

Given a line and a set of points, I can't figure out how to use sf to identify which side of the line each point falls. A small reproducible example follows, adapted from a different question # Load ...
8
votes
3answers
10k views

Removing columns in a SpatialPolygonsDataFrame in R?

My spatial polygon data frame (SPDF) contains too many columns (variables) and I want to remove most of the columns entirely. I know how to do this with a regular data frame in R, but I am unsure ...
8
votes
4answers
4k views

What is the cause of 'tearing' of polygons (artifacts) using R, ggplot and geom_polygon?

Thanks to the answer given in this question I have been able to subset and draw a map of electoral divisions in part of the UK, in this case Pembrokeshire. The resulting data frame is large and ...
8
votes
2answers
3k views

Re-projecting raster in R: gives warning that projected point(s) not finite?

1. Question I have encountered a warning using the projectRaster() function in the raster package in R. A full reproducible example is pasted below. Warning message: In rgdal::rawTransform(...
8
votes
3answers
16k views

R : How to build heatmap with the leaflet package

I read a post about interactive maps with R using the leaflet package. In this article, the author createD a heat map like this: X=cbind(lng,lat) kde2d <- bkde2D(X, bandwidth=c(bw.ucv(X[,1]),bw....
8
votes
1answer
5k views

Distance to nearest point for every point same SpatialPointsDataFrame in R

I have a SpatialPointsDataFrame that I'm working with in R. I want to add a new vector to the dataframe that contains, for every point, the distance to the nearest other point in the ...
8
votes
1answer
4k views

R raster: masking a raster by polygon also remove cells partially covered?

I want to mask out a raster based on the values of a polygon: i.e., set to NA all values of the raster that are not covered by the polygons. However, it seems that raster::mask() masks out cells (i.e. ...
8
votes
1answer
5k views

Fill the gaps using nearest neighbors

I want to fill the NA values using the average values of the nearest neighbors: r <- raster(matrix(1:16, nrow=8, ncol=8)) r[r==12] <- NA
8
votes
2answers
5k views

How to join a table to a shapefile with non-matching IDs and names (similar strings)?

I'm having an annoying problem that I'm trying to find an automated solution for. The shorthand version is that I have a shapefile and a table of created data for regions within countries. The created ...
8
votes
2answers
1k views

Problem with plotting map in R

While plotting the gadm map of Russia in R, I have a problem at the 180 degree meridian, where part of the Russian region is plotted separately. You can see it on the plot using the following code (it'...
8
votes
2answers
3k views

R: sf package points to multiple lines with st_cast

I want to create multiple lines out of given points as sf objects. If I have a number of points as library(sf) pts <- st_multipoint(matrix(c(10, 10, 15, 20, 30, 30), nrow = 3, byrow = TRUE), dim =...
8
votes
1answer
5k views

Extracting mean of multiple raster layers using R?

I don't know how to deal with big data that I had from radars. I've have 144 images .tif per day and I need to extract a mean daily value, for each pixel, and export it in one image .tif. I thought ...
8
votes
2answers
5k views

Alternatives of spTransform?

Let's say that we have a shapefile with a certain projection. s<-readOGR(dsn=".",layer="Spain") We also have the airports of Spain as points in another projection. a<-readOGR(dsn=".",layer="...