Questions tagged [sp]
R package with classes and methods to create and manipulate spatial data
304
questions
2
votes
1
answer
32
views
Specifying ggplot2 aesthetics for factors stored in SpatialLinesDataFrame
I produced a set of 2 contour lines for 6 different individuals. The contours for each individual were originally stored in a single list which contained 6 separate SpatialLinesDataFrames (one per ...
1
vote
0
answers
21
views
When I add a custom R Script Tool to my ModelBuilder, it gives me this error message
I have been trying to add an R Script Tool to my model in Model Builder within ArcGIS Pro--the tool, called Tree Detection, works well when I run it on its own, but every time I try to run it as part ...
1
vote
3
answers
61
views
Intersecting objects and converting it to simple features so I can use 'raster', R
This question is connected to: How to create a regular, square grid, and find centroid by factors using R
I have a data frame which have three columns: (1) the "scientificName" column ...
1
vote
1
answer
189
views
How to create a regular, square grid, and find centroid by factors using R
I want to create a regular, square grid of .5x.5 degree around my sampling points and find latlong centroid by factors.
I have a data frame which have three columns: (1) the "scientificName" ...
1
vote
0
answers
90
views
Combine a polygon map on top of a raster map in R
I would like to combine a shapefile map of some US states on top of a raster map obtained from using library ggmap.
This is the code I have
library(USAboundaries)
library(ggmap)
library(ggplot2)
...
0
votes
1
answer
268
views
Creating hexagons around polygon using sf
I create hexagons within a polygon perimeter using either the sp package or the newer sf package. Page 134 6.4 of Bivand et al.'s (2008) "Applied Spatial Data Analysis with R" gives an ...
0
votes
0
answers
51
views
How to intersect shapefile with polygons in R properly?
I have a WI shapefile (https://data-wi-dnr.opendata.arcgis.com/datasets/wi-dnr::wisconsin-state-boundary-24k/explore?location=44.747223%2C-89.836300%2C8.20) and a grid that I want to intersect so that ...
3
votes
0
answers
331
views
How to compute weighted mean centroid of lat+lon points taking into account spheroid
I have a bunch of points (lat+lon coordinates). Each one has a weight. I would like to get a weighted mean centroid of the points, taking into account the spheroid (as my points are scattered across ...
1
vote
1
answer
353
views
Extracting variables from grid cells using R
I am trying to extract bioclimatic variables from individual grid cells. So i started loading my shapefile:
# I used the Admin 0 - Countries (1:10) dataset from Natural Earth
shp <- sf::st_read(&...
1
vote
1
answer
190
views
Why do dist2Line and st_nn give slightly different distances?
I have some points and am finding the distance to the nearest state border. My question is: why do dist2Line and st_nn give slightly different answers for the distances?
The code below is based on ...
1
vote
1
answer
252
views
How to associate point to nearest state boundary outside of the state the point is in
I have a point within a state and I want to find 1) the distance to the nearest state border and 2) the bordering state's name. I am able to do 1). For 2). I am able to get the state name ...
1
vote
1
answer
143
views
Append more variables to a SpatialPolygonsDataFrame using R
I would like to generate a SpatialPolygonsDataFrame that I can use to plot a cartogram whose polygons are proportional to a variable.
A clear example is how FiveThirtyEight created a hex cartogram ...
1
vote
1
answer
219
views
Create a grid for more than one country in R
Some time ago I posted my own answer to create a grid inside a country to be used in kriging interpolation:
0........0.kriging error messages, grid file problem ? (automap, gstat)
This grid was for ...
0
votes
1
answer
255
views
Identify overlapping polygons within a single MULTIPOLYGON
I have a multipolygon shapefile that contains thousands of records with a spatial and temporal component.
I'd like to be able to identify records that overlap (the amount of overlap doesn't really ...
0
votes
1
answer
127
views
Getting polygon coordinates for areas outside known polygons using R
I have downloaded shapefile containing polygons for urban areas. However, I am interested in polygons representing rural areas. Therefore I would like to convert the shapefile containing urban areas ...
0
votes
1
answer
926
views
Adding attribute to SpatialPolygonsDataFrame in R
I have a SpatialPolygonsDataFrame with 14 different polygons. Each polygon currently has an attribute column "id", which is a single string that identifies the original colony, year, and ...
0
votes
2
answers
1k
views
Clipping dataframe (spatial data) to area of interest using R
I have Global Fishing Watch data for the whole world in a dataframe with columns being Lon, Lat, fishing_hours, gear type.
How do I crop the data to my area of interest?
I have tried the following:
# ...
0
votes
1
answer
191
views
Ordinary Kriging: "Warning message: In fit.variogram(data.var, vgm("Mat")) : No convergence after 200 iterations: try different initial values?"
I am trying to fit a variogram for kriging using the sp and gstat packages in r, but when I fit the variogram using a mattern fit, I get this warning message:
Warning message:
In fit.variogram(data....
0
votes
1
answer
107
views
Error message with Krige function: Error in as.character.default(X[[i]], ...) : no method for coercing this S4 class to a vector
I am trying to run the Krige function but I keep receiving NA values for var1.pred and var1.var. After using the warning() command, it says: Error in as.character.default(X[[i]], ...) :
no method for ...
0
votes
1
answer
207
views
Coloring polygons (made with concaveman) in ggplot by column
I'm adapting code for a map made by someone else that uses a package concaveman to generate concave hulls from points. The goal is to plot a number of different polygons in the oceans, and to color-...
0
votes
1
answer
109
views
My R package doesn't use `raster` or `sp` but these seem to be loaded when I roxygenize it
I have refactored my package to remove any trace of raster to replace it with the newer, faster terra package. Here is the list of functions and packages I now import as listed in my package's ...
0
votes
1
answer
45
views
NA outcome when running over() between a SpatialPoints and SpatialPolygonsDataFrame
I am having a problem when over() doesn't give a value but keep giving meNA for every field in the outcome data.frame. The aim is to have the counts of tardigrade occurrences in each biogeoregion.
...
1
vote
1
answer
172
views
Replacing single location by mean of duplicate locations using R
I would like to apply kriging with a set of heavy metals Belgian data.
But I have a duplicate location :
length(clean.donnees.Ni@coords)
[1] 5740
length(unique(clean.donnees.Ni@coords))
[1] 5186
As ...
0
votes
1
answer
300
views
krige() function with SpatialPointsDataFrame in R
I would like to make some kriging in a belgian territory.
I got a data set called clean.donnees.Ni after removing outliers and NAvalues.
I first tried simply with this, but got this warning as result :...
0
votes
0
answers
419
views
Extracting Nightlights data using R
I am working with Bangladesh data and want to create an annual Nightlights index for all sub-districts. I am using R package named "nightlights". I used this following code, and get a CSV ...
0
votes
0
answers
147
views
Creating data.frame reprsenting grid points of all pairs of coordinates and corresponding Z to each paid of coordinates
I have a inter.spt dataframe representing rainfall station's coordinates and elevation. I want to create a new data.frame containing a grid of all pairs of coordinates with corresponding Z of each ...
1
vote
1
answer
61
views
LAS catalog not loading - Error in sp::SpatialPolygons
I am getting this error that I have never received before. I have tried loading data in the catalog format with multiple LiDAR files including the Megaplot.laz data built into the lidR package.
...
3
votes
1
answer
128
views
How can I extract cell numbers/dimensions from cell size and extent?
I need to rasterize a SpatialPolygonsDataFrame object. I have a cell size of 100m for my analysis and the raster extent is extracted from the Polygon. But, the problem is that I cannot set a ncol and ...
1
vote
1
answer
155
views
Quantile of a polygon over a raster stack in R
I'm working with RasterStack of 300 simulations sims_trend. and I also have a SpatialPolygonsDataFrame limits. I'm trying to calculate quantiles for each polygon through the raster stack.
I know that ...
1
vote
1
answer
259
views
How to test whether the argument passed to an R function is a raster or a vector
I am writing a function that expects two arguments: X and Y. Argument X should be a raster which can be generated by packages such as raster, terra, or stars.
Argument Y should be a polygon from ...
0
votes
1
answer
400
views
Calculate raster mean within polygon limit using R [duplicate]
I have a rasterlayer MeanMap and I would like to do some calculations of the raster values contained within a determinate polygon fregs. How can I calculate the mean and the median of the raster for ...
2
votes
1
answer
312
views
Checking whether CRS is geographic coordinate system or projected coordinate system using R
I am writing a generic script that would calculate areas covered by different classes in a categorical raster in R.
I would like to provide two functions; one for use when the CRS of the raster is ...
0
votes
1
answer
414
views
Merging two spatial datasets based on both geometry intersection and year (try to create cell-year panel data, so basically 2 conditions) in R
I am trying to merge two datasets, both have geometry column (1st with polygons-cells and 2nd with points). Where i want the 2nd dataset (with the points) to be merged to the 1st dataset (with ...
2
votes
0
answers
605
views
R Error in sp::CRS(SRS_string = "4326") : no arguments in initialization list
When trying to use the get_elev_raster from the elevatr package, I am running into an error which seems a few libraries deep. As a basic reprex:
library(sf)
library(elevatr)
luxembourg <- readRDS(...
0
votes
1
answer
3k
views
Raster subset error in R: "Error: object of type 'S4' is not subsettable"
I am running this code in R:
country_template <- raster()
dimensions <- extent(124000, 463000, 2953600, 3127600)
country_template <- setExtent(country_template, dimensions)
res(...
1
vote
1
answer
2k
views
Creating raster stack from two raster layers
I have two raster layers that I would like to create a raster stack from. They are currently in different extents. One is a DEM layer and the other is a raster of an individual's home range. This is ...
1
vote
2
answers
664
views
R raster package unable to properly convert sp or sf feature to raster
I had previous functioning R code that took an interpolated dataset of class sf, and turned it into a raster. I then preformed an average of raster values over specific overlayed polygons. It seems ...
1
vote
2
answers
474
views
Preserving IDs when using gCentroid to find centroids of multiple polygons in R
This seems like it should be simple. I have multiple polygons contained in one shapefile, and I am using the gCentroid() function from rgeos to create a bunch of centroid points. The function has an ...
1
vote
0
answers
224
views
Getting a rasterized object from irregular lat and long data
I have a dataframe (I've named it ozone2raster) with latitude and longitude points, and values for ozone concentration that I want to use for making a rasterized map. The dimensions of this dataframe ...
1
vote
1
answer
711
views
Error in writeOGR when trying to export spatial polygons as shapefile in R
I am trying to export polygons that i have created for home range data but when i go to export them get this error message:
Error in writeOGR(colkud95[1, ], ".", "colonyhomerange", ...
1
vote
1
answer
509
views
Converting a SpatialPointsDataFrame into km units from m, in R
I read in a UTM shapefile to R using readOGR. I want to use the resulting SpatialPointsDataFrame to build a mesh in the INLA package, but I've been told that to help with numerical stability, I should ...
0
votes
1
answer
480
views
Determining off to add scale bar and north arrow in spplot
I have a spplot in which I want to add north arrow and scale bar.
bbox(dis) # dis is my shapefile, an sp object
min max
x -285706.6 1492871
y 2620690.6 4120742
I want to attach the ...
1
vote
2
answers
774
views
Change projection of list of rasters in R
I am handed down some RData that contain a list of of raster stacks. The file structure is pretty challenging to manipulate. After doing load(), the data looks like this:
[[1]]
class : ...
0
votes
2
answers
73
views
Trying to apply inlabru:::bru_fill_missing to a SpatialPointsDataFrame to fill in NAs
I'm struggling with a function from the inlabru R package, which could help me fill in the NAs in my data.
According to the helpfile, I need:
bru_fill_missing(
data,
where,
values)
data is a ...
4
votes
1
answer
197
views
Fixing polygon with incorrectly defined hole in R
I've been given this polygon as a SpatialPolygons object from the sp package.
It looks like there is a problem with how this was created, there is an unwanted line connecting the hole to the outer ...
5
votes
1
answer
86
views
Unexpected buffer output
Using both R and QGIS I got unexpected output from the buffer function. I'm wondering if it has something to do with my coordinate reference system, USA Contiguous Albers Equal Area Conic, because the ...
0
votes
1
answer
129
views
R packge sp to sf QGIS 3.14
I have several scripts written in R language with package "sp" for Qgis. However I am stuck in the old versions (2.18) because whenever I use this same package in current versions 3.14 the ...
1
vote
1
answer
67
views
Stats for forest cover change over 10 years in R
I am rather new to GIS and I don't know how to perform the following operation: [ R programming language]
I am developing a project evaluating forest cover change over 10 years (2010-2020) for a ...
0
votes
2
answers
256
views
Raster extent based on SpatialPolygonsDataFrame generating incorrect extent
I'm trying to rasterize data from Berlin's average price per parcel data. I've downloaded the shapefile from their data portal using an API with a function that generates an sf object, and then ...
0
votes
1
answer
416
views
Plot points in spastat ppp object
I am new to spatstat package and I am trying to make a point patten map with a shape file and some case points. I was able to plot the shape file plot but I just don't know how to make the points on ...