Comments (2)
from sfdep.
I was using the test points from PySal http://pysal.org/notebooks/explore/pointpats/centrography.html
library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.4.3, PROJ 7.2.1; sf_use_s2() is TRUE
library(sfdep)
library(tidyverse,warn.conflicts = F)
#points creation
points <- rbind(c(66.22, 32.54), c(22.52, 22.39), c(31.01, 81.21),
c(9.47, 31.02), c(30.78, 60.10), c(75.21, 58.93),
c(79.26, 7.68), c(8.23, 39.93), c(98.73, 77.17),
c(89.78, 42.53), c(65.19, 92.08), c(54.46, 8.48)) %>%
as.data.frame() %>% rename(x = V1, y = V2) %>% mutate(weights = seq(0,11,1))
# to sf
points_sf <- points %>% st_as_sf(coords = c('x','y'))
# Test center mean no W
mean_c <- center_mean(points_sf)
#plot results
plot(points_sf$geometry, axes = T)
plot(mean_c, col = 'red', add = T)
# Test center with W, default sfdep function
mean_cw <- center_mean(points_sf, weights = points_sf$weights)
#plot results
plot(points_sf$geometry, axes = T)
plot(mean_cw, col = 'blue', add = T) #result outside of bbox
## changing the line and possible solution
center_mean_ps <- function (geometry, weights = NULL) {
#geometry <- check_polygon(geometry) # removed just for this example
crs <- sf::st_crs(geometry)
coords <- sf::st_coordinates(geometry)
n <- nrow(coords)
if (!is.null(weights)) {
res <- colSums(coords * weights)/sum(weights, na.rm = T)
}
else {
res <- colSums(coords)/n
}
sf::st_sfc(sf::st_point(res), crs = crs)
}
#testing
mean_cw <- center_mean_ps(points_sf, weights = points_sf$weights)
#plot results
plot(points_sf$geometry, axes = T)
plot(mean_cw, col = 'blue', add = T) #result outside of bbox
## check both mean center
#plot results
plot(points_sf$geometry, axes = T)
plot(mean_c, col = 'red', add = T, pch = 13)
plot(mean_cw, col = 'blue', add = T,pch = 15) #result outside of bbox
Created on 2022-10-06 with reprex v2.0.2
from sfdep.
Related Issues (20)
- Check for matching observations and times in spacetime cube test
- convert stars to spacetime representation
- weights transformations to binary HOT 2
- significance on local moran HOT 1
- provide skater interface HOT 3
- Inefficient calculation of bivariate moran HOT 4
- feature request: getting nb object and wt vector from an sfnetworks object HOT 6
- graph based neighbors HOT 1
- Consider better fx prefixing
- Error in stopifnot() with local moran HOT 6
- activate() drops active attribute
- add kernel wiki to kernels add kernels to st_kernel_weights
- Estimation of local spatial autocorrelation statistics (local Moran's Ii and Getis-Ord's Gi/Gi*) using sfdep and tidyverse HOT 1
- complete_spacetime_cube breaks grouped data HOT 1
- inconsistent results between emerging_hotspot_analysis() and mannually calculating hotspots step-by-step HOT 8
- Negative and larger than 1 p-values with local_gstar_perm HOT 7
- Error with spacetime due to "." at start of of data labels HOT 3
- Consider utility function to provide summaries of multiple variables HOT 3
- Dealing with NA's on spacetime objects HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sfdep.