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
71
votes
4 answers
rbind error: "names do not match previous names"
As part of a larger problem (adding a ,makeUniqueIDs argument to rbind.SpatialPolygonsDataFrame for situations when the polygon IDs are identical), I'm running into this weird message from rbind:
> do.call("rbind",xd.small)
Error in…

Ari B. Friedman
- 71,271
- 35
- 175
- 235
27
votes
3 answers
Efficient extraction of all sub-polygons generated by self-intersecting features in a MultiPolygon
Starting from a shapefile containing a fairly large number (about 20000) of potentially partially-overlapping polygons, I'd need to extract all the sub-polygons originated by intersecting their different "boundaries".
In practice, starting from…

lbusett
- 5,801
- 2
- 24
- 47
20
votes
3 answers
PROJ4 to PROJ6 upgrade and "Discarded datum" warnings
Context
My questions are related to the changes induced by the upgrade from PROJ4 to PROJ6
and the consequences in various R spatial packages (sp, sf, raster).
We receive now a lot of warnings about “Discarded datum” that looks a bit worrying and…

Gilles San Martin
- 4,224
- 1
- 18
- 31
20
votes
2 answers
Create SpatialPointsDataframe
I have a dataframe df1 with 10 columns. Two of these columns are lng and lat.
I want to create a SpatialPointsDataframe from df1.
When I read on how to create a SpatialPointsDataframe it feels like I have to create a matrix m1 from my two…

four-eyes
- 10,740
- 29
- 111
- 220
18
votes
2 answers
R - convert SpatialLines into raster
In R, we can take a raster and turn it into a SpatialLinesDataFrame with the function rasterToCountour:
library(raster)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
x <- rasterToContour(r)
class(x)
[1]…

Rich Pauloo
- 7,734
- 4
- 37
- 69
17
votes
2 answers
How to efficiently calculate distance between pair of coordinates using data.table :=
I want to find the most efficient (fastest) method to calculate the distances between pairs of lat long coordinates.
A not so efficient solution has been presented (here) using sapply and spDistsN1{sp}. I believe this could be made much faster if…

rafa.pereira
- 13,251
- 6
- 71
- 109
17
votes
1 answer
SpatialPoints and SpatialPointsDataframe
Working with the sp package in R.
I wonder when I would use SpatialPoints and when SpatialPointsDataframe. It seems so me that there is not much difference?!
Is the only difference that in a SpatialPointsDataframe I can store more attributes?!
If…

four-eyes
- 10,740
- 29
- 111
- 220
16
votes
1 answer
SpatialPolygons - Creating a set of polygons in R from coordinates
I am trying to take create a set of polygons from vertex locations, saved in X,Y format.
Here is an example of my data - each row represents the vertices for one polygon. the polygons are squares
square <- rbind(c(255842.4, 4111578, 255862.4,…

Leah Wasser
- 717
- 3
- 8
- 22
15
votes
1 answer
How do I generate a Hexagonal grid in R
I would like to be able to create a SpatialPolygons object (which is a Hexagonal grid) that covers another SpatialPolygon.
I would like all the Hexagons to have a diameter of 1km (ideally i can vary this) and for all the hexagons together to cover…

h.l.m
- 13,015
- 22
- 82
- 169
15
votes
2 answers
Converting a "map" object to a "SpatialPolygon" object
I am guessing there is a simple solution to the problem I have been having, but I am having some trouble.
I am trying to convert the following map object:
require(maps)
usa <- map("state")
into a SpatialPolygon object using the map2SpatialPolygons…

Mike.Gahan
- 4,565
- 23
- 39
14
votes
3 answers
R Overlay points and polygons with a certain degree of tolerance
Using R, I would like to overlay some spatial points and polygons in order to assign to the points some attributes of the geographic regions I have taken into consideration.
What I usually do is to use the command over of the sppackage. My problems…

Nemesi
- 781
- 3
- 13
- 29
14
votes
1 answer
Creating a regular polygon grid over a spatial extent, rotated by a given angle
Hi all,
I am struggling with this and hope someone could come out with a simple solution.
My objective is to create a regular polygon grid over the extent of a polygon, but rotated
by a user-defined angle.
I know that I can easily create a…

lbusett
- 5,801
- 2
- 24
- 47
14
votes
4 answers
How to find which polygon a point belong to via sf
I have a sf object that contains polygon information (precincts) for a metro area, obtained through a .shp file. For a given lat/lon pair, I want to determine which precinct it belongs to. I'm thinking I can utilize sf::st_contains() but am having…

kevinykuo
- 4,600
- 5
- 23
- 31
14
votes
1 answer
Changing the Projection of Shapefile
I am trying to change or assign the projection of a Germany-Shapefile from NA to +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0, but somehow it doesn't work well.
Reproducible Example:
Shapefile and other files can be downloaded…

And_R
- 1,647
- 3
- 18
- 32
13
votes
2 answers
Merge data frame with SpatialPolygonsDataFrame
I want to merge a SpatialPolygonsDataFrame :
# From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html
states <- readOGR(dsn = "./cb_2014_us_state_20m.shp",
layer = "cb_2014_us_state_20m", verbose = FALSE)
with a normal…

Ignacio
- 7,646
- 16
- 60
- 113