47
votes
Accepted
Read a table from an ESRI file geodatabase (.gdb) using R
This can now be read by sf, with
vessel <- sf::st_read(dsn = "Zone9_2014_01.gdb", layer = "Zone9_2014_01_Vessel")
It returns a warning (no feature geometries present) but also a data.frame with ...
38
votes
Extracting intersection areas in R
Here's an alternate approach using the new sf package, which is meant to replace sp. Everything is much cleaner, and pipe friendly:
library(sf)
library(tidyverse)
# example data from raster package
...
27
votes
Reading feature class in file geodatabase using R?
As already posted in this answer, this now also works very nicely with sf:
require(sf)
fc <- sf::st_read("C:/path/to/your/filegeodatabase.gdb", layer = "some_featureclass")
But ...
20
votes
Accepted
Processing vector to raster faster with R
I tried to "parallelize" the function rasterize using the R package parallel in this way:
split the SpatialPolygonsDataFrame object in n parts
rasterize every part separately
merge all the parts into ...
17
votes
Accepted
Fast way to convert raster to polygon shapefile in R
Use the terra package instead of raster and use as.polygons to polygonize.
Sample data maker:
library(terra)
maker = function(x,y){rast(matrix(sample(1:18, x*y, TRUE), x, y))}
# same scale as yours:
...
15
votes
Accepted
Writing multiple layers to GeoPackage using writeOGR() in R?
You can do this using the append flag on sf::st_write():
library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
storms <- st_read(system.file("shape/storms_xyz.shp", package="...
11
votes
Accepted
Find maximum extent out of list of shapefiles (in projected coordinate system) in R
Given a list of shapey objects:
> shapes = list(cities, birds)
Compute the list of extents of those shapey objects
> shape_extents = lapply(shapes, raster::extent)
and then call raster::...
8
votes
Read only part of an ESRI shapefile into R
The only thing that comes to mind is to leverage the new "sfr" library and its associated simple feature class for the subsetting. The sfr library is currently available on GitHub and here is a ...
8
votes
Reading in a single polygon from a shapefile
Time to ditch the shapefile!
Here's a reproducible example using a combination of packages sf, gdalUtils and dplyr:
library(sf)
library(dplyr)
library(mapview)
library(gdalUtils)
## as an example we ...
8
votes
Accepted
Unable to install ‘sf’ R package on Ubuntu 16.04 LTS
This worked for me. Using
sudo aptitude install libgdal-dev
and then
devtools::install_github("r-spatial/sf")
7
votes
Checking if points fall within polygon Shapefile
I used a similar approach to the accepted answer in this post but was never really satisfied with it so I looked into alternatives and found the sf library.
And using this library you can then write ...
7
votes
R spatial: Erase one polygon from another: correct use of `st_difference`?
Your code worked just fine for me, so I think that make it throws that error because you have some topology error in your shape. I've just adapted your code adding a check and repair part in order to ...
6
votes
Accepted
How to read a feature class in an Esri Personal GeoDatabase using R?
EDIT: this answer is out of date, there is a 64-bit support for Access now, and rgdal is going to be defunct in a year or so.
You are on Windows so I will assume you are on a 64-bit machine, running ...
6
votes
Accepted
r - Setting custom projection in PROJ >=5 paradigm
You could template the WKT2 version i.e.
lon_0 <- 9
lat_0 <- 53
x_0 <- 4321000
y_0 <- 3210000
template <- "+proj=laea +lat_0={lat_0} +lon_0={lon_0} +x_0={x_0} +y_0={y_0} +datum=WGS84 +...
5
votes
Writeogr to PostgreSQL/PostGIS database with R
If this is still relevant, at the University of Florida, David Bucklin and I have released a rpostgis package that provides bi-directional transfer between PostGIS and R for vector and raster data. ...
5
votes
Read multiple layers of KML file using R
Farid Cheraghi's solution works well. Alternatively, you can use lapply from the apply family of functions (so named because it returns a list) instead of a for loop. If you don't care about saving ...
5
votes
Accepted
Calculating Proportion of Land Cover Classes with moving window around point in R?
For calculating proportions around points you can define a function in the raster::extract function.
First, create an example raster with values of [1,2] and generate a random point sample.
library(...
5
votes
Accepted
Set the minimum and maximum values for an elevation raster in R
Try the commented and reproducible example below. You can assign NA values to your elevation RasterLayer as elev[elev < 0] <- NA and elev[elev > 1200] <- NA.
# Load libraries
library('...
5
votes
Accepted
sp::proj4string equivalent in the PROJ6 framework?
I was also quite confused about the move away from PROJ Strings and what to use instead until I watched this video of a talk held last year at FOSS4G.
Here's my main takeaways:
Why PROJ and GDAL are ...
5
votes
Accepted
Checking whether CRS is geographic coordinate system or projected coordinate system using R
The raster package has a function isLonLat for this purpose.
Analogous for vector data, there is the st_is_longlat function from sf.
4
votes
Accepted
Raster IO error (R)
Don't trust the original raster file.
When I tried converting it on the command line, I got:
$ gdal_translate -co "COMPRESS=NONE" ./IOERROR.tif IOERRORgdal.tif
Input file size is 5607, 7271
0...10......
4
votes
R cannot read *.shp shapefile with rgdal
This bit:
a <- shapefile("C:/.../Desktop/ne_10m_urban_areas.shp")
Error: file.exists(extension(x, ".shx")) is not TRUE
tells us that there is no ne_10m_urban_areas.shx file - note the file ...
4
votes
Accepted
geom_line() does not plot points from a shapefile in its correct order
The issue is how you plot the lines.
From the geom_path/geom_line help page:
geom_path() connects the observations in the order in which they appear in the data. geom_line() connects them in order ...
4
votes
Accepted
Reading shapefile in R with shapefile function?
You are doing this:
d <- file("/Volumes/Environment_layers/original/WaterRoad/Road.shp")
which is calling file on the path. This opens the file for reading by R's general reading and writing ...
4
votes
Loading shapefiles for reprojection using sf
The problem here seems to be (and hard to be certain without more code or examples) that you have spatial data objects saved in multiple .RDA files and need to read them in a loop.
The struggle is ...
4
votes
Accepted
How to test whether the argument passed to an R function is a raster or a vector
I'm doing pretty much the same
if (is(X, "RasterLayer") | is(X, "SpatRaster") | is(X, "stars"))
{
# handle the different cases with specific code
# personnally I ...
3
votes
Accepted
GDAL installation problem: Linux server without sudo privileges
One option is to use the Anaconda package manager. You can use a user only, not root installation to your home directory (or wherever you have write access).
Install miniconda
Create a conda ...
3
votes
How to load postgis raster layers into R?
If this is still relevant, at the University of Florida, David Bucklin and I have released a rpostgis package that provides bi-directional transfer between PostGIS and R for vector and raster data. ...
3
votes
Importing several GeoTiff files into R?
This code will create a raster brick which needs all the rasters to be of the same extent. You could tweak it for creating a raster stack. I'm assuming your files in the working directory and are ...
3
votes
Rgdal add column to shapefile
OMG, I added a whole dataframe to my object. So in the end I have this:
library(rgdal)
foo <- readOGR(dsn="myfolder",layer="myshapefileWithoutEnding")
foo@data$MY_VALUE <- ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
rgdal × 217r × 198
raster × 61
sp × 35
shapefile × 29
gdal × 28
coordinate-system × 26
proj × 12
rgeos × 12
sf × 11
polygon × 10
postgis × 9
geotiff-tiff × 7
ggplot2 × 7
qgis × 6
kml × 5
ogr × 5
file-geodatabase × 5
latitude-longitude × 4
overlapping-features × 4
modis × 4
terra × 4
gdalutils × 4
postgresql × 3
geojson × 3