Questions tagged [r]

Statistical computing language and software environment.

R is a programming language and software environment for statistical computing and graphics. It offers a number of tools and methods for statistical analysis of almost everything. Several add-on packages provide functions for handling and analysis of spatial, and particularly geographical, data. These packages can be roughly structured into the following topics:

  • Classes for spatial data
  • Handling spatial data
  • Reading and writing spatial data
  • Point pattern analysis
  • Geostatistics
  • Disease mapping and areal data analysis
  • Spatial Regression

See the CRAN Task View Analysis of Spatial Data for further information.

Resources:

5860 questions
14
votes
1 answer

Subset a SpatialPolygonsDataFrame by ID in R?

I've used the gIntersect function from the rgeos package to determine which polygons intersect in two SpatialPolygonsDataFrames (spdfs). The result is a logical matrix with rownames comprising the polygon IDs from sfdf #1 and colnames the polygon…
Alberto
  • 143
  • 1
  • 1
  • 5
10
votes
3 answers

How to produce spatial grid from raster?

I need a Spatial Grid as a master grid for diverse thematic maps. How do I produce a Spatial Grid from a raster discarding all NA pixels?
10
votes
1 answer

Error: identicalCRS(x, y) is not TRUE

I have a spatial Grid dataframe, Elev, that I want to crop by a spatial polygon object (state.sp). I assigned the CRS to both objects with spTransform and the CRS defined as: CRS.new<-CRS("+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96…
user89556
  • 101
  • 1
  • 3
8
votes
2 answers

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="airports") If we aim to place the points onto the Spain's…
gsa
  • 1,246
  • 6
  • 19
  • 29
7
votes
3 answers

Converting DMS coordinates to decimal in R

I have a vector of DMS coordinates similar in format to the following: coords <- c("43°46′50″N 79°24′53″W", "43°46′06″N 79°24′46″W") and I would like to convert them into two numeric decimal vectors for latitude and longitude to eventually mark…
Phil
  • 207
  • 1
  • 3
  • 7
7
votes
2 answers

Remove points which are out of shapefile (or raster) extent

My problem is quite simple. I have thousands of points (coordinates) to analyse, however some of them are so inaccurate that they "hit" the sea. I need to get rid of them. I was trying to find some R function which is capable to filter (delete) such…
Ladislav Naďo
  • 267
  • 3
  • 10
7
votes
1 answer

Wrap a raster at the 180° meridian

I have a raster file that extends longitudinally from 0° to 360°. Using R, I'd like to wrap the raster at 180°, so that longitudes between 180° and 360° are translated to the interval [-180°, 0°]. Is there an existing function or package that can do…
Dan
  • 409
  • 4
  • 11
6
votes
2 answers

Joining grid or polygon layers in R?

I have two grids. Cells in each grid have an attribute. Size of grid cells differs between the two grids and the two grids do not overlay each other perfectly. I would like to create a new layer, or group of polygons, or grid, that results from…
Mark Miller
  • 230
  • 1
  • 9
5
votes
2 answers

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
user204173
5
votes
2 answers

R- alphahull - duplicate points error help

I am just starting to use R. I came across R function -alphahull- and believe it is the best option to turn gps points into a polygon (3 or 4 days worth of gps points across residence/neighborhood for each of 300 subjects). How do I remove duplicate…
user9914
  • 71
  • 1
  • 3
5
votes
2 answers

Sum up rasters in R

I have 365 rasters (daily_sm2rain data of a year) in .TIF. I would like to create a new raster which is sum of 365 input rasters in R (~ sum of rain in a year). How can I do this? I tried input=list.files("path_to_data",pattern="*.tif$"). it's…
quoc-non duong
  • 51
  • 1
  • 1
  • 2
5
votes
1 answer

How to compute the number of none NA-values for each row?

I have a matrix(raster) that I am computing the the mean of each row in this raster as: library (raster) r <- raster(nrows=10, ncols=10);r <- setValues(r, 1:ncell(r)) # The x-values will be the mean of each row in the raster: xvals =…
usersam
  • 259
  • 1
  • 2
  • 11
4
votes
1 answer

R - Dealing with missing data in SpatialPolygonDataFrames for Moran.test

I'm trying to use Moran.test on a SpatialPolygonDataFrame consisting of 7194 elements in R. I know that there is around 150 polygons with NA values. First I generate a spatial weights matrix: W_cont_msoa <- poly2nb(all.data, queen=T) …
4
votes
2 answers

Add Numbers to United States Map Help R, R-Studio?

Can someone help me with creating a map in R? I need to make a map of the number of retail stores a company has in each state. All I need is the store count displayed in each state. For example: if there are 150 stores in California and 250 in…
Nathan Wadhwani
  • 71
  • 1
  • 1
  • 3
4
votes
3 answers

Look up OS grid letters from easting/northing in R

Suppose I have an easting/northing point: data<-c("423851", "300384") I would like to find out the grid letters for this point using the British National Grid system (Ordnance Survey). If you visit https://gridreferencefinder.com/ and put those…
Simon
  • 259
  • 3
  • 11
1
2 3
13 14