Skip to content
Back to skills

R Spatial Vector

ASecurity

R vector spatial data with sf, sp, terra. Use for points, lines, polygons, and geometric operations.

  • 5 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 4, 2026
datago

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill r-spatial-vector --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of R Spatial Vector?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for R Spatial Vector
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-r-spatial-vector/badge)](https://www.skillsdirectory.com/skills/leolin990405-r-spatial-vector)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: r-spatial-vector
description: R vector spatial data with sf, sp, terra. Use for points, lines, polygons, and geometric operations.
---

# R Vector Spatial Data

Points, lines, and polygons.

## sf (Simple Features)

```r
library(sf)

# Read/write
shp <- st_read("file.shp")
geojson <- st_read("file.geojson")
st_write(shp, "output.gpkg")

# Create geometries
pt <- st_point(c(0, 0))
line <- st_linestring(matrix(c(0,0, 1,1, 2,0), ncol = 2, byrow = TRUE))
poly <- st_polygon(list(matrix(c(0,0, 1,0, 1,1, 0,1, 0,0), ncol = 2, byrow = TRUE)))

# Create sf object
df <- data.frame(id = 1:3, name = c("A", "B", "C"))
geom <- st_sfc(pt1, pt2, pt3, crs = 4326)
sf_obj <- st_sf(df, geometry = geom)

# CRS operations
st_crs(shp)
st_transform(shp, 4326)
st_set_crs(shp, 4326)

# Geometric operations
st_buffer(shp, dist = 100)
st_intersection(shp1, shp2)
st_union(shp)
st_difference(shp1, shp2)
st_centroid(shp)
st_area(shp)
st_length(lines)
st_distance(shp1, shp2)

# Spatial predicates
st_intersects(shp1, shp2)
st_contains(shp1, shp2)
st_within(shp1, shp2)
st_touches(shp1, shp2)

# Spatial joins
st_join(points, polygons)
st_filter(points, polygon)
```

## terra (Vectors)

```r
library(terra)

# Read/write
v <- vect("file.shp")
writeVector(v, "output.gpkg")

# Create
pts <- vect(cbind(x, y), crs = "EPSG:4326")

# Operations
buffer(v, width = 100)
intersect(v1, v2)
union(v1, v2)
aggregate(v, by = "field")
```

Files in this skill

  • SKILL.md1.4 KB
  • maptools/SKILL.md1 KB
  • rgdal/SKILL.md967 B
  • rgeos/SKILL.md1.2 KB
  • sf/SKILL.md2.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.