Questions tagged [sp]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
11 views

How to add labels to points in elevation plot in R?

I am a complete noob at using GIS in R and have been trying many packages and functions but get stuck each time. What I want is to generate an elevation map for a location in the Himalayas with ...
1
vote
0answers
17 views

Can poly2nb() or nb2listw() be made time-sensitive?

I was wondering if there is a way to make the poly2nb() or nb2listw() temporally sensitive. For example, let's say we have a spatialobject that tracks a set of polygons for 2019 and 2020. Some of the ...
1
vote
1answer
36 views

Calculating density within a shapefile (in R)

I'm trying to calculate density within a shapefile, but I'm fairly confident I'm doing it wrong. The idea is to figure out which geographical regions there have been the most sales by density. Here ...
1
vote
0answers
32 views

Replicated Point Pattern: Get Density Variance Between Replicated Patterns and Subtract from Composite

I have written a lengthy code that dissects differently shaped/sized windows into recognizable components (individual cells in the image), gets the point density within each cell, then builds a whole ...
1
vote
1answer
72 views

Weighted kernel density estimate mapping in R

I am trying to reproduce ArcGIS' kernel density in R. Specifically, I'd like to make a weighted kernel density map, like you see in Census OnTheMap (example). I am running into a lot of dead ends, ...
1
vote
1answer
21 views

spTransform cutting off part of ROI in stereographic projection

I'd like to have a map of land above 50N in the stereographic projection. I use the following code but as you can see, some land is cut out. proj<- "+proj=stere +lat_0=90 +lat_ts=71 +lon_0=0 ...
2
votes
1answer
90 views

calculate distance of points from centroid

I have a spatialpoints object, and a spatialpolygonsdataframe, composed of rectangular cells, and which the spatialpoints fall into. What I would like is to determine which polygon in the ...
1
vote
1answer
28 views

ggplot2lend for sf-objects

I wanted to make a simple plot of four sf-objects which don't contain much more than the sfc-column and some postal-code information. The sf-objects have the names level 1-4 and plz. What I would ...
0
votes
0answers
38 views

Creating a pattern with certain parameters [R, spatstat, spatial, sf]

Let's say I want to create a pattern, that is based on numerous other patterns with similar shaped areas. Other than an average of the point densities in the rectangles, is there other patterning ...
1
vote
0answers
75 views

Unknown proj4: how to create custom proj4 from wkt?

I have a shapefile with a .prj file I've never seen before. In fact, it seems that GDAL doesn't even know what it is (see below). Therefore, when I read it into R with raster::shapefile() the CRS isn'...
1
vote
0answers
9 views

DSpat::create.lines and spatstat::rlinegrid: Adding too many lines?

Does anybody know of an issue with either DSpat's create.lines or spatstat's rlinegrid? Whenever I use these functions on my Windows (owins), the output has far too many lines. For example, if I run ...
1
vote
1answer
28 views

Connecting spatiallines or SpatialPoints based on minimum distance using R

Does anybody know of a way to create a single polygon (that will eventually be converted to an Owin) from either a spatialpoints object or a spatiallines object? Here is an example of each: Here's ...
2
votes
1answer
27 views

Aligning Multiple Polygons (Based on centroid possibly) [Spatstat, sf, sp]

I'm trying to create a composite/average of multiple similarly shaped polygons. I think the first step is most likely to align them via the centroid of each polygon. Does anybody know of a tool to ...
1
vote
1answer
40 views

spplot doesn´t work - sppanel error

I have this code (below) for plotting some information in a map, but it doesn't work, in the map appear only the error "sppanel", why I solve that? library(GWmodel) library(RColorBrewer) data(...
1
vote
2answers
57 views

String column in QGIS shapefile that is read as a factor column in R

I have a shapefile that has 3 columns (ID_1, NAME_1 and Rainfall). The 2nd column contains the names of governorates (type of variable is string). I have used the sf package in R to read this ...
2
votes
1answer
52 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
39 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
30 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
34 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
149 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
74 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 ...
2
votes
1answer
92 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
55 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
34 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
2answers
51 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
115 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
61 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
37 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 ...
3
votes
1answer
97 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
31 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
132 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
22 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
82 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
90 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
87 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
604 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
48 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
26 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
182 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
102 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
8 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
40 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
131 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
78 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
134 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 ...
2
votes
1answer
93 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
2k 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
62 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
79 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, ...