Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sp]

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

0
votes
1answer
40 views

Subdivide raster file by polygon in R

I am trying to get a raster file of nightlights data for Brazil and subdivide/regroup it into several rasters for each state, in a list or data.frame in R I managed to download the nightlights file, ...
0
votes
0answers
7 views

Is it possible to assign values from polygons to a new layer in an existing raster in R?

I'm a bit of an R novice and looking to see if there is any way to assign values to a raster layer based upon polygons. Some background - I am working on a mining project and have a regular grid of ...
0
votes
2answers
28 views

How to save a plot to disc with tmap in R

I have made a plot with these lines mainland print(Bornhold, vp = viewport(x = 0.7, y = 0.5, width = 0.3, height = 0.2)) One is mainland and the other an island. How can I save it to one one png ...
2
votes
1answer
74 views

Extract areas with certain pixel values from raster

I have land cover data from GEE (https://developers.google.com/earth-engine/datasets/catalog/ESA_GLOBCOVER_L4_200901_200912_V2_3) for specific countries. I would like to extract the values from the ...
-1
votes
1answer
33 views

The slot for “plotOrder” comes up as 1 instead of a vector with length specific to my data

My goal is to find neighbors from my SpatialPolygons object using the poly2nb() command from the sp package in R. This is my code thus far: p <- s_gis %>% select(long, lat) %>% ...
3
votes
1answer
33 views

gIntersection error: linearRing not created

I am trying to do something relatively simple but with large shapefiles. I have a shapefile of protected areas in the USA: and watershed boundaries: I want to calculate the percentage and ...
1
vote
1answer
34 views

Error coercing raster with one non-NA value to SpatialPixelsDataFrame [closed]

I'm getting a strange error when trying to convert a raster with only 1 non-NA pixel to SpatialPixelsDataFrame. r0 <- raster( matrix( 1, 1,1)) as(r0, 'SpatialPixelsDataFrame') Error in (...
2
votes
2answers
255 views

Plotting spatial points data in R?

I have some kind of noob question: how do I plot spatialpoints dataframe in R using spplot (or ggmap) based on column values? let's say we have this: library(sp) data(meuse) v <- ...
3
votes
1answer
41 views

How might one optimise geospatial operations on complex polygons, especially plots in R?

Question: I'm attempting to run some simple plots on some shapefiles with a high number of complex polygons. These aren't massive files - for the example below, the shapefile is 70mb (15872 obs), but ...
0
votes
2answers
32 views

sf polygon goes black in for loop in R

I'm making this loop, it's part of a script I'm making to illustrate a percentage in a polygon (let's say instead of a pie) but then I realized it looks good as an animation; when I start plotting, ...
0
votes
1answer
89 views

Legend color scale problem with tmap for island

Bornholm_data <- geo_RH %>% filter(KOMNAVN=="Bornholm") tm_shape(geo_RH) + tm_fill(col="Befolkning") + tm_borders() mainland <- tm_shape(mainland_data, projection = 0) + ...
-1
votes
1answer
52 views

Dealing with Islands with sf objects and the tmap package [closed]

I have the bounderies for the municipalities in the "capital region" of Denmark. The acctual map looks like this: The yellow island is the fourth row in my sf object. I am trying to folllow the ...
0
votes
1answer
76 views

How to I limit the x and y axes with tmap in r

I have made this plot with the following code: library(tmap) tm_shape(RH2) + tm_fill(col="AREAL") + tm_borders() But there is a dot on the far right (an island) which I don't ...
0
votes
0answers
19 views

Error with over() ´sp ´ package in R

I have a df with spatial points that I've converted into a spatial object (dai18) and I want to select only the points that are inside a polygon (peri_A). I think my coordinate system is incorrect, ...
0
votes
1answer
40 views

Measure distance for spatialLine in R returns bad value

I have this spatialLine in R: library(sp) library(maptools) library(SDraw) library(leaflet) x <- c(153.9, 152.67072,147.9879,144.25364,135.45557,116.03998,76.92708,45.10622,37.02522,36.76888,36....
2
votes
1answer
39 views

Calculate distance between buffer and geographic points for grouped subsets (and get tally)

The data I used can be found here. After importing my data, I select a subset of points (Nest2017 in column type) to create 30 m buffers around: library(dplyr) nests<-df %>% filter(type %...
0
votes
1answer
57 views

How to create and empty SpatialLinesDataFrame in R

I need to create and SpatialLinesDataFrame with a predefined structure (9 fields). I'm performing a function over a list of shp which I want to append to this empty spatiallinesdataframe. I already ...
1
vote
0answers
58 views

over function in R not working [closed]

I am trying to find the number of pubs for each London LSOA. I do this with London's LSOA boundaries shapefile which I imported as a SpatialPolygonsDataFrame and a SpatialPointsDataFrame of pubs ...
0
votes
1answer
121 views

Rearrange plotorder of SpatialPolygonsDataframe

I have a SpatialPolygonDataframe (loaded with readOGR) I want to plot in either tmap or leaflet. A lot of the polygons are overlapping, and the smaller polygons are completely covered by larger ...
0
votes
1answer
113 views

Simplifying a SpatialPointsDataFrame in ggplot world

I've been working on a map showing lines running across Europe. Each line is coming from a GPX file, parsed in like so: spdf <- readOGR("data/file.gpx", layer = "track_points") Now, if I plot the ...
0
votes
1answer
181 views

Legend Key for discrete values in spplot

I have a shapefile with various attributes. I want to plot the shapefile using `spplot'. I first read the shapefile A <- readOGR('myshapefile.shp') I am using the following command: p <- ...
1
vote
1answer
53 views

spplot R and order of panels for Lattice plots

I have a shapefile with various attributes. I want to plot the shapefile using `spplot'. I first read the shapefile A <- readOGR('myshapefile.shp') I am using the following command: p <- ...
1
vote
0answers
32 views

Divide irregularly shaped polygon into 3 equal parts

I have a polygon object of a transect line that I would like to divide into 3 equal parts that are one-after-the-other along the transect line. So far I have only been able to slice the polygon ...
0
votes
2answers
168 views

Extracting non-spatial data from imported KML file using R?

I have a KML file which was created using Google's My Maps. The original file can be downloaded here: Google My Maps Using R, I can import this using the "readOGR" function of the rgdal library ...
0
votes
1answer
206 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
49 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
145 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
23 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
33 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
81 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
116 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
317 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
80 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
239 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
579 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
326 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 ...
4
votes
1answer
890 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
133 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
106 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
53 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
57 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
147 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
264 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
235 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
158 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
37 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
159 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
476 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
156 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....
4
votes
2answers
229 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 (...