An R package for spatial data. Questions on spatial data might be better asked on https://gis.stackexchange.com
Questions tagged [r-sp]
691 questions
3
votes
2 answers
Calculate the euclidean distance between points within grouped data
In the data below (included with dput), I have repeat observations (lat and long) for three individuals (IndIDII). Note, there are a different number of locations for each individual.
> Dat
IndIDII IndYear WintLat WintLong
1 BHS_265…

B. Davis
- 3,391
- 5
- 42
- 78
3
votes
1 answer
Surface Area Weighted Spatial Join of Polygons
Problem Statement
I have two sets of polygons and I want to join quantitative features from one set of polygons into another.
For example, consider the multipolygon of Yolo county, yolo. I want to aggregate tract-level data from all features in the…

Rich Pauloo
- 7,734
- 4
- 37
- 69
3
votes
2 answers
How to set the alpha based on a column?
Consider this example:
library(dplyr)
library(sf)
library(tmap)
d <- data_frame(one = c(1,1,2,1,1,1,1),
two = c(1,1,2,1,1,1,1))
std <- st_as_sf(d, coords = c('one', 'two'))
std %>% tm_shape() + tm_bubbles(alpha = 0.3)
You can…

ℕʘʘḆḽḘ
- 18,566
- 34
- 128
- 235
3
votes
1 answer
Plot shapefile on ggplot
library(raster)
library(ggplot2)
map.shp <- getData('GADM', country='FRA', level=1)
plot(map.shp)
ggplot(mtcars, aes(x = hp, y = disp)) + geom_point()
How can I put the map.shp on the right side of the ggplot as a small inset.

89_Simple
- 3,393
- 3
- 39
- 94
3
votes
1 answer
Aggregating all SpatialPolygonsDataFrame objects from list into one SpatialPolygonsDataFrame
Not looking to editing topology, merely aggregating all polygons into one sp object of type SpatialPolygonsDataFrame (spdf). There is only one polygon per spdf.
Data (dropbox link to data) (filesize 1.1KB) ( dput() not appropriate in this instance):…

jpinelo
- 1,414
- 5
- 16
- 28
3
votes
2 answers
determine whether location of fish is wrong based on boat speed and time of last capture
I have a series of coordinates for fish caught from a boat at different datetimes and different trips. How do I determine whether the coordinates of a fish are likely to be incorrect (e.g. due to transcription error) based on time since last fish…

sebdalgarno
- 2,929
- 12
- 28
3
votes
1 answer
Merging the polygons inside a spatial polygons data frame based on a field in the @data slot
I am not a pro with R nor spatial analysis. I am looking for a way to combine the polygons inside a spatial polygons data frame based on a field in the @data slot: the equivalent of dplyr's "group_by" for spdf's.
I'm not sure if merge, join, or…

Claudio Paladini
- 1,000
- 1
- 10
- 20
3
votes
1 answer
How to plot a shp with holes with ggmap?
I am trying to plot a *.shp file available here ArcGis. Looking at the page where I took the data from, I would expect the colored area to look like this:
.
But when I plot it I get something different (see below). In particular, it seems that some…

Dambo
- 3,318
- 5
- 30
- 79
3
votes
1 answer
Create empty spatial lines object
I am trying to create an empty SpatialLines object. With polygons it is easy:
SpatialPolygons(list())
For spatial lines this does not work:
SpatialLines(LinesList = list())
Error in bb[1, ] : incorrect number of dimensions
SpatialLines(LinesList =…

Tobias Dekker
- 980
- 8
- 19
3
votes
2 answers
Does this point stand within a polygon?
Very simple situation : a polygon define a geographical area and I want to know whether a point, given by it gps coordinates, lies within that polygon.
I went through many SO questions and have tried various functions and packages like sp, but…

Xavier Prudent
- 1,570
- 3
- 25
- 54
3
votes
0 answers
Leaflet for non-geographic data (Cartesian coordinates) from R
I'm trying to create an interactive plot with leaflet containing polygons.
The coordinates of these polygons are not longitude/latitudes but rather Cartesian x and y coordinates that represent a building floor plan.
For coordinates that are single…

Jeroen Boeye
- 580
- 4
- 18
3
votes
0 answers
Error in polygonData/default(data) : Dont know how to get path data from object of class numeric
I have a function that creates a leaflet map from data outputs of other functions. One of my outputs is a spatialPolygonsDataFrame, which is the result of a buffer of groups of points using gBuffer, followed by gUnaryUnion to dissolve each group…

gvan
- 473
- 4
- 15
3
votes
2 answers
5 nearest neighbors based on given distance in r
I have the following dataset:
id x y age
1 1745353 930284.1 30
2 1745317 930343.4 23
3 1745201 930433.9 10
4 1745351 930309.4 5
5 1745342 930335.2 2
6 1746619 929969.7 66
7 1746465 929827.1 …

user2797174
- 167
- 2
- 11
3
votes
2 answers
Underlay a vector image to a grid for kriging in R
After searching around a lot, asking, and doing some code, I kinda got the bare minimum for doing kriging in R's gstat.
Using 4 points (I know, totally bad), I kriged the unsampled points located between them. But in actuality, I don't need all of…

ace_01S
- 387
- 2
- 5
- 16
3
votes
3 answers
Bounding box for each polygon in SpatialPolygonsDataFrame R
How can I get the bbox for each polygon in polys?
pp <- cbind(coordinates(polys),as.data.frame(polys))
gives me lonlat only but I would like to get lat1lat2 and lon1lon2 for each polygon.
polys=new("SpatialPolygonsDataFrame"
, data =…

code123
- 2,082
- 4
- 30
- 53