Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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
Appearance settings

A Package For Weighted and Unweighted Spatial Centers

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

ryanzomorrodi/centr

Repository files navigation

CRAN statuscentr status badgeR-CMD-checkCodecov test coverage

A Package for Weighted and Unweighted Spatial Centers

Installation

# Install centr from CRANinstall.packages("centr")# Or the development version from GitHub:# install.packages("devtools")devtools::install_github("ryanzomorrodi/centr")

Usage

The main functions aremean_center andmedian_center. They weredesigned for calculation of population weighted centroids, but can beextended to other forms of analyses.

Mean center calculates the geographic average center. One can specifythe groups to calculate individual centers for groups and weights foreach individual point. It is analagous to theArcGIS Pro MeanCentertool.

library(centr)df<-data.frame(lon= c(20,50,30,80,10),lat= c(25,70,30,50,30),group1= c("a","b","a","b","a"),group2= c(1,1,1,1,2),wt= c(1,5,1,3,2))x<-sf::st_as_sf(df,coords= c("lon","lat"),crs=4326)mean_center(x,group= c("group1","group2"),weight="wt")#> Simple feature collection with 3 features and 2 fields#> Geometry type: POINT#> Dimension:     XY#> Bounding box:  xmin: 10 ymin: 27.58952 xmax: 65.92087 ymax: 63.32603#> Geodetic CRS:  WGS 84#> # A tibble: 3 × 3#> # Groups:   group1 [2]#>   group1 group2            geometry#> * <chr>   <dbl>         <POINT [°]>#> 1 a           1 (24.88607 27.58952)#> 2 a           2             (10 30)#> 3 b           1 (65.92087 63.32603)

Median center iteratively calculates the point that minimizes distanceto all features. One can specify the groups to calculate individualcenters for and weights for each individual point. It is analagous totheArcGIS Pro MedianCentertool.

median_center(x,group= c("group1","group2"),weight="wt")#> Simple feature collection with 3 features and 2 fields#> Geometry type: POINT#> Dimension:     XY#> Bounding box:  xmin: 10 ymin: 27.96116 xmax: 50 ymax: 70#> Geodetic CRS:  WGS 84#> # A tibble: 3 × 3#> # Groups:   group1 [2]#>   group1 group2            geometry#> * <chr>   <dbl>         <POINT [°]>#> 1 a           1 (25.63316 27.96116)#> 2 a           2             (10 30)#> 3 b           1             (50 70)

Summaries of other attributes can be calculated by passing the summaryexpressions to... just as indplyr::summarise().

mean_center(x,group= c("group1","group2"),weight="wt",total_weight= sum(wt))#> Simple feature collection with 3 features and 3 fields#> Geometry type: POINT#> Dimension:     XY#> Bounding box:  xmin: 10 ymin: 27.58952 xmax: 65.92087 ymax: 63.32603#> Geodetic CRS:  WGS 84#> # A tibble: 3 × 4#> # Groups:   group1 [2]#>   group1 group2            geometry total_weight#> * <chr>   <dbl>         <POINT [°]>        <dbl>#> 1 a           1 (24.88607 27.58952)            2#> 2 a           2             (10 30)            2#> 3 b           1 (65.92087 63.32603)            8

About

A Package For Weighted and Unweighted Spatial Centers

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp