Here's my hacky solution. First, decrease the number of points by 10 to find a near optimum then search from that number+9 decreasing by 1.
#loading packages
library(tidyverse)
library(rgdal)
#> Loading required package: sp
#> Please note that rgdal will be retired by the end of 2023,
#> plan transition to sf/stars/terra functions using GDAL and PROJ
#> at your earliest convenience.
#>
#> rgdal: version: 1.5-27, (SVN revision 1148)
#> Geospatial Data Abstraction Library extensions to R successfully loaded
#> Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
#> Path to GDAL shared files: C:/Program Files/R/R-4.1.2/library/rgdal/gdal
#> GDAL binary built with GEOS: TRUE
#> Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
#> Path to PROJ shared files: C:/Program Files/R/R-4.1.2/library/rgdal/proj
#> PROJ CDN enabled: FALSE
#> Linking to sp version:1.4-6
#> To mute warnings of possible GDAL/OSR exportToProj4() degradation,
#> use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
#> Overwritten PROJ_LIB was C:/Program Files/R/R-4.1.2/library/rgdal/proj
library(raster)
#>
#> Attaching package: 'raster'
#> The following object is masked from 'package:dplyr':
#>
#> select
library(geosphere)
# making a bounding box of the area of interest
boundbox <- as(raster::extent(174.00117, 174.01626, -39.39970, -39.39005), "SpatialPolygons")
# setting projection and datum
proj4string(boundbox) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
### Now I need points for the sampling plots....
## the area is **about**, 1,357,167 metres squered. - is is not exact as I only measured it from google earth by hand.
meetCrit <- FALSE
npts <- 670 # number of points
while (!meetCrit){
# generating a sample of regular points in the bounded area
nplots <- spsample(boundbox, n = npts, type ="regular")
# checking the distance between points
dist.matrix.2 <- dist.matrix <- distm(nplots, fun = distGeo) # generating a distance matrix-
diag(dist.matrix.2) <- NA
if (min(dist.matrix.2, na.rm=TRUE) >50){
meetCrit <- TRUE
break
} else{
npts <- npts-10 # step down by 10
}
}
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
# now we know the best is between npts and npts+9
npts
#> [1] 430
npts <- npts+9
meetCrit <- FALSE
while (!meetCrit){
# generating a sample of regular points in the bounded area
nplots <- spsample(boundbox, n = npts, type ="regular")
# checking the distance between points
dist.matrix.2 <- dist.matrix <- distm(nplots, fun = distGeo) # generating a distance matrix-
diag(dist.matrix.2) <- NA
if (min(dist.matrix.2, na.rm=TRUE) >50){
meetCrit <- TRUE
break
} else{
npts <- npts-1 # step down by 1
}
}
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> Warning in proj4string(obj): CRS object has comment, which is lost in output; in tests, see
#> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
npts
#> [1] 432
min(dist.matrix.2, na.rm=TRUE)
#> [1] 50.01003
Created on 2021-12-20 by the reprex package (v2.0.1)