mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 02:52:13 +00:00
commit
757e5745f2
2
contrib/h3
vendored
2
contrib/h3
vendored
@ -1 +1 @@
|
|||||||
Subproject commit e209086ae1b5477307f545a0f6111780edc59940
|
Subproject commit c7f46cfd71fb60e2fefc90e28abe81657deff735
|
@ -3,21 +3,22 @@ set(H3_BINARY_DIR "${ClickHouse_BINARY_DIR}/contrib/h3/src/h3lib")
|
|||||||
|
|
||||||
set(SRCS
|
set(SRCS
|
||||||
"${H3_SOURCE_DIR}/lib/algos.c"
|
"${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/coordijk.c"
|
||||||
"${H3_SOURCE_DIR}/lib/faceijk.c"
|
"${H3_SOURCE_DIR}/lib/bbox.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/polygon.c"
|
"${H3_SOURCE_DIR}/lib/polygon.c"
|
||||||
|
"${H3_SOURCE_DIR}/lib/h3Index.c"
|
||||||
"${H3_SOURCE_DIR}/lib/vec2d.c"
|
"${H3_SOURCE_DIR}/lib/vec2d.c"
|
||||||
"${H3_SOURCE_DIR}/lib/vec3d.c"
|
"${H3_SOURCE_DIR}/lib/vec3d.c"
|
||||||
"${H3_SOURCE_DIR}/lib/vertex.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/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")
|
configure_file("${H3_SOURCE_DIR}/include/h3api.h.in" "${H3_BINARY_DIR}/include/h3api.h")
|
||||||
|
@ -21,6 +21,7 @@ namespace DB
|
|||||||
namespace ErrorCodes
|
namespace ErrorCodes
|
||||||
{
|
{
|
||||||
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||||
|
extern const int INCORRECT_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -79,11 +80,14 @@ public:
|
|||||||
const double lat = col_lat->getFloat64(row);
|
const double lat = col_lat->getFloat64(row);
|
||||||
const UInt8 res = col_res->getUInt(row);
|
const UInt8 res = col_res->getUInt(row);
|
||||||
|
|
||||||
GeoCoord coord;
|
LatLng coord;
|
||||||
coord.lon = degsToRads(lon);
|
coord.lng = degsToRads(lon);
|
||||||
coord.lat = degsToRads(lat);
|
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;
|
dst_data[row] = hindex;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
+ " 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
|
// 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;
|
dst_data[row] = res;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public:
|
|||||||
throw Exception("The argument 'resolution' (" + toString(resolution) + ") of function " + getName()
|
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);
|
+ " 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;
|
dst_data[row] = res;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public:
|
|||||||
{
|
{
|
||||||
const UInt64 hindex = col_hindex->getUInt(row);
|
const UInt64 hindex = col_hindex->getUInt(row);
|
||||||
|
|
||||||
UInt8 res = h3GetBaseCell(hindex);
|
UInt8 res = getBaseCellNumber(hindex);
|
||||||
|
|
||||||
dst_data[row] = res;
|
dst_data[row] = res;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public:
|
|||||||
{
|
{
|
||||||
const UInt64 hindex = col_hindex->getUInt(row);
|
const UInt64 hindex = col_hindex->getUInt(row);
|
||||||
|
|
||||||
UInt8 res = h3GetResolution(hindex);
|
UInt8 res = getResolution(hindex);
|
||||||
|
|
||||||
dst_data[row] = res;
|
dst_data[row] = res;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
throw Exception("The argument 'resolution' (" + toString(resolution) + ") of function " + getName()
|
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);
|
+ " 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;
|
dst_data[row] = res;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public:
|
|||||||
const UInt64 hindex_origin = col_hindex_origin->getUInt(row);
|
const UInt64 hindex_origin = col_hindex_origin->getUInt(row);
|
||||||
const UInt64 hindex_dest = col_hindex_dest->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;
|
dst_data[row] = res;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public:
|
|||||||
{
|
{
|
||||||
const UInt64 hindex = col_hindex->getUInt(row);
|
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;
|
dst_data[row] = is_valid;
|
||||||
}
|
}
|
||||||
|
@ -84,14 +84,14 @@ public:
|
|||||||
throw Exception("The argument 'resolution' (" + toString(child_resolution) + ") of function " + getName()
|
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);
|
+ " 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)
|
if (vec_size > MAX_ARRAY_SIZE)
|
||||||
throw Exception("The result of function" + getName()
|
throw Exception("The result of function" + getName()
|
||||||
+ " (array of " + toString(vec_size) + " elements) will be too large with resolution argument = "
|
+ " (array of " + toString(vec_size) + " elements) will be too large with resolution argument = "
|
||||||
+ toString(child_resolution), ErrorCodes::TOO_LARGE_ARRAY_SIZE);
|
+ toString(child_resolution), ErrorCodes::TOO_LARGE_ARRAY_SIZE);
|
||||||
|
|
||||||
hindex_vec.resize(vec_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);
|
dst_data.reserve(dst_data.size() + vec_size);
|
||||||
for (auto hindex : hindex_vec)
|
for (auto hindex : hindex_vec)
|
||||||
|
@ -74,7 +74,7 @@ public:
|
|||||||
throw Exception("The argument 'resolution' (" + toString(resolution) + ") of function " + getName()
|
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);
|
+ " 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;
|
dst_data[row] = res;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public:
|
|||||||
{
|
{
|
||||||
const UInt64 hindex = col_hindex->getUInt(i);
|
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);
|
throw Exception("Invalid H3 index: " + std::to_string(hindex), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public:
|
|||||||
const H3Index origin_hindex = col_hindex->getUInt(row);
|
const H3Index origin_hindex = col_hindex->getUInt(row);
|
||||||
const int k = col_k->getInt(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.
|
/// 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.
|
/// Let's use huge underestimation as the safe bound. We should not allow to generate too large arrays nevertheless.
|
||||||
constexpr auto max_k = 10000;
|
constexpr auto max_k = 10000;
|
||||||
@ -86,9 +86,9 @@ public:
|
|||||||
if (k < 0)
|
if (k < 0)
|
||||||
throw Exception(ErrorCodes::PARAMETER_OUT_OF_BOUND, "Argument 'k' for {} function must be non negative", getName());
|
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);
|
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);
|
dst_data.reserve(dst_data.size() + vec_size);
|
||||||
for (auto hindex : hindex_vec)
|
for (auto hindex : hindex_vec)
|
||||||
|
@ -4,7 +4,7 @@ OWNER(g:clickhouse)
|
|||||||
LIBRARY()
|
LIBRARY()
|
||||||
|
|
||||||
CFLAGS(
|
CFLAGS(
|
||||||
-DUSE_H3 -DUSE_SSL -DUSE_XXHASH
|
-DUSE_SSL -DUSE_XXHASH
|
||||||
)
|
)
|
||||||
|
|
||||||
ADDINCL(
|
ADDINCL(
|
||||||
|
@ -3,7 +3,7 @@ OWNER(g:clickhouse)
|
|||||||
LIBRARY()
|
LIBRARY()
|
||||||
|
|
||||||
CFLAGS(
|
CFLAGS(
|
||||||
-DUSE_H3 -DUSE_SSL -DUSE_XXHASH
|
-DUSE_SSL -DUSE_XXHASH
|
||||||
)
|
)
|
||||||
|
|
||||||
ADDINCL(
|
ADDINCL(
|
||||||
|
Loading…
Reference in New Issue
Block a user