Merge pull request #25483 from qoega/update-h3

Update h3
This commit is contained in:
alexey-milovidov 2021-07-10 19:18:45 +03:00 committed by GitHub
commit 757e5745f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 34 additions and 29 deletions

2
contrib/h3 vendored

@ -1 +1 @@
Subproject commit e209086ae1b5477307f545a0f6111780edc59940
Subproject commit c7f46cfd71fb60e2fefc90e28abe81657deff735

View File

@ -3,21 +3,22 @@ set(H3_BINARY_DIR "${ClickHouse_BINARY_DIR}/contrib/h3/src/h3lib")
set(SRCS
"${H3_SOURCE_DIR}/lib/algos.c"
"${H3_SOURCE_DIR}/lib/baseCells.c"
"${H3_SOURCE_DIR}/lib/bbox.c"
"${H3_SOURCE_DIR}/lib/coordijk.c"
"${H3_SOURCE_DIR}/lib/faceijk.c"
"${H3_SOURCE_DIR}/lib/geoCoord.c"
"${H3_SOURCE_DIR}/lib/h3Index.c"
"${H3_SOURCE_DIR}/lib/h3UniEdge.c"
"${H3_SOURCE_DIR}/lib/linkedGeo.c"
"${H3_SOURCE_DIR}/lib/localij.c"
"${H3_SOURCE_DIR}/lib/mathExtensions.c"
"${H3_SOURCE_DIR}/lib/bbox.c"
"${H3_SOURCE_DIR}/lib/polygon.c"
"${H3_SOURCE_DIR}/lib/h3Index.c"
"${H3_SOURCE_DIR}/lib/vec2d.c"
"${H3_SOURCE_DIR}/lib/vec3d.c"
"${H3_SOURCE_DIR}/lib/vertex.c"
"${H3_SOURCE_DIR}/lib/linkedGeo.c"
"${H3_SOURCE_DIR}/lib/localij.c"
"${H3_SOURCE_DIR}/lib/latLng.c"
"${H3_SOURCE_DIR}/lib/directedEdge.c"
"${H3_SOURCE_DIR}/lib/mathExtensions.c"
"${H3_SOURCE_DIR}/lib/iterators.c"
"${H3_SOURCE_DIR}/lib/vertexGraph.c"
"${H3_SOURCE_DIR}/lib/faceijk.c"
"${H3_SOURCE_DIR}/lib/baseCells.c"
)
configure_file("${H3_SOURCE_DIR}/include/h3api.h.in" "${H3_BINARY_DIR}/include/h3api.h")

View File

@ -21,6 +21,7 @@ namespace DB
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int INCORRECT_DATA;
}
namespace
@ -79,11 +80,14 @@ public:
const double lat = col_lat->getFloat64(row);
const UInt8 res = col_res->getUInt(row);
GeoCoord coord;
coord.lon = degsToRads(lon);
LatLng coord;
coord.lng = degsToRads(lon);
coord.lat = degsToRads(lat);
H3Index hindex = geoToH3(&coord, res);
H3Index hindex;
H3Error err = latLngToCell(&coord, res, &hindex);
if (err)
throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect coordinates latitude: {}, longitude: {}, error: {}", coord.lat, coord.lng, err);
dst_data[row] = hindex;
}

View File

@ -66,7 +66,7 @@ public:
+ " is out of bounds because the maximum resolution in H3 library is " + toString(MAX_H3_RES), ErrorCodes::ARGUMENT_OUT_OF_BOUND);
// Numerical constant is 180 degrees / pi / Earth radius, Earth radius is from h3 sources
Float64 res = 8.99320592271288084e-6 * edgeLengthM(resolution);
Float64 res = 8.99320592271288084e-6 * getHexagonEdgeLengthAvgM(resolution);
dst_data[row] = res;
}

View File

@ -70,7 +70,7 @@ public:
throw Exception("The argument 'resolution' (" + toString(resolution) + ") of function " + getName()
+ " is out of bounds because the maximum resolution in H3 library is " + toString(MAX_H3_RES), ErrorCodes::ARGUMENT_OUT_OF_BOUND);
Float64 res = edgeLengthM(resolution);
Float64 res = getHexagonEdgeLengthAvgM(resolution);
dst_data[row] = res;
}

View File

@ -59,7 +59,7 @@ public:
{
const UInt64 hindex = col_hindex->getUInt(row);
UInt8 res = h3GetBaseCell(hindex);
UInt8 res = getBaseCellNumber(hindex);
dst_data[row] = res;
}

View File

@ -59,7 +59,7 @@ public:
{
const UInt64 hindex = col_hindex->getUInt(row);
UInt8 res = h3GetResolution(hindex);
UInt8 res = getResolution(hindex);
dst_data[row] = res;
}

View File

@ -65,7 +65,7 @@ public:
throw Exception("The argument 'resolution' (" + toString(resolution) + ") of function " + getName()
+ " is out of bounds because the maximum resolution in H3 library is " + toString(MAX_H3_RES), ErrorCodes::ARGUMENT_OUT_OF_BOUND);
Float64 res = hexAreaM2(resolution);
Float64 res = getHexagonAreaAvgM2(resolution);
dst_data[row] = res;
}

View File

@ -67,7 +67,7 @@ public:
const UInt64 hindex_origin = col_hindex_origin->getUInt(row);
const UInt64 hindex_dest = col_hindex_dest->getUInt(row);
UInt8 res = h3IndexesAreNeighbors(hindex_origin, hindex_dest);
UInt8 res = areNeighborCells(hindex_origin, hindex_dest);
dst_data[row] = res;
}

View File

@ -59,7 +59,7 @@ public:
{
const UInt64 hindex = col_hindex->getUInt(row);
UInt8 is_valid = h3IsValid(hindex) == 0 ? 0 : 1;
UInt8 is_valid = isValidCell(hindex) == 0 ? 0 : 1;
dst_data[row] = is_valid;
}

View File

@ -84,14 +84,14 @@ public:
throw Exception("The argument 'resolution' (" + toString(child_resolution) + ") of function " + getName()
+ " is out of bounds because the maximum resolution in H3 library is " + toString(MAX_H3_RES), ErrorCodes::ARGUMENT_OUT_OF_BOUND);
const size_t vec_size = maxH3ToChildrenSize(parent_hindex, child_resolution);
const size_t vec_size = cellToChildrenSize(parent_hindex, child_resolution);
if (vec_size > MAX_ARRAY_SIZE)
throw Exception("The result of function" + getName()
+ " (array of " + toString(vec_size) + " elements) will be too large with resolution argument = "
+ toString(child_resolution), ErrorCodes::TOO_LARGE_ARRAY_SIZE);
hindex_vec.resize(vec_size);
h3ToChildren(parent_hindex, child_resolution, hindex_vec.data());
cellToChildren(parent_hindex, child_resolution, hindex_vec.data());
dst_data.reserve(dst_data.size() + vec_size);
for (auto hindex : hindex_vec)

View File

@ -74,7 +74,7 @@ public:
throw Exception("The argument 'resolution' (" + toString(resolution) + ") of function " + getName()
+ " is out of bounds because the maximum resolution in H3 library is " + toString(MAX_H3_RES), ErrorCodes::ARGUMENT_OUT_OF_BOUND);
UInt64 res = h3ToParent(hindex, resolution);
UInt64 res = cellToParent(hindex, resolution);
dst_data[row] = res;
}

View File

@ -66,7 +66,7 @@ public:
{
const UInt64 hindex = col_hindex->getUInt(i);
if (!h3IsValid(hindex))
if (!isValidCell(hindex))
{
throw Exception("Invalid H3 index: " + std::to_string(hindex), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}

View File

@ -77,7 +77,7 @@ public:
const H3Index origin_hindex = col_hindex->getUInt(row);
const int k = col_k->getInt(row);
/// Overflow is possible. The function maxKringSize does not check for overflow.
/// Overflow is possible. The function maxGridDiskSize does not check for overflow.
/// The calculation is similar to square of k but several times more.
/// Let's use huge underestimation as the safe bound. We should not allow to generate too large arrays nevertheless.
constexpr auto max_k = 10000;
@ -86,9 +86,9 @@ public:
if (k < 0)
throw Exception(ErrorCodes::PARAMETER_OUT_OF_BOUND, "Argument 'k' for {} function must be non negative", getName());
const auto vec_size = maxKringSize(k);
const auto vec_size = maxGridDiskSize(k);
hindex_vec.resize(vec_size);
kRing(origin_hindex, k, hindex_vec.data());
gridDisk(origin_hindex, k, hindex_vec.data());
dst_data.reserve(dst_data.size() + vec_size);
for (auto hindex : hindex_vec)

View File

@ -4,7 +4,7 @@ OWNER(g:clickhouse)
LIBRARY()
CFLAGS(
-DUSE_H3 -DUSE_SSL -DUSE_XXHASH
-DUSE_SSL -DUSE_XXHASH
)
ADDINCL(

View File

@ -3,7 +3,7 @@ OWNER(g:clickhouse)
LIBRARY()
CFLAGS(
-DUSE_H3 -DUSE_SSL -DUSE_XXHASH
-DUSE_SSL -DUSE_XXHASH
)
ADDINCL(