Questions tagged [sp]

An R package for spatial data. Questions on spatial data might be better asked on https://gis.stackexchange.com

615 questions
26
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,191
  • 2
  • 18
  • 43
17
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
  • 5,424
  • 3
  • 22
  • 50
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…
Stophface
  • 6,919
  • 16
  • 71
  • 152
15
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…
Stophface
  • 6,919
  • 16
  • 71
  • 152
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
  • 11,457
  • 18
  • 73
  • 155
15
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
  • 673
  • 1
  • 6
  • 20
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,323
  • 17
  • 37
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,517
  • 2
  • 16
  • 32
14
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
  • 10,729
  • 4
  • 59
  • 88
13
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,191
  • 2
  • 18
  • 43
12
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
  • 634
  • 10
  • 24
12
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,050
  • 4
  • 20
  • 29
12
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
  • 6,566
  • 8
  • 51
  • 99
11
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
  • 3,668
  • 13
  • 27
10
votes
3 answers

R measuring distance from a coastline

I have a set of coordinates: d1 <- data_frame( title = c("base1", "base2", "base3", "base4"), lat = c(57.3, 58.8, 47.2, 57.8, 65.4, 56.7, 53.3), long = c(0.4, 3.4, 3.5, 1.2, 1.5, 2.6, 2.7)) I would like to know whether the coordinates fall on land,…
Mrmoleje
  • 448
  • 1
  • 5
  • 20
1
2 3
40 41