Questions tagged [sp]

R package with classes and methods to create and manipulate spatial data

Filter by
Sorted by
Tagged with
2
votes
0answers
194 views

Maintaining same extents in R?

How can I maintain perfectly equivalent raster and SpatialPointsDataFrame extents when in R? Each time I combine rasters, or raster and point data, the extents are very slightly different (like ...
5
votes
1answer
323 views

Polygon and raster in the same plot do not align

I can't manage to plot a raster and boundary of country (sp data frame) in the same plot. The data (lon,lat,value) are in mat data frame. The grid is not regular and comes from a climate change ncdf ...
2
votes
1answer
938 views

R doesn't find SpatialPoints or SpatialPointsDataFrame

I'm trying to create SpatialPoints objetcs from data frame on R natFPV <- SpatialPointsDataFrame(coords = coordinates(natFPv.per_data[,c(27,28)]),data = natFPv.per_data[,-c(27,28)]) natFPV <- ...
0
votes
1answer
65 views

Coercing to sp and dealing with duplicate field names

I am dealing with a very similar situation as described at: rgdal::writeOGR collision in column names results in NULL data I have an sf object with duplicate field names (in a case-insensitive way). ...
3
votes
2answers
5k views

How to plot gridded map from lat-lon and fill values in R?

I want to plot a spatial map in which each pixel is of 0.25 degree spatial resolution in R. For this I have fill values at 0.25 degree grid spacing. Below is the data ----------------------- ...
1
vote
1answer
497 views

Using R, why am I unable to select a column from an sp Spatial Lines Dataframe?

With utm_RDS being the spatial lines in question, derived from the following shapefile: library(rgdal) library(sp) RDSYS <- readOGR(dsn = "C:/************") utm_RDS <- ...
2
votes
1answer
2k views

Extracting Spatial Points that match Raster Value using R?

I have a question concerning the extraction of spatial points that match a certain value of an additional raster in R. The operation itself should actually be pretty simple, but I'm stuck somehow. (I ...
0
votes
1answer
588 views

spplot() does not work properly when called via a function

I have spatial data in R, let's say an object of formal class SpatialPointsDataFrame but the below problem is encountered with Raster too. I can plot easily the data with spplot() and save a .png ...
1
vote
1answer
306 views

Write time stamp for .gpx in R

I am in the process of editing gpx files and need to write the files back to .gpx in order to put them in a GPS unit. Basically, I am cleaning up some data and removing some track points. However, ...
4
votes
1answer
3k views

Breaking out single polygon (feature) of SpatialPolygonDataframe

I am trying to break out a single feature of a Spatialpolygon object. That is e.g. plot a single polygon from a shapefile that contains multiple. Any suggestions how to do this? >#Import shapefile,...
3
votes
0answers
779 views

Group and aggregate SpatialPolygonsDataFrame by column in R

I'm working with rgdal, sp, maptools, etc. I have a SpatialPolygonsDataFrame that has each row/Polygons list with only one Polygon. It also has an identifier column which I want to use to group by, ...
3
votes
0answers
130 views

Assigning a new coordinate system and projection to a shapefile in R [duplicate]

I have a shapefile with no spatial reference nor projection, and a GEOTIFF that has the spatial reference and projection data. The shapefile was created from a segmentation analysis of the GEOTIFF, ...
5
votes
1answer
1k views

Slow plotting of spatial data in macOS RStudio's plotting device

In my macOS system RStudio, plotting spatial data (statialpolygons, points and lines) is extremely slow, making it impossible to work with. When I try to plot the shapefile in this link (@https://...
1
vote
1answer
1k views

R spatial aggregate, IDs out of order

HUC12_intersects is a SpatialPolygonsDataFrame object with over 5000 polygons library(rgdal) library(sp) library(rgeos) library(raster) library(maptools) HUC12_intersects@data AREA_ACR_1 GEOL_CODE ...
3
votes
0answers
319 views

How to apply a rectangular buffer on spatial polygons in R/qGIS

I am trying to find a way to apply a rectangular buffer on my spatial polygon dataframe in R. At the end, I would like to be able to shrink my polygons by specified units on both sides. So far, I have ...
2
votes
1answer
2k views

R- Polygons overlapping Polygons

I'm very new to spatial stuff in R and am trying to do something I imagine is very simple but am having trouble. I have two spatialpolygonsdataframes. 1 is of all US counties and another is of core-...
2
votes
4answers
3k views

Merge a list of SpatialLines

I started off with a SpatialPointsDataFrame, containing locations from animals wearing GPS loggers. Aside from the coordinates, the data frame also contains the animals' ID and a timestamp. From ...
1
vote
3answers
1k views

Is there an equivalent of dplyr::bind_rows (or the old plyr::rbind.fill) for spatial objects?

bind_rows can append dataframes even when they do not have identical columns. It fills any non-matching columns with NAs. Is there an equivalent for spatial point data frames in R? I have two ...
2
votes
1answer
680 views

How to display legend in mapview when using cex argument

Giving the example: library(sp) library(mapview) data(meuse) coordinates(meuse) <- ~x+y proj4string(meuse) <- CRS("+init=epsg:28992") mapview(meuse, cex = "cadmium", legend = TRUE) I was ...
4
votes
1answer
2k views

Set the minimum and maximum values for an elevation raster in R

I have a raster that displays elevational values at a global scale. I would like to set the minimum and maximum values based on the values I would like to choose. > elev class : RasterLayer ...
1
vote
1answer
376 views

What is the most efficient way to do a spatial join of all raster points within a polygon layer area?

I have a raster GeoTIFF of a digital elevation model and a polygon shapefile with spatial boundaries of the raster. Here is a snapshot of raster and polygon layer: The shapefile has one attribute ...
4
votes
1answer
331 views

inconsistent results with sp::over in R

I have a dataset with lat/longs mostly in the UK and want to add a column indicating parliamentary constituency. The whole dataset is ~50k rows by 30 columns. A short sample is: lat long Age ...
2
votes
2answers
1k views

Calculating Proportion of Land Cover Classes with moving window around point in R?

I am currently using a raster that is a land cover class raster (with 50 different land cover classes at a resolution of 30m). I would like to obtain 50 different rasters (essentially predictors for a ...
1
vote
1answer
242 views

Converting spatial objects to lists

I have a SpatialLinesData frame with 1657 different routes. Each route is of a different length and has a differing number of nodes or waypoints (lat, lon). For example, routes@line[[87]] is made up ...
2
votes
2answers
333 views

Number of segments in SpatialLinesDataFrame

After importing a spatial lines dataframe with readOGR, I would like to determine the number of line segments (nodes) in each line. I cannot find a practical way to simply export the lengths as a ...
2
votes
2answers
1k views

Enlarging polygon slightly using R?

Consider the following scenario: I have made polygon of mainland Africa + Madagascar. From a different source I have got some point data about this area. The point data include points in small ...
2
votes
1answer
584 views

Using getValues in R but unable to obtain corresponding row number and column number

I currently have a list of PC values for each row and column of a raster. I would like an output that looks like this: x y PC 1 500 -3.45 1 501 -2.8 Here, x and y stand for row ...
0
votes
1answer
466 views

Error coercing raster to SpatialPixelsDataFrame in R

I obtain the below error when I try to coerce my raster to a vector. Initially my rasters are of different extents and I use the projectRaster tool to obtain the same extent for both the rasters. ...
4
votes
1answer
1k views

Difference between large Rasterlayer and formal class Raster Layer in R?

I currently possess two rasters with the EXACT SAME resolution and extent, and yet they show different number of rows when loaded into the global environment in R. In addition, before these rasters ...
2
votes
1answer
889 views

Same extent and resolution of rasters, but different number of cells

Based on Unable to writeRaster for signature "rasterPCA", "character", I obtained two rasters that are PC1 and PC2 of a bunch of climatic variables. However, irrespective of having ...
0
votes
1answer
510 views

Unable to writeRaster for signature “rasterPCA”, “character”

I am currently trying to obtain two rasters that are the Principal component axes 1 and 2 for a list of bioclimatic variables that I am using. I am using the rasterPCA() function that exists in the ...
2
votes
3answers
721 views

How can I determine the area of each block of a SpatialGridDataFrame in R?

I'd like to be able to determine the area of each block inside a grid of (long, lat) coordinates. How can I do this? Alternatively, how can I determine the area of any Spatial Polygon with a long+...
1
vote
1answer
440 views

Find closed lines inside SpatialLines objects in R

I need to find which lines are closed lines and which aren't inside a SpatialLines object in R. A closed line mean that the first point is the same as the last point. Is there any tool or function in ...
1
vote
1answer
169 views

Finding the side of a square that a point intersects with R (sp)

I have a point and a square polygon. Both are sp classes. The point intersects one side of the polygon, and I need to know which side of the square it intersects (i.e. north, east, south, or west). ...
3
votes
1answer
641 views

Counting how many times a point is inside a set of intersecting polygons in R

I have a set of points (latitude and longitude) and a set of polygons with the same CRS. Since some of the polygons are interescting, it may be that some of the points are in more than one polygon. ...
1
vote
0answers
905 views

points2grid error: (points,tolerance,round) - grid has empty columns/rows in dimension

I have seen answers to this on R-sig-geo, but I am still unclear on the solutions provided in different forums. Below, I am trying to convert a dataframe to a raster that can later be used in ArcMap (...
2
votes
1answer
466 views

Building multiple extents as polygons from lat/long list values in R

I have a loaded .csv table in R containing xlongl, xlongr, ylatb, ylatup values (EPSG:4326). Each row indicates with its combination of lat/long the extent of one rectangled polygon. > mydata ...
1
vote
1answer
37 views

Spatialdataframe from a multipoligon array column

i have a df with a character colum that contains an arrays of wgs84 coordinates. > head(df$Multipoint) [1] "[[11.038156,44.525654],[9.768989,45.620678],[7.923145,45.060564]]" ...
2
votes
1answer
362 views

Reproject global latlong into UTM slices

I'm working with a global shapefile in R that is latlong projected. I'd like to reproject it into the appropriate UTM projection for individual zones. But, I'd like to chop it up into those zones ...
2
votes
1answer
548 views

Removing attribute from SpatialPointsDataFrame with spdplyr::select() in R

I'm trying to drop columns/attributes from a SpatialPointsDataFrame, using spdplyr, like so: library(sp) library(spdplyr) x <- c(15.2, 15.3, 15.4, 15.5, 15.7) y <- c(50.4, 50.2, 50.3, 50.1, 50....
8
votes
3answers
3k views

Join spatial point data with multiple polygon data using R

I want to spatial join with SpatialPolygonsDataFrame and SpatialPointsDataFrame. get only one point data within multiple polygons, under the code. sp::over(meuse, srdf) Some points data into ...
6
votes
1answer
3k views

Creating empty Polygons or SpatialPolygons in R?

I'm working on a project where I'm looking at overlap in users circling an area in an image. Esentially, I make a SpatialPolygonsDataFrame where each user gets one row. Some users don't select ...
0
votes
1answer
327 views

How to change the coordinate scale of SpatialPolygons in R?

I hope to plot SpatialPolygons on satellite raster images. The coordinates of SpatialPolygons are converted to be in the range of x = [0,1] and y = [-1,0]. I know that this overlay plot can be done in ...
4
votes
1answer
598 views

Lapply function on raster iterating through SPDF polygons in R

I have a raster DTM and a SPDF. I'd need to mask a different elevation interval of the DTM within each overlaid polygon. I tried a for loop to iterate through the polygons, but as one might expect ...
2
votes
1answer
255 views

Error mapping categorical vector from spatial points data frame in R

I have had trouble mapping categorical points on to a map using rworldmaps or the maps package in R. The original data was Aragonite saturation levels in the ocean on an .adf file which was in ...
1
vote
0answers
43 views

Confirming accuracy of spatial match?

As a follow up to Correctly setting up CRS systems for the NUTS (Eurostat) geographies and Doogal's data? I have spatially matched a set of files, one with lat/long coordinates for postcodes ...
0
votes
3answers
448 views

I want to do SpatialLines programatically

This is my dataframe: df <- data.frame(ID = rep(1:100, each = 2), x =runif(200, 10, 90), y = runif(200, 10, 90)) For each ID I need to create SpatialLines, I haven't had good luck. I think I ...
2
votes
3answers
599 views

What are the coordinates on my rectangle of the closest point to a polygon in R?

I have a non-overlapping extent rectangle and a sample lake polygon. I can measure the distance from the rectangle to the polygon but I want to know which point on the rectangle is the closest to the ...
3
votes
1answer
2k views

Subset and sort a SpatialPolygonsDataFrame object by one variable

I took a sample of a spatial polygon dataframe with 2256 elements using: valdata <- ref_10[sample(ref_10@data$ID, length(ref_10)/3),] now I would like to sort my new spatial dataframe by my ID-...
1
vote
1answer
522 views

Seeking routing libraries in R?

I'm trying find libraries for R that would find the shortest route between two locations, given a SpatialLinesDataFrame representing the road network. All I could find was stplanr, which delegates the ...