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

1
vote
1answer
23 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
118 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
38 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
24 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
42 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
43 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
32 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
18 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
37 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
33 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
37 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
50 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
76 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
79 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
127 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
32 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
31 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
112 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
98 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
44 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
101 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
21 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
29 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
69 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
92 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
271 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
63 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
195 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
367 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
236 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 ...
3
votes
1answer
647 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
109 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
79 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
43 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
54 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 ...
1
vote
0answers
112 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
241 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
182 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
0answers
27 views

Select one point in each polygon from spatialpolygonsdataframe and get the attributes from it to create a table with the coordinates

I have a spatialpolygonsdataframe with 3 attributes. I want to select one point in each polygon and get the attributes from it in order to create a table with the coordinates of the point, and the ...
0
votes
1answer
142 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") ...
0
votes
0answers
229 views

How do I count the number of intersections within one SpatialLines object?

I have one SpatialLines object where I would like to find and count the total number of intersections between linear features. I have tried using gIntersects() to determine whether lines have points ...
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
136 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
418 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
148 views

r-Mapview non reponsive with large simple feature dataframe

Im 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
199 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 (...
1
vote
1answer
896 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
100 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 ...
3
votes
2answers
2k 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 ...
10
votes
1answer
3k 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 (...