问题描述
我有一组大约5000个地理(WGS84)坐标。它们全都在40 km的正方形内。
I have a set of about 5000 geographical (WGS84) coordinates. All of them are inside 40km square.
是否有任何算法/ R函数可以在正方形内而不在给定集合内查找点,而该点距集合内的任何点都最远?
Is there any algorithm / R function to find point, inside square and not in the given set, farthest from any point from set?
我的意思是如何在正方形中找到距集合最近点的距离最长的点?
I mean how to find point in the square where the distance to the nearest point from set is longest?
现在,我通过生成等距分布的坐标网格并找到从每个网格点到最近的设定点的距离来做到这一点。有没有更少的数值/非蛮力方法?
Now I do it by generating grid of coordinates equally spaced and finding distance from each grid point to the nearest set point. Is there any less numerical / not brute force method?
编辑:
我在先前版本的问题中犯了错误。也许这会有所帮助:
I made mistake in previous version of the question. Maybe this will help:
点集是城市中5000家商店的坐标。我想在距最近商店的距离最长的城市中找到一个地方。
Set of points are coordinates of the 5000 shops in the city. I want to find place in the city where distance to the nearest shop is the longest.
推荐答案
下面是一个使用多个功能的示例( distanceFromPoints()
, maxValue()
,哪个()
,以及 raster
包中的 xyFromCell()
)来执行关键计算:
Here's an example that uses several functions (distanceFromPoints()
, maxValue()
, Which()
, and xyFromCell()
) from the raster
package to perform the key calculations:
# Load required libraries
library(sp)
library(rgdal)
library(raster)
# Create a SpatialPoints object with 10 points randomly sampled from
# the area lying between longitudes 0 and 1 and latitudes 0 and 1
bbox <- matrix(c(0,0,1,1), ncol=2, dimnames = list(NULL, c("min", "max")))
PRJ4 <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84")
S <- Spatial(bbox = bbox, proj4string = PRJ4)
SP <- spsample(S, 10, type="random")
# Create a raster object covering the same area
R <- raster(extent(bbox), nrow=100, ncol=100, crs=PRJ4)
# Find the coordinates of the cell that is farthest from all of the points
D <- distanceFromPoints(object = R, xy = SP)
IDmaxD <- Which(D == maxValue(D), cells=TRUE)
(XY <- xyFromCell(D, IDmaxD))
# x y
# [1,] 0.005 0.795
# Plot the results
plot(D, main = "Distance map, with most distant cell in red")
points(SP)
points(XY, col="red", pch=16, cex=2)
这篇关于如何找到与坐标集相关的点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!