diff --git a/DESCRIPTION b/DESCRIPTION index 2d82466..2ba7ac5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ BugReports: https://github.com/symbolixau/h3r/issues Encoding: UTF-8 LazyData: true Depends: - h3lib (>= 0.1.3), + h3lib (>= 0.1.4), R (>= 2.10) LinkingTo: h3lib @@ -25,4 +25,4 @@ Suggests: sfheaders, tinytest Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/NAMESPACE b/NAMESPACE index cb1e6df..378c571 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,7 +14,6 @@ export(cellToParent) export(cellToVertex) export(cellToVertexes) export(cellsToDirectedEdge) -export(cellsToMultiPolygon) export(childPosToCell) export(compactCells) export(degsToRads) diff --git a/R/regions.R b/R/regions.R index 95658fd..b9ab91a 100644 --- a/R/regions.R +++ b/R/regions.R @@ -90,28 +90,28 @@ polygonToCells <- function(polygons, resolution, isLatLng = TRUE) { } -#' Cells to GeoPolygons -#' -#' Get the outlines of a set of H3 hexagons, returned in GeoJSON-like -#' MultiPolygon. -#' -#' @param cellSet list of string vectors containing to be H3 cell indexes -#' @inheritParams polygonToCells -#' -#' @return GeoJSON-like MultiPolygon containing the outlines of the set of -#' input H3 hexagons -#' -#' @examples -#' -#' cellsToMultiPolygon( -#' cellSet = list( -#' list(c("872830828ffffff", "87283082effffff")) -#' , list(c("872830828ffffff")) -#' ) -#' , 1L -#' ) -#' -#' @export -cellsToMultiPolygon <- function(cellSet, isLatLng = TRUE) { - .Call(h3rCellsToMultiPolygon, cellSet, int(isLatLng)) -} +# Cells to GeoPolygons +# +# Get the outlines of a set of H3 hexagons, returned in GeoJSON-like +# MultiPolygon. +# +# @param cellSet list of string vectors containing to be H3 cell indexes +# @inheritParams polygonToCells +# +# @return GeoJSON-like MultiPolygon containing the outlines of the set of +# input H3 hexagons +# +# @examples +# +# cellsToMultiPolygon( +# cellSet = list( +# list(c("872830828ffffff", "87283082effffff")) +# , list(c("872830828ffffff")) +# ) +# , 1L +# ) +# +# @export +# cellsToMultiPolygon <- function(cellSet, isLatLng = TRUE) { +# .Call(h3rCellsToMultiPolygon, cellSet, int(isLatLng)) +# } diff --git a/inst/include/h3r.h b/inst/include/h3r.h index 8e5b3fd..5374ea6 100644 --- a/inst/include/h3r.h +++ b/inst/include/h3r.h @@ -127,7 +127,7 @@ SEXP h3rUncompactCells(SEXP h3Sets, SEXP res); // Regions SEXP h3rPolygonToCells(SEXP polygonArray, SEXP res, SEXP isLatLng); -SEXP h3rCellsToMultiPolygon(SEXP h3Sets, SEXP isGeoJson); +// SEXP h3rCellsToMultiPolygon(SEXP h3Sets, SEXP isGeoJson); // Directed Edges SEXP h3rAreNeighborCells(SEXP origH3, SEXP destH3); diff --git a/inst/tinytest/test_region.R b/inst/tinytest/test_region.R index 8f12aa0..d00d707 100644 --- a/inst/tinytest/test_region.R +++ b/inst/tinytest/test_region.R @@ -33,21 +33,21 @@ expect_equal(polygonToCells(polygon = list( ) ), resolution = c(7L, 6L)), list(c( "872830870ffffff","872830828ffffff","872830876ffffff"), c("862830827ffffff"))) -expect_equal(cellsToMultiPolygon(cellSet = list(list(c("872830828ffffff", "87283082effffff")), list(c("862830827ffffff"))), 1L) - , list(list(list(list(matrix(c(37.78404622259876, -122.42708872508096, - 37.77226734985154, -122.43458610784572, - 37.76173573392154, -122.42576908738396, - 37.76298184766421, -122.40945463242251, - 37.75244647475626, -122.40063951171169, - 37.75368882535418, -122.38432356237523, - 37.76546768434345, -122.37681938644465, - 37.776004200673846, -122.38563455403627, - 37.7747607144902, -122.40195385157608, - 37.78529347359728, -122.41077092287513), - ncol = 2, byrow = TRUE)))), list(list(list(matrix(c(37.69973779105049, -122.35658316980643, - 37.724533591552756, -122.32525327556627, - 37.75740308914818, -122.33536307014123, - 37.76546768434345, -122.37681938644465, - 37.74066613210137, -122.40813889567379, - 37.707805739822945, -122.39801249019256), - ncol = 2, byrow = TRUE)))))) +# expect_equal(cellsToMultiPolygon(cellSet = list(list(c("872830828ffffff", "87283082effffff")), list(c("862830827ffffff"))), 1L) +# , list(list(list(list(matrix(c(37.78404622259876, -122.42708872508096, +# 37.77226734985154, -122.43458610784572, +# 37.76173573392154, -122.42576908738396, +# 37.76298184766421, -122.40945463242251, +# 37.75244647475626, -122.40063951171169, +# 37.75368882535418, -122.38432356237523, +# 37.76546768434345, -122.37681938644465, +# 37.776004200673846, -122.38563455403627, +# 37.7747607144902, -122.40195385157608, +# 37.78529347359728, -122.41077092287513), +# ncol = 2, byrow = TRUE)))), list(list(list(matrix(c(37.69973779105049, -122.35658316980643, +# 37.724533591552756, -122.32525327556627, +# 37.75740308914818, -122.33536307014123, +# 37.76546768434345, -122.37681938644465, +# 37.74066613210137, -122.40813889567379, +# 37.707805739822945, -122.39801249019256), +# ncol = 2, byrow = TRUE)))))) diff --git a/man/cellsToMultiPolygon.Rd b/man/cellsToMultiPolygon.Rd deleted file mode 100644 index 75e7953..0000000 --- a/man/cellsToMultiPolygon.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/regions.R -\name{cellsToMultiPolygon} -\alias{cellsToMultiPolygon} -\title{Cells to GeoPolygons} -\usage{ -cellsToMultiPolygon(cellSet, isLatLng = TRUE) -} -\arguments{ -\item{cellSet}{list of string vectors containing to be H3 cell indexes} - -\item{isLatLng}{\code{TRUE} (default) if the coordinates are in \code{lat / lng} order. -\code{FALSE} otherwise} -} -\value{ -GeoJSON-like MultiPolygon containing the outlines of the set of -input H3 hexagons -} -\description{ -Get the outlines of a set of H3 hexagons, returned in GeoJSON-like -MultiPolygon. -} -\examples{ - -cellsToMultiPolygon( - cellSet = list( - list(c("872830828ffffff", "87283082effffff")) - , list(c("872830828ffffff")) - ) - , 1L - ) - -} diff --git a/src/h3rHierarchy.c b/src/h3rHierarchy.c index 59648a2..c0aa8af 100644 --- a/src/h3rHierarchy.c +++ b/src/h3rHierarchy.c @@ -195,8 +195,9 @@ SEXP h3rCompactCells(SEXP h3Sets) { setSize = Rf_xlength(h3Set); H3Index cellSet[setSize]; - memset(cellSet, H3_INIT, sizeof(cellSet)); + memset(cellSet, -1, sizeof(cellSet)); H3Index compactedSet[setSize]; + memset(compactedSet, -1, sizeof(compactedSet)); for (j = 0; j < setSize; j++) { cellSet[j] = sexpStringToH3(h3Set, j); @@ -236,6 +237,8 @@ SEXP h3rUncompactCells(SEXP h3Sets, SEXP res) { setSize = Rf_xlength(h3Set); H3Index compactedSet[setSize]; + memset(compactedSet, -1, sizeof(compactedSet)); + ires = _getResolution(res, i); for (j = 0; j < setSize; j++) { @@ -244,6 +247,7 @@ SEXP h3rUncompactCells(SEXP h3Sets, SEXP res) { h3rError(uncompactCellsSize(compactedSet, setSize, ires, &cellSize), i); H3Index cellSet[cellSize]; + memset(cellSet, -1, sizeof(cellSet)); h3rError(uncompactCells(compactedSet, setSize, cellSet, cellSize, ires), i); diff --git a/src/h3rRegions.c b/src/h3rRegions.c index 17f7477..7723d01 100644 --- a/src/h3rRegions.c +++ b/src/h3rRegions.c @@ -246,48 +246,49 @@ SEXP h3rReadMultiPolygon(LinkedGeoPolygon *polygon, int isLatLng) { } -SEXP singleCellsToMultiPolygon(SEXP h3Sets, int geojson, R_xlen_t idx) { - R_xlen_t n = Rf_xlength(h3Sets); - R_xlen_t i; - int64_t j, setSize; - - SEXP out = PROTECT(Rf_allocVector(VECSXP, n)); - - for (i = 0; i < n; i++) { - SEXP h3Set = VECTOR_ELT(h3Sets, i); - setSize = Rf_xlength(h3Set); - - H3Index cellSet[setSize]; - - for (j = 0; j < setSize; j++) { - cellSet[j] = sexpStringToH3(h3Set, j); - } - - LinkedGeoPolygon geoPolygon; - - h3rError(cellsToLinkedMultiPolygon(cellSet, setSize, &geoPolygon), idx); - - SET_VECTOR_ELT(out, i, h3rReadMultiPolygon(&geoPolygon, geojson)); - } - - UNPROTECT(1); - return out; -} - -SEXP h3rCellsToMultiPolygon(SEXP h3Sets, SEXP isLatLng) { - R_xlen_t n = Rf_xlength(h3Sets); - R_xlen_t i ; - - int geojson = INTEGER(isLatLng)[0]; - - SEXP out = PROTECT(Rf_allocVector(VECSXP, n)); - - for (i = 0; i < n; i++) { - SEXP h3Set = VECTOR_ELT(h3Sets, i); - SEXP multiPolygon = singleCellsToMultiPolygon(h3Set, geojson, i); - SET_VECTOR_ELT(out, i, multiPolygon); - } - - UNPROTECT(1); - return out; -} +// SEXP singleCellsToMultiPolygon(SEXP h3Sets, int geojson, R_xlen_t idx) { +// R_xlen_t n = Rf_xlength(h3Sets); +// R_xlen_t i; +// int64_t j, setSize; +// +// SEXP out = PROTECT(Rf_allocVector(VECSXP, n)); +// +// for (i = 0; i < n; i++) { +// SEXP h3Set = VECTOR_ELT(h3Sets, i); +// setSize = Rf_xlength(h3Set); +// +// H3Index cellSet[setSize]; +// memset(cellSet, -1, sizeof(cellSet)); +// +// for (j = 0; j < setSize; j++) { +// cellSet[j] = sexpStringToH3(h3Set, j); +// } +// +// LinkedGeoPolygon geoPolygon; +// +// h3rError(cellsToLinkedMultiPolygon(cellSet, setSize, &geoPolygon), idx); +// +// SET_VECTOR_ELT(out, i, h3rReadMultiPolygon(&geoPolygon, geojson)); +// } +// +// UNPROTECT(1); +// return out; +// } +// +// SEXP h3rCellsToMultiPolygon(SEXP h3Sets, SEXP isLatLng) { +// R_xlen_t n = Rf_xlength(h3Sets); +// R_xlen_t i ; +// +// int geojson = INTEGER(isLatLng)[0]; +// +// SEXP out = PROTECT(Rf_allocVector(VECSXP, n)); +// +// for (i = 0; i < n; i++) { +// SEXP h3Set = VECTOR_ELT(h3Sets, i); +// SEXP multiPolygon = singleCellsToMultiPolygon(h3Set, geojson, i); +// SET_VECTOR_ELT(out, i, multiPolygon); +// } +// +// UNPROTECT(1); +// return out; +// } diff --git a/src/h3rTraversal.c b/src/h3rTraversal.c index 94c1b6d..5bd6b87 100644 --- a/src/h3rTraversal.c +++ b/src/h3rTraversal.c @@ -246,6 +246,7 @@ SEXP h3rGridRingUnsafe(SEXP h3, SEXP k) { h3rError(maxGridDiskSize(length, &maxSize), i); H3Index result[maxSize]; + memset(result, -1, sizeof(result)); h3rError(gridRingUnsafe(h, length, result), i); diff --git a/src/init.c b/src/init.c index 802d9eb..cae0f99 100644 --- a/src/init.c +++ b/src/init.c @@ -55,7 +55,7 @@ static const R_CallMethodDef callMethods[] = { // Regions {"h3rPolygonToCells", (DL_FUNC) &h3rPolygonToCells, 3}, - {"h3rCellsToMultiPolygon", (DL_FUNC) &h3rCellsToMultiPolygon, 2}, + // {"h3rCellsToMultiPolygon", (DL_FUNC) &h3rCellsToMultiPolygon, 2}, // Directed Edges {"h3rAreNeighborCells", (DL_FUNC) &h3rAreNeighborCells, 2}, @@ -153,7 +153,7 @@ void attribute_visible R_init_h3r(DllInfo *info) // Regions R_RegisterCCallable("h3r", "h3rPolygonToCells", (DL_FUNC) &h3rPolygonToCells); - R_RegisterCCallable("h3r", "h3rCellsToMultiPolygon", (DL_FUNC) &h3rCellsToMultiPolygon); + // R_RegisterCCallable("h3r", "h3rCellsToMultiPolygon", (DL_FUNC) &h3rCellsToMultiPolygon); // Directed Edges R_RegisterCCallable("h3r", "h3rAreNeighborCells", (DL_FUNC) &h3rAreNeighborCells);