Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

📦 distanceto is an R package to calculate distances from point locations to features

License

NotificationsYou must be signed in to change notification settings

robitalec/distance-to

Repository files navigation

Lifecycle: stableR-CMD-checkCRAN status

distance-to

Overview

Thedistanceto package is designed to quickly sample distances frompoints features to other vector layers. Normally the approach forcalculating distance to (something) involves generating distancesurfaces using raster based approaches eg.raster::distance orgdal_proximity and subsequently point sampling these surfaces. Sinceraster based approaches are a costly method that frequently leads tomemory issues or long and slow run times with high resolution data orlarge study sites, we have opted to compute these distances using vectorbased approaches. As a helper, there’s a decidedly low-res raster basedapproach for visually inspecting your region’s distance surface. But theworkhorse isdistance_to. See theExample.

Install

install.packages('distanceto',repos='https://robitalec.r-universe.dev')

Example

library(distanceto)library(sf)
## Linking to GEOS 3.11.2, GDAL 3.7.0, PROJ 9.2.0; sf_use_s2() is TRUE
# Load nc datanc<- st_read(system.file("shape/nc.shp",package="sf"))
## Reading layer `nc' from data source ##   `/home/alecr/R/x86_64-pc-linux-gnu-library/4.3/sf/shape/nc.shp' ##   using driver `ESRI Shapefile'## Simple feature collection with 100 features and 14 fields## Geometry type: MULTIPOLYGON## Dimension:     XY## Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965## Geodetic CRS:  NAD27
# Set number of sampling pointsnpts<-1e3# Sample points in ncncpts<- st_sample(nc,npts)# Select first 5 of ncncsub<-nc[1:5,]# Measure distance from ncpts to first 5 of ncdists<- distance_to(ncpts,ncsub,measure='geodesic')head(dists,30)
##  [1] 237543.35 217923.10  91920.82 225703.62  63642.69 141852.37 178301.66##  [8]  88882.68  20298.52      0.00 100173.24 149001.91  68735.30  11992.49## [15] 151591.39 162214.72  67969.38 227235.50  49860.75  42067.82  50899.94## [22]  69211.60 111186.57  35096.09  95508.78 105467.67  31168.95 209061.13## [29]  48339.16  25743.09
# Add to ncptsncpts$dist<-dists

Other approaches

  • nngeo::st_nn
  • gdal_proximity
  • raster::distance
  • GUI GIS applications

[8]ページ先頭

©2009-2025 Movatter.jp