library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
set.seed(15)
X=7.5
Y=7.5
f = function(){
a = runif(10,1,10)
return( a=as.integer(a))
}
onlineloc=data.frame(x=f(),y=f())
store=data.frame(X,Y)
plot(onlineloc,main="Online and instore customer loc",col=" red")
points(X,Y,pch=15)
p = st_sfc(st_point(c(7.5,7.5)))
q=st_sfc(onlineloc)
#> Error in vapply(lst, class, rep(NA_character_, 3)): values must be length 3,
#> but FUN(X[[1]]) result is length 1
st_distance(p, q )
#> Error in UseMethod("st_geometry"): no applicable method for 'st_geometry' applied to an object of class "function"
st_distance(q, p, by_element = TRUE)
#> Error in UseMethod("st_geometry"): no applicable method for 'st_geometry' applied to an object of class "function"
Created on 2019-09-12 by the reprex package (v0.3.0)
why it is occuring
Yeah, sf is a bit fiddly and confusing. What are you trying to do? To convert onlineloc to sf you need to convert it to a matrix, and then perhaps a multipoint? (depends what you are trying to do)
q = st_sfc(st_multipoint(as.matrix(onlineloc)))
This will only give you the first distance since p is only a single point.
I think sf is designed to work with dataframes. sf dataframes have a geom column which gives the spatial geometry of each item.
yes i want to find distance of 10 points (in online loc) from single reference point (store) for that i guess i have to convert it in sf object, how i can get the distance of all 10 points from single reference point please help