Questions tagged [sp]
R package with classes and methods to create and manipulate spatial data
289
questions
0
votes
2
answers
32
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
24
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
0
answers
10
views
Raster intersect is duplicating polygons
I am using a raster intersect to intersect two spatialpolygonsdataframes. One is a moose home range and the other is a SPDF containing wetlands. However, when I intersect them, the total number of ...
0
votes
1
answer
20
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
22
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
26
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
44
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
79
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
70
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
116
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
23
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
41
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
56
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
45
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
76
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
86
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
75
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
209
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
312
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
1k
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
304
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
152
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
171
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
47
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
344
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
110
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
188
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
303
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
48
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
93
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
68
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
67
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
37
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
97
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
74
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 ...
2
votes
4
answers
468
views
Creating smallest-circle covering polygon using R with sf
How can I create the smallest-possible circle which covers a polygon geometry using the sf (preferred) or sp packages in R?
One reprex using GADM data:
# Load packages
library(sf)
# Load Nigeria ...
6
votes
1
answer
2k
views
r sp::CRS() returns NA
I just updated R (from 4.0.2 to 4.0.3) and all my R packages (previously updated about a month ago), and got an error in a previously working workflow on raster objects. It seems that it comes from ...
0
votes
1
answer
74
views
Applying function to each element of SpatialLinesDataFrame
How do I apply functions to each element of a SpatialLinesDataFrame, in particular using other data also stored as an attribute (e.g. coordinates or elevation per line vertex)?
I've a number of ...
1
vote
2
answers
268
views
Navigating an Object of class 'SpatialPolygonsDataFrame' to filter on Polygon Area
I have an Object of class 'SpatialPolygonsDataFrame' with the structure shown below.
What's the secret to getting to the @area slot? Ultimately, I'm trying to filter this file so that I'm only left ...
0
votes
0
answers
38
views
Some polygons failing to fill with color
I have several Spatial Polygon Data Frames I am adding successively to a plot in R 4.0.2. The polygons represent US States, National Forests, National Parks, and wildfire perimeters. While it probably ...
1
vote
1
answer
1k
views
Finding overlapping polygons of two Spatial Polygon Data Frames using R
I am new to GIS and GIS in R. I have two Spatial Polygon Data Frames (spdf), one contains the marine ecoregions of the world (MEOW), the other one contains Exclusive Economic Zones (EEZ) of the world. ...
1
vote
1
answer
49
views
Locating SpatialPoints on SpatialPixels using R
I have met this frustrating problem while using R doing some GIS operation.
The problem is, I want to locate some spatial points (SpatialPointsDataFrame) on geographical grids (SpatialPixelsDataFrame)....
3
votes
1
answer
297
views
Save Spatial Pixel Data Frame
I have met a small yet puzzling problem about saving and reading Spatial Pixel Data Frame.
I created a raster with over 10 million grids (resolution = 25000).
adm0 <- readOGR(dsn = path.expand(&...
1
vote
1
answer
24
views
Use mapview in function to open viewer, but also do other things afterwards
The question may sound a little strange, but what I want to do is the following:
library(sp)
library(sf)
data(meuse)
meuse = st_as_sf(meuse, coords = c("x", "y"))
plotit = ...
0
votes
1
answer
1k
views
Problems with specifiying TM_fill when creating a map in R with TM_maps
For my research I am visualizing plastic contents in segments of water.
After creating my segment (online, polygons in KML-file) I jointed it with my table with fieldworkdata with plastics per segment....
3
votes
1
answer
520
views
Combining two shapefiles using common attribute
I have two shapefiles "sf1" and "sf2" for same area.
"sf1" is population data for year 2015 and has 6 variables.
"sf2" is population data for year 2010 and ...
2
votes
1
answer
255
views
Reproject using WKT for just the horizontal CRS
I'm trying to reproject LiDAR point clouds from California zone 2 (ftUS) using spTransform from sp R package to a metric CRS like EPSG 3857 (initial post here) and got non finite transformation ...
1
vote
2
answers
256
views
"non finite transformation detected" using sp R
This is a part of a broader question already posted (Non finite transformation detected - lidR spTransform) but I am creating a new question for the sp related part of that.
I'm trying to reproject ...
1
vote
1
answer
382
views
Non finite transformation detected - lidR spTransform
I would like to re project the following laz file using lidR and spTransform from sp.
The EPSG code is not defined but it seems to me that the CRS string is complete:
tmp_laz <- readLAS("./...
0
votes
0
answers
39
views
Are these sp files equal in terms of proj4string? Can I do some transformation of the proj4string?
summary(SCat_sp_E6)
Object of class SpatialPolygonsDataFrame
Coordinates:
min max
x -74.095072 -74.018988
y 4.647323 4.832934
Is projected: FALSE
proj4string :
[+proj=longlat +...