Questions tagged [sp]

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

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

Spliting a polyline object by line ID based on @data values

I am trying split a SpatialLinesDataFrame by attributes I merged into @data I extracted a list of line ID's associated with a points data frame and aggregated them by category and line ID in dplyr # ...
1
vote
1answer
29 views

Exracting data fromSpatialPolygonDataFrame conditionally in R?

For some research I am working on, I have a dataframe called charters of charter schools in New Jersey. Simplified it looks like this: school.name school.id district.id lat ...
1
vote
0answers
24 views

Speeding up spatial subsetting in R?

I need to subset a global fishing dataset to just have the fishing in the Pacific. Right now I have a shapefile of the Pacific and I am using the sp method of subsetting (see below) oceans <- ...
1
vote
1answer
15 views

Generating pattern in each of set of polygons using sp (r)?

I have an object of class SpatialPolygonsDataFrame, and for each polygon in the dataframe I have a number of points I would like to generate in that polygon (e.g. I have 130 polygons, and I have a ...
2
votes
1answer
67 views

R (spatstat, sp, sf): Grid a single polygon, divide, alphanumeric labels based on column/row

I am trying to take a polygon and add grid lines over top, then divide the polygon into many polygons based on the grids. I've accomplished this through st_make_grid() and raster::intersect(). The ...
1
vote
0answers
55 views

ggplot with island (“Alaska problem”)

The data for this example can be found here: https://github.com/davidbaniadam/maps The problem is essentially the same with Alaska and mainland USA, i.e. I want the size of Alaska to be correct in ...
1
vote
0answers
21 views

Spatial 1 to 1 join by proximity in sf and R?

I'm trying to join a Simple Feature of POINT geometry type to another Simple Feature of POLYGON geometry type using st_join and nngeo::st_nn as the person asking this other question also did. The ...
2
votes
0answers
37 views

Union anti-meridian “multipolygons” after re-centering world map

My goal is to create a world map (using ggplot2) with a Pacific perspective. I have managed to re-center the map, by following this solution. Code below: # world country layer sppolys <-...
1
vote
1answer
24 views

Get shortest/fastest path between two points from SpatialLines(DataFrame)

I have a large rivernetwork as a SpatialLines(DataFrame) and want to subset it so I get a SpatialLine with only the shortest/fastest path between two SpatialPoints(DataFrame) which propably need to be ...
1
vote
1answer
24 views

Adequate proj4string for ETRS89

I am currently working with spatial data in R using sp When I used WGS84-referenced coordinates, I used to specify it by setting the proj4string to: +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs +...
1
vote
1answer
23 views

Keep spatial lines intersecting spatial polygons using R?

I am trying to keep spatial Lines objects intersecting a spatial polygon in R. The intersect function from raster package is doing actually a crop. But what I need is to keep the lines intersecting a ...
1
vote
1answer
40 views

Remove polygons having less than 4 coordinates in R

I have a multiPolygon shapefile of buildings in a particular city. I read it in with readOGR and and transform it to my desired planar projection with the following code: buildings_data<-readOGR("...
0
votes
0answers
30 views

How to correct border between 2 polygons in R? [duplicate]

What algorithm to use to correct (average) the borderline between 2 polygons? All I know is that they have their own borderlines very close to each other. Sometimes they may overlap, otherwise not. ...
1
vote
0answers
55 views

Areas of imported features in Google Earth Engine

I originally wanted to ask the following question: "In the FeaturesCollection r_features, why do the two features have such different areas? They should have the same areas because they are both ...
2
votes
1answer
50 views

CRS validity and PROJ versions

I'm not sure where the right place to raise this is, so: The PROJ strings for EPSG codes 4151 and 4283 are identical: +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs which is a hassle ...
0
votes
1answer
25 views

Finding datasets embedded in R GISTools package?

How can I find the embedded datasets in R package GISTools? I can find examples of datasets (Georgia, Newhaven etc.), but I cannot see exactly which datasets are available.
0
votes
0answers
18 views

Error: trying to get slot “polygons” from an object (class “data.frame”) that is not an S4 object

I am trying to join .csv file data to shape file data using @data slot. I am getting error "trying to get slot "polygons" from an object (class "data.frame") that is not an S4 object " Here is my ...
0
votes
0answers
12 views

Copying polygons from lists of polygons to one SpatialPolygon list in R?

I do not know how to regroup polygons from SpatialPolygons list in the following manner: I have object rtu: > rtu class : SpatialPolygons features : 81 extent : 450685, 458760, ...
1
vote
0answers
36 views

Easy way to plot separate groups of SpatialPolygons in R

I have SpatialPolygons grouped by 81 polygons and in each there are some other Polygons I'd like to plot them group by group but have little trouble with it. > rtu_spl class : ...
0
votes
1answer
47 views

After I give kring command, this error comes up: data item in gstat object and newdata have different coordinate reference systems

> library(gstat) > library(readxl) > library(sp) > library(rgdal) #2013(FATALITIES) data <- read.csv("C:/Users/sbs/Desktop/Study/RA/Accident analysis/New folder/Iowa total crashes ...
1
vote
1answer
32 views

How to build polygons from buffered points and merge overlapping ones using R?

I have a sample of 3 groups of points which are similarly spread within their groups. > pts x y [1,] 453067.5 364073.5 [2,] 453066.5 364072.5 [3,] 453068.5 364072.5 [4,] ...
1
vote
1answer
113 views

sp::over vs sf::st_intersection in r

I was wondering why sf::st_intersection() takes too much time, in comparison with sp::over(); I use sf for pretty much all of my geospatial workflows (I was used to sp as well), and more and more ...
0
votes
1answer
27 views

How to create circular polygon and add it to shapefile as a layer?

I have such data of points which could be stored with their radii. cdf = rbind(matrix(c(100, 200, 10), ncol = 3), matrix(c(400, 300, 20), ncol = 3)) di = c("1", "2") spcs <- list() for (c in 1:...
0
votes
1answer
23 views

How to overcome missing of “sp::Point” to create points layer in shapefile?

I can produce Polygon layer from matrix in following way: pols <- lapply(cdf, Polygon) pls <- lapply(seq_along(pols), function(i) Polygons(list(pols[[i]]), ID = i)) sps <- ...
0
votes
1answer
39 views

Identify polygon grid in which the point belongs to?

I have a dataframe with 3 columns , which has my custom lat / long with a failure rate associated with each Lat / long head(df) Latitude Longitude Failure.rate 51.3 ...
0
votes
1answer
65 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
33 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
97 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
50 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
74 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
61 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
974 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
45 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
58 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
157 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
67 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
177 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
56 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
45 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
85 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
84 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 ...
1
vote
1answer
228 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
188 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
251 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
113 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
35 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
288 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 ...
1
vote
1answer
471 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 ...