Questions tagged [sp]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
550 views

Setting fill to a variable based on data within SpatialPolygonsDataFrame?

I'm currently on the cusp of getting done what I want to get done - but having a slight problem with referring to my data from within R's sp SpatialPolygonDataFrame object. The issue is how ggplot2 ...
1
vote
1answer
70 views

Using R to create a choropleth generated from lat/lon lists - with data generated internally

a friend referred me here as opposed to the regular Stack Overflow site, as this community maybe better able to help! My issue is largely with the syntax and framework of ggmap,ggplot, and the sp ...
0
votes
1answer
212 views

Connect points from two SpatialPointsDataFrames in R, considering the closest distance

I have two SpatialPointsDataFrames. In SpatialPointsDataFrame one (dat1) I have three points (A, B and C). In SpatialPointsDataFrame two (dat2), I have eight points with temperature measurements. I ...
1
vote
0answers
33 views

Clipping polygons to existing plotting area

I have an existing plotting area onto which I want to add some polygons. In order to be sure the polygons' labels are displayed within the plotting area, I'd like to clip the polygons to this area so ...
1
vote
0answers
35 views

Swapping raster bands on disk efficiently using R

I have two raster files, each with RGB bands and an alpha layer. I would simply like to swap one of the raster's alpha bands for another, but to do so as efficiently as possible (these are very big ...
1
vote
1answer
128 views

Generating lines from coordinate file using R?

I have got an excel sheet with X and Y coordinates, actually Y is constant, since it is a straight line. I want a Shapefile with as many features as distance between points. I only get one line from ...
3
votes
1answer
173 views

sf appears to truncate a projection string

Curious how folks deal with this type of thing where sf appears to trim the spatial projection: library(sf) library(sp) nc <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) ...
5
votes
1answer
434 views

R spTransform polygon that crosses dateline

I have created polygons with CRS = UTM (see here), which I need to transform to latitude/longitude. Some of my polygons cross the dateline, which causes the transformation to create a polygon that ...
2
votes
1answer
119 views

How can / should sf spatial objects be translated (i.e. moved within same projection)?

Big fan of the sf (and previously, sp) spatial packages in R. I see spTransform and st_transform as methods to reproject a spatial object into a new space. However, I have a case where I have a ...
0
votes
1answer
360 views

Mapping data: error in classIntervals: var is not numeric

When executing the 'classIntervals' command I got the error while mapping data from Eurostat. library(rgdal) library(RColorBrewer) library(sp) library(GISTools) library(classInt) library(maptools) ...
1
vote
2answers
1k views

Creating lines between pairs of points

I have a sf dataframe table_sf as: Classes ‘sf’, ‘tbl_df’, ‘tbl’ and 'data.frame': 12251 obs. of 5 variables: $ ID : int 1 2 3 4 5 6 7 8 9 10 ... $ NOMBRE : chr "AL011900" "AL011900" "...
0
votes
2answers
483 views

Creating empty SpatialPoints or SpatialPointsDataFrame in R?

I have been trying to create an empty SpatialPoints in R but have not found the way yet. I have tried with this formula: SpatialPoints(as.matrix(data.table(x = numeric(), y = numeric()))) But it ...
6
votes
1answer
1k views

Kriging example with sf object

I am new to geo spacial analysis. I would like to learn kriging from a simple example. Say, we have four points with some z value. library(sf) library(gstat) library(tidyverse) dt<-tibble::...
0
votes
2answers
183 views

Error with Intersecting Rasters and Lines in R

I'm trying to ''cut'' a spatial lines data frame object by a raster grid using R, raster::intersect(SLDF, grid) However, when I run this code I get, Error in as.vector(x) : no method for coercing ...
2
votes
1answer
190 views

Find overlay between polygons excluding boundary

I want to find which polygons in a spatialpolygonsdataframe overlay each polygon in another spatialpolygonsdataframe. I have tried to use the function over from the package sp and it works fine... ...
0
votes
1answer
102 views

spTransform produces unexpected results

I am struggling to plot points using WGS84 co-ordinates on a map of the UK using the OSGB 1936 / British National Grid CRS. I'm using the rgdal package in R. Here is my reproducible example, using ...
0
votes
1answer
63 views

Find tree whose closest to the greatest variety of other trees using sf and R

Given a large spatial database of trees (600,000) find the tree that within radius r encircles the greatest variety of types of trees. Looking at an answer by andyteucher I've simulated some tree ...
2
votes
0answers
230 views

Length of the boundary intersection between two polygons in R

I am trying to find the length of the border shared by two polygons. I have run cleangeo on these shapefiles. There were no flags that came up. I have looked through several other posts on the topic ...
0
votes
0answers
333 views

plot coordinates as points with spplot in R

I want to do something that I thought should be relatively simple, but it doesn't seem to work... I have a SpatialPointsDataframe and a SpatialPolygonsDataframe. I want to plot all the points I have ...
0
votes
0answers
330 views

spTransform doesn't seem to actually reproject my data

I'm trying to create spatial point data and lay it over a shapefile. I'm starting out with simple LatLons, converting to sp using Coordinates(), changing the CRS to the same as the shapefile, and then ...
0
votes
1answer
197 views

change ggmap to sp.: Create circle where radius represents distance (km)

I am trying to made multiple concentric circles of multiple radii in kms scaled to a map, similar this post was using the post here (ggmap: create circles). map.sp<-readShapeSpatial("C:file.shp") ...
3
votes
1answer
38 views

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 ...
2
votes
1answer
231 views

sf equivalent of R maptools package's SpatialLinesMidPoints

I've been moving most of my workflow to using the sf package in R, and I'm trying to find the equivalent to the maptools package SpatialLinesMidPoints function - I've used this function frequently ...
1
vote
1answer
590 views

Converting projected coordinates from bbox into long/lat using R?

I have a DEM file in QGIS and would like to import the the satellite image for the same region into R. According to QGIS, the CRS used in the DEM file is: Layer Spatial Reference System +proj=...
0
votes
1answer
180 views

r-Mapview non reponsive with large simple feature dataframe?

I am trying to visualize a large sf dataframe with around 1000 rows containing linestrings with mapview::mapview() in R. Unfortunately a warning comes up when I perform the command: mapview(data....
3
votes
2answers
291 views

Is their an equivalent of SpChFIDS for a spatial POINTS data frame?

This code: seattle <- spChFIDs(seattle.shp, paste("seattle.shp", row.names(seattle.shp), sep=".")) Results in this error: Error in (function (...
2
votes
1answer
1k views

Adding labels to spatial grid in leaflet using R?

Problem: I am trying to add grid cell labels to a leaflet map in R using shapefiles provided by TIGER/Line Census Data. The desired result is a leaflet map displaying the raster ID layer labelled ...
2
votes
1answer
147 views

Orphaned Holes after Mercator-Projection in R

In R I want to apply the Mercator-Projection to a SpatialPolygonsDataFrame before plotting it with ggplot. I dont want to use ggplot::coord_map() since the map is supposed to be the "canvas" for a ...
4
votes
2answers
3k views

Create spatial polygon grid from spatial points in R

I am trying to recreate a map in R. I need 2 by 5 degree grid cells across the contiguous United States, but plotted in Albers Equal Area. The result is a grid with curved lines and slightly variable ...
14
votes
1answer
6k views

equivalent of sp package's point in polygon / overing using sf

I am migrating code from sp package to the newer sf package. My previous code I had a polygon SpatialDataFrame (censimentoMap) and a SpatialPointDataFrame (indirizzi.sp) and I got the polygon cell id (...
0
votes
1answer
579 views

Why did spTransform fail here?

I'm trying to convert a map I found here into lat/lon compatible with another data set I created from Google Maps lat/lons. From the directory with that .shp file, I run: library(rgdal) SG = readOGR(...
2
votes
1answer
3k views

Package sp : coordinates function error no numeric matrix

I am trying to use coordinates function from sp package to transform my data in spatial data. I made sure I deleted all the NAs values and that all my data is numeric, however, i still get the same ...
1
vote
2answers
2k views

How to use rbind with SPDFs when the number of columns of arguments do not match?

I'm looking to use rbind to combine the SPDFs of different European countries. However, I'm looking to use SPDFs of different levels of regions. Unfortunately, I'm getting the following error: ...
0
votes
2answers
359 views

ggplot2 adding extra polygons

So, I'm working with a dataset of polygons generated at different levels of sensitivity to error from a citizen science project. I have been trying to visualize how my sensitivity threshold changes ...
2
votes
1answer
796 views

Error While Converting UTM data to Lat-Long Coordinate

I have a a dataset of Vancouver,BC where Coordinate values are projected in UTM Zone 10 . Now I can convert it using spTransform by the following piece of code and looks like the it correctly ...
2
votes
1answer
2k views

Converting Spatial Points to Neighbours List using R?

I am trying to convert some spatial points into a listw object to run the moran.mc function on my data. The data are not adjacent but the points cluster in spatial patterns. Here is how I have tried ...
2
votes
0answers
185 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
274 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
834 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
56 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
4k 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
437 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
537 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
279 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
716 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
959 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 ...