Questions tagged [sp]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
38 views

Displaying arrow using spplot and sp.layout

I have been wrestling with an error (that I am clearly making) in trying to add an arrow on the bottom right of an otherwise functional sp plot. I am using sp.layout and a SpatialPolygonsDataFrame. ...
rratnaya's user avatar
0 votes
1 answer
60 views

Colouring wrld_simpl countries with a variable

This seemed at first rather easy but turned out to be impossible to solve. I want to plot the wrld_simpl map but coloring the countries with a color gradient that depends on a variable. The countries ...
Agus camacho's user avatar
0 votes
1 answer
254 views

Error using "if" in R: "== : missing value where TRUE/FALSE needed" for spTransform

I am trying to make the projection of a set of coordinates identical to a shape from wrld_simpl. But I keep getting the error below. How to solve that? d=read.csv() it= wrld_simpl[wrld_simpl$NAME == &...
Agus camacho's user avatar
0 votes
0 answers
40 views

Clip a SpatialGrid using a SpatialPolygon

In order to perform kriging methods using automap::autoKrige I need to provide a SpatialGrid for which values can be predicted. I would like to reduce the rectangular grid to the actual area (in this ...
M.Teich's user avatar
  • 115
2 votes
1 answer
88 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 ...
Ryan's user avatar
  • 123
1 vote
0 answers
55 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 ...
MiriamSeely's user avatar
1 vote
3 answers
87 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 ...
Non_Praying_Mantis's user avatar
1 vote
1 answer
561 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" ...
Non_Praying_Mantis's user avatar
1 vote
0 answers
265 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) ...
Giuseppe Petri's user avatar
0 votes
1 answer
882 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 ...
Mark Thompson's user avatar
0 votes
0 answers
89 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 ...
user8229029's user avatar
3 votes
0 answers
738 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 ...
bill999's user avatar
  • 125
1 vote
1 answer
581 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(&...
Non_Praying_Mantis's user avatar
1 vote
1 answer
297 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 ...
bill999's user avatar
  • 125
1 vote
1 answer
488 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 ...
bill999's user avatar
  • 125
1 vote
1 answer
340 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 ...
ma991ng's user avatar
  • 113
1 vote
1 answer
422 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 ...
Maria Eugenia D'Amato's user avatar
0 votes
1 answer
907 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 ...
derelict's user avatar
  • 1,425
0 votes
1 answer
177 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 ...
ccc's user avatar
  • 1
0 votes
1 answer
2k 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 ...
user303287's user avatar
0 votes
2 answers
3k 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: # ...
user303287's user avatar
0 votes
1 answer
420 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....
s_o_c_account's user avatar
0 votes
1 answer
162 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 ...
Ric's user avatar
  • 1
0 votes
1 answer
467 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-...
AFH's user avatar
  • 155
0 votes
1 answer
204 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 ...
Faustin Gashakamba's user avatar
0 votes
1 answer
47 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. ...
Uyen Bui's user avatar
1 vote
1 answer
225 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 ...
Jouline's user avatar
  • 63
0 votes
1 answer
453 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 :...
Jouline's user avatar
  • 63
0 votes
0 answers
579 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 ...
Aparna Howlader's user avatar
0 votes
0 answers
225 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 ...
Abdul's user avatar
  • 211
1 vote
1 answer
73 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. ...
nerdsconsider's user avatar
3 votes
1 answer
192 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 ...
Abdul's user avatar
  • 211
1 vote
1 answer
255 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 ...
noob_researcher's user avatar
3 votes
1 answer
572 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 ...
Faustin Gashakamba's user avatar
0 votes
1 answer
669 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 ...
noob_researcher's user avatar
2 votes
1 answer
499 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 ...
Faustin Gashakamba's user avatar
0 votes
1 answer
637 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 ...
Guy Pincus's user avatar
1 vote
0 answers
693 views

R Error in sp::CRS(SRS_string = "4326") : no arguments in initialization list [closed]

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(...
Robert Hickman's user avatar
1 vote
1 answer
4k 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(...
user8160648's user avatar
1 vote
1 answer
3k 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 ...
John Huang's user avatar
1 vote
2 answers
903 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 ...
geoscience123's user avatar
1 vote
2 answers
637 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 ...
seak23's user avatar
  • 181
1 vote
0 answers
416 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 ...
Matt's user avatar
  • 11
1 vote
1 answer
1k 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", ...
Courtney's user avatar
1 vote
1 answer
712 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 ...
Michael Smith's user avatar
0 votes
1 answer
669 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 ...
Tariq Abbas's user avatar
1 vote
2 answers
1k 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 : ...
mand3rd's user avatar
  • 161
0 votes
2 answers
94 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 ...
Michael Smith's user avatar
4 votes
1 answer
278 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 ...
ASeaton's user avatar
  • 164
5 votes
1 answer
99 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 ...
Dave-Evans's user avatar

1
2 3 4 5
7