Skip to content

Commit

Permalink
permit GDAL < 3.7.0 by unzipping zipped gpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
rsbivand committed Sep 10, 2024
1 parent 304df1b commit 28983fb
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 77 deletions.
13 changes: 10 additions & 3 deletions man/bhicv.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@
%%\format{}
%%\details{}
\examples{
if (as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0") {
bh <- st_read(system.file("etc/shapes/bhicv.gpkg.zip",
package="spdep")[1])
(GDAL37 <- as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0")
file <- "etc/shapes/bhicv.gpkg.zip"
zipfile <- system.file(file, package="spdep")
if (GDAL37) {
bh <- st_read(zipfile)
} else {
td <- tempdir()
bn <- sub(".zip", "", basename(file))
target <- unzip(zipfile, files=bn, exdir=td)
bh <- st_read(target)
}
}
\keyword{data}% at least one, from doc/KEYWORDS
16 changes: 12 additions & 4 deletions man/mstree.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ mstree(nbw, ini = NULL)
%%\seealso{ ~~objects to See Also as \code{\link{help}}, ~~~ }
\examples{
### loading data
if (as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0") {
bh <- st_read(system.file("etc/shapes/bhicv.gpkg.zip",
package="spdep")[1], quiet=TRUE)
(GDAL37 <- as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0")
file <- "etc/shapes/bhicv.gpkg.zip"
zipfile <- system.file(file, package="spdep")
if (GDAL37) {
bh <- st_read(zipfile)
} else {
td <- tempdir()
bn <- sub(".zip", "", basename(file))
target <- unzip(zipfile, files=bn, exdir=td)
bh <- st_read(target)
}
### data padronized
dpad <- data.frame(scale(as.data.frame(bh)[,5:8]))

Expand All @@ -70,7 +78,7 @@ par(mar=c(0,0,0,0))
plot(st_geometry(bh), border=gray(.5))
plot(mst.bh, st_coordinates(st_centroid(bh)), col=2,
cex.lab=.6, cex.circles=0.035, fg="blue", add=TRUE)
}

}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
Expand Down
15 changes: 12 additions & 3 deletions man/read.gwt2nb.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,17 @@ nc1ia <- read.swmdbf2listw(fn, region.id=as.character(nc_sf$UniqueID),
style="B", zero.policy=TRUE)
nc1ia
all.equal(nc1i, nc1ia)
if (as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0") {
cal <- st_read(system.file("etc/shapes/california.gpkg.zip", package="spdep")[1])
(GDAL37 <- as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0")
file <- "etc/shapes/california.gpkg.zip"
zipfile <- system.file(file, package="spdep")
if (GDAL37) {
cal <- st_read(zipfile)
} else {
td <- tempdir()
bn <- sub(".zip", "", basename(file))
target <- unzip(zipfile, files=bn, exdir=td)
cal <- st_read(target)
}
fn <- system.file("etc/misc/contiguity_myid.dbf", package="spdep")[1]
cal1 <- read.swmdbf2listw(fn, style="B")
cal1a <- read.swmdbf2listw(fn, region.id=as.character(cal$MYID), style="B")
Expand All @@ -114,7 +123,7 @@ all.equal(cal1a_1n$weights, cal1a_1n_rt$weights, check.attributes=FALSE)
cal1_1n_rt <- read.swmdbf2listw(file, style="B", zero.policy=TRUE)
all(isTRUE(all.equal(cal1a_1n$neighbours, cal1_1n_rt$neighbours)))
all(isTRUE(all.equal(cal1a_1n$weights, cal1_1n_rt$weights)))
}

}
}
\keyword{spatial}
16 changes: 12 additions & 4 deletions man/skater.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,17 @@ skater(edges, data, ncuts, crit, vec.crit, method = c("euclidean",
\seealso{See Also as \code{\link{mstree}}}
\examples{
### loading data
if (as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0") {
bh <- st_read(system.file("etc/shapes/bhicv.gpkg.zip",
package="spdep")[1], quiet=TRUE)
(GDAL37 <- as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0")
file <- "etc/shapes/bhicv.gpkg.zip"
zipfile <- system.file(file, package="spdep")
if (GDAL37) {
bh <- st_read(zipfile)
} else {
td <- tempdir()
bn <- sub(".zip", "", basename(file))
target <- unzip(zipfile, files=bn, exdir=td)
bh <- st_read(target)
}
### data standardized
dpad <- data.frame(scale(as.data.frame(bh)[,5:8]))

Expand Down Expand Up @@ -198,7 +206,7 @@ if(!get.mcOption()) {
all.equal(res1, pres1, check.attributes=FALSE)
invisible(set.coresOption(coresOpt))
}
}

}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
Expand Down
Loading

0 comments on commit 28983fb

Please sign in to comment.