Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: DRAFT: polygonToCellsExperimental integration #159

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,21 @@ project(
# set this to "${PROJECT_VERSION}" on release
#set(INSTALL_VERSION "${PROJECT_VERSION}")
set(INSTALL_VERSION "unreleased")
set(H3_CORE_VERSION 4.1.0)
set(H3_CORE_SHA256 ec99f1f5974846bde64f4513cf8d2ea1b8d172d2218ab41803bf6a63532272bc)
#set(H3_CORE_VERSION 4.1.0)
set(H3_CORE_BRANCH master)
set(H3_CORE_SHA256 e8b16611b582275bdb9815bc5a80e0559a811758)

if(H3_CORE_VERSION)
set(H3_ARCHIVE_URL, https://github.com/uber/h3/archive/refs/tags/v${H3_CORE_VERSION}.tar.gz)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize how fancy CMake was and that it had a git integration already... so this is probably not the best way to go about this.

endif()

if(H3_CORE_BRANCH)
set(H3_ARCHIVE_URL, https://github.com/uber/h3/archive/refs/heads/${H3_CORE_BRANCH}.zip)
endif()

if(H3_CORE_BRANCH AND H3_CORE_VERSION)
message(FATAL_ERROR "Cannot specify both H3_CORE_BRANCH and H3_CORE_VERSION")
endif()

# If you set any CMAKE_ variables, that can go here.
# (But usually don't do this, except maybe for C++ standard)
Expand Down
4 changes: 2 additions & 2 deletions cmake/h3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ set(ENABLE_DOCS OFF)

FetchContent_Declare(
h3
URL https://github.com/uber/h3/archive/refs/tags/v${H3_CORE_VERSION}.tar.gz
URL_HASH SHA256=${H3_CORE_SHA256}
GIT_REPOSITORY https://github.com/uber/h3.git
GIT_TAG master
)
FetchContent_MakeAvailable(h3)

Expand Down
24 changes: 22 additions & 2 deletions h3/src/binding/regions.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "type.h"
#include "srf.h"

H3Error polygonToCellsExperimental(const GeoPolygon* geoPolygon, int res, uint32_t flags, H3Index* out);

PGDLLEXPORT PG_FUNCTION_INFO_V1(h3_polygon_to_cells);
PGDLLEXPORT PG_FUNCTION_INFO_V1(h3_cells_to_multi_polygon);

Expand Down Expand Up @@ -91,6 +93,7 @@ h3_polygon_to_cells(PG_FUNCTION_ARGS)
H3Index *indices;
ArrayType *holes;
int nelems = 0;
uint32_t flags = 2; // Default to CONTAINMENT_OVERLAPPING
int resolution;
GeoPolygon polygon;
Datum value;
Expand All @@ -110,6 +113,12 @@ h3_polygon_to_cells(PG_FUNCTION_ARGS)
}
resolution = PG_GETARG_INT32(2);

// Check if flags argument is provided
if (PG_NARGS() > 3 && !PG_ARGISNULL(3))
{
flags = PG_GETARG_UINT32(3);
}

/* build polygon */
polygonToGeoLoop(exterior, &(polygon.geoloop));

Expand Down Expand Up @@ -142,10 +151,10 @@ h3_polygon_to_cells(PG_FUNCTION_ARGS)
}

/* produce hexagons into allocated memory */
h3_assert(maxPolygonToCellsSize(&polygon, resolution, 0, &maxSize));
h3_assert(maxPolygonToCellsSize(&polygon, resolution, flags, &maxSize));
indices = palloc_extended(maxSize * sizeof(H3Index),
MCXT_ALLOC_HUGE | MCXT_ALLOC_ZERO);
h3_assert(polygonToCells(&polygon, resolution, 0, indices));
h3_assert(polygonToCellsExperimental(&polygon, resolution, flags, indices));

funcctx->user_fctx = indices;
funcctx->max_calls = maxSize;
Expand Down Expand Up @@ -339,4 +348,15 @@ struct LinkedGeoPolygon
LinkedGeoLoop *last;
LinkedGeoPolygon *next;
};

**
* Values representing polyfill containment modes, to be used in
* the `flags` bit field.
*
typedef enum {
CONTAINMENT_CENTER = 0, ///< Cell center is contained in the shape
CONTAINMENT_FULL = 1, ///< Cell is fully contained in the shape
CONTAINMENT_OVERLAPPING = 2, ///< Cell overlaps the shape at any point
CONTAINMENT_INVALID = 3 ///< This mode is invalid and should not be used
} ContainmentMode;
*/
Loading