-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert to existing H3_BOUNDARY until SF improve H3_CELL_TO_BOUNDARY_P…
…ERFORMANCE
- Loading branch information
1 parent
d0e78a9
commit 0f8cc80
Showing
3 changed files
with
30 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
-------------------------------- | ||
-- Copyright (C) 2021-2024 CARTO | ||
-------------------------------- | ||
---------------------------- | ||
-- Copyright (C) 2021 CARTO | ||
---------------------------- | ||
-- TODO: Re-implement this using SF's native H3_CELL_TO_BOUNDARY when they improve performance | ||
-- Shortcut story/chore ID: 398796 | ||
|
||
CREATE OR REPLACE FUNCTION @@SF_SCHEMA@@._H3_BOUNDARY | ||
(index STRING) | ||
RETURNS STRING | ||
LANGUAGE JAVASCRIPT | ||
IMMUTABLE | ||
AS $$ | ||
if (!INDEX) { | ||
return null; | ||
} | ||
|
||
@@SF_LIBRARY_H3_BOUNDARY@@ | ||
|
||
if (!h3BoundaryLib.h3IsValid(INDEX)) { | ||
return null; | ||
} | ||
|
||
const coords = h3BoundaryLib.h3ToGeoBoundary(INDEX, true); | ||
const uniqueCoords = h3BoundaryLib.removeNextDuplicates(coords); | ||
return `POLYGON((${uniqueCoords.map(c => `${c[0]} ${c[1]}`).join(',')}))`; | ||
$$; | ||
|
||
CREATE OR REPLACE SECURE FUNCTION @@SF_SCHEMA@@.H3_BOUNDARY | ||
(index STRING) | ||
RETURNS GEOGRAPHY | ||
IMMUTABLE | ||
AS $$ | ||
IFF( | ||
@@SF_SCHEMA@@.H3_ISVALID(INDEX), | ||
H3_CELL_TO_BOUNDARY(INDEX), | ||
NULL | ||
) | ||
TRY_TO_GEOGRAPHY(@@SF_SCHEMA@@._H3_BOUNDARY(INDEX)) | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters