mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Revert "more mercator"
This reverts commit d4258922d1543211cf8b62f7c827a927712dca42.
This commit is contained in:
parent
a6779df0ae
commit
c81c742877
@ -1,7 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/ColumnWithTypeAndName.h>
|
||||
#include <Core/Types.h>
|
||||
|
||||
#include <boost/geometry/geometries/geometries.hpp>
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnTuple.h>
|
||||
@ -9,10 +14,12 @@
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/IDataType.h>
|
||||
#include <DataTypes/DataTypeCustomGeo.h>
|
||||
#include <Functions/geometryTypes.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <Interpreters/castColumn.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
@ -22,6 +29,26 @@ namespace ErrorCodes
|
||||
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||
}
|
||||
|
||||
template <typename Point>
|
||||
using Ring = boost::geometry::model::ring<Point>;
|
||||
|
||||
template <typename Point>
|
||||
using Polygon = boost::geometry::model::polygon<Point>;
|
||||
|
||||
template <typename Point>
|
||||
using MultiPolygon = boost::geometry::model::multi_polygon<Polygon<Point>>;
|
||||
|
||||
using CartesianPoint = boost::geometry::model::d2::point_xy<Float64>;
|
||||
using CartesianRing = Ring<CartesianPoint>;
|
||||
using CartesianPolygon = Polygon<CartesianPoint>;
|
||||
using CartesianMultiPolygon = MultiPolygon<CartesianPoint>;
|
||||
|
||||
/// Latitude, longitude
|
||||
using SphericalPoint = boost::geometry::model::point<Float64, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>>;
|
||||
using SphericalRing = Ring<SphericalPoint>;
|
||||
using SphericalPolygon = Polygon<SphericalPoint>;
|
||||
using SphericalMultiPolygon = MultiPolygon<SphericalPoint>;
|
||||
|
||||
/**
|
||||
* Class which takes converts Column with type Tuple(Float64, Float64) to a vector of boost point type.
|
||||
* They are (x,y) in case of cartesian coordinated and (lon,lat) in case of Spherical.
|
||||
|
@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/Types.h>
|
||||
|
||||
#include <boost/geometry/geometries/geometries.hpp>
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
template <typename Point>
|
||||
using Ring = boost::geometry::model::ring<Point>;
|
||||
|
||||
template <typename Point>
|
||||
using Polygon = boost::geometry::model::polygon<Point>;
|
||||
|
||||
template <typename Point>
|
||||
using MultiPolygon = boost::geometry::model::multi_polygon<Polygon<Point>>;
|
||||
|
||||
using CartesianPoint = boost::geometry::model::d2::point_xy<Float64>;
|
||||
using CartesianRing = Ring<CartesianPoint>;
|
||||
using CartesianPolygon = Polygon<CartesianPoint>;
|
||||
using CartesianMultiPolygon = MultiPolygon<CartesianPoint>;
|
||||
|
||||
/// Latitude, longitude
|
||||
using SphericalPoint = boost::geometry::model::point<Float64, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>>;
|
||||
using SphericalRing = Ring<SphericalPoint>;
|
||||
using SphericalPolygon = Polygon<SphericalPoint>;
|
||||
using SphericalMultiPolygon = MultiPolygon<SphericalPoint>;
|
||||
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
#include <Functions/mercatorConverters.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr double PI = 3.14159265358979323846;
|
||||
|
||||
constexpr double epsilon = 1e-4;
|
||||
|
||||
/// Convert angle from degrees to radians.
|
||||
double deg_to_rad(double degree) {
|
||||
return (degree - epsilon) * (PI / 180.0);
|
||||
}
|
||||
|
||||
/// Convert angle from radians to degrees.
|
||||
double rad_to_deg(double radians) {
|
||||
return radians * (180.0 / PI);
|
||||
}
|
||||
|
||||
double earth_radius_for_epsg3857 = 6378137.0;
|
||||
// constexpr double max_coordinate_epsg3857 = 20037508.34;
|
||||
|
||||
|
||||
double lon_to_x(double lon) {
|
||||
return earth_radius_for_epsg3857 * deg_to_rad(lon);
|
||||
}
|
||||
|
||||
// canonical log(tan()) version
|
||||
double lat_to_y_with_tan(double lat) { // not constexpr because math functions aren't
|
||||
return earth_radius_for_epsg3857 * std::log(std::tan(PI/4 + deg_to_rad(lat)/2));
|
||||
}
|
||||
|
||||
double x_to_lon(double x) {
|
||||
return rad_to_deg(x) / earth_radius_for_epsg3857;
|
||||
}
|
||||
|
||||
double y_to_lat(double y) { // not constexpr because math functions aren't
|
||||
return rad_to_deg(2 * std::atan(std::exp(y / earth_radius_for_epsg3857)) - PI/2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void PointMercatorConverter::forward(CartesianPoint & point)
|
||||
{
|
||||
point.x(lon_to_x(point.template get<0>()));
|
||||
point.y(lat_to_y_with_tan(point.template get<1>()));
|
||||
}
|
||||
|
||||
|
||||
void RingMercatorConverter::forward(CartesianRing & ring)
|
||||
{
|
||||
for (auto & point : ring)
|
||||
PointMercatorConverter::forward(point);
|
||||
}
|
||||
|
||||
void PolygonMercatorConverter::forward(CartesianPolygon & polygon)
|
||||
{
|
||||
RingMercatorConverter::forward(polygon.outer());
|
||||
for (auto & hole : polygon.inners())
|
||||
RingMercatorConverter::forward(hole);
|
||||
}
|
||||
|
||||
void MultiPolygonMercatorConverter::forward(CartesianMultiPolygon & multipolygon)
|
||||
{
|
||||
for (auto & polygon : multipolygon)
|
||||
{
|
||||
RingMercatorConverter::forward(polygon.outer());
|
||||
for (auto & hole : polygon.inners())
|
||||
RingMercatorConverter::forward(hole);
|
||||
}
|
||||
}
|
||||
|
||||
void PointMercatorConverter::backward(CartesianPoint & point)
|
||||
{
|
||||
point.x(x_to_lon(point.template get<0>()));
|
||||
point.y(y_to_lat(point.template get<1>()));
|
||||
}
|
||||
|
||||
|
||||
void RingMercatorConverter::backward(CartesianRing & ring)
|
||||
{
|
||||
for (auto & point : ring)
|
||||
PointMercatorConverter::backward(point);
|
||||
}
|
||||
|
||||
void PolygonMercatorConverter::backward(CartesianPolygon & polygon)
|
||||
{
|
||||
RingMercatorConverter::backward(polygon.outer());
|
||||
for (auto & hole : polygon.inners())
|
||||
RingMercatorConverter::backward(hole);
|
||||
}
|
||||
|
||||
void MultiPolygonMercatorConverter::backward(CartesianMultiPolygon & multipolygon)
|
||||
{
|
||||
for (auto & polygon : multipolygon)
|
||||
{
|
||||
RingMercatorConverter::backward(polygon.outer());
|
||||
for (auto & hole : polygon.inners())
|
||||
RingMercatorConverter::backward(hole);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,85 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Functions/geometryTypes.h>
|
||||
#include <Common/Exception.h>
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int LOGICAL_ERROR;
|
||||
}
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
/// It must work only with CartesianPoint
|
||||
class PointMercatorConverter
|
||||
{
|
||||
public:
|
||||
static void forward(CartesianPoint & point);
|
||||
static void backward(CartesianPoint & point);
|
||||
};
|
||||
|
||||
|
||||
class RingMercatorConverter
|
||||
{
|
||||
public:
|
||||
static void forward(CartesianRing & ring);
|
||||
static void backward(CartesianRing & ring);
|
||||
};
|
||||
|
||||
|
||||
class PolygonMercatorConverter
|
||||
{
|
||||
public:
|
||||
static void forward(CartesianPolygon & polygon);
|
||||
static void backward(CartesianPolygon & polygon);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MultiPolygonMercatorConverter
|
||||
{
|
||||
public:
|
||||
static void forward(CartesianMultiPolygon & polygon);
|
||||
static void backward(CartesianMultiPolygon & polygon);
|
||||
};
|
||||
|
||||
|
||||
struct PType
|
||||
{
|
||||
using Type = PType;
|
||||
};
|
||||
|
||||
|
||||
template <typename Geometry>
|
||||
void mercatorForward(Geometry & geometry)
|
||||
{
|
||||
if constexpr (std::is_same_v<Geometry, CartesianPoint>)
|
||||
return PointMercatorConverter::forward(geometry);
|
||||
else if constexpr (std::is_same_v<Geometry, CartesianRing>)
|
||||
return RingMercatorConverter::forward(geometry);
|
||||
else if constexpr (std::is_same_v<Geometry, CartesianPolygon>)
|
||||
return PolygonMercatorConverter::forward(geometry);
|
||||
else if constexpr (std::is_same_v<Geometry, CartesianMultiPolygon>)
|
||||
return MultiPolygonMercatorConverter::forward(geometry);
|
||||
else
|
||||
throw Exception("Unknown geometry type", ErrorCodes::LOGICAL_ERROR);
|
||||
}
|
||||
|
||||
|
||||
template <typename Geometry>
|
||||
void mercatorBackward(Geometry & geometry)
|
||||
{
|
||||
if constexpr (std::is_same_v<Geometry, CartesianPoint>)
|
||||
return PointMercatorConverter::backward(geometry);
|
||||
else if constexpr (std::is_same_v<Geometry, CartesianRing>)
|
||||
return RingMercatorConverter::backward(geometry);
|
||||
else if constexpr (std::is_same_v<Geometry, CartesianPolygon>)
|
||||
return PolygonMercatorConverter::backward(geometry);
|
||||
else if constexpr (std::is_same_v<Geometry, CartesianMultiPolygon>)
|
||||
return MultiPolygonMercatorConverter::backward(geometry);
|
||||
else
|
||||
throw Exception("Unknown geometry type", ErrorCodes::LOGICAL_ERROR);
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,22 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/geometryConverters.h>
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnTuple.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/DataTypeTuple.h>
|
||||
#include <DataTypes/DataTypeCustomGeo.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
|
@ -1,6 +1,22 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/geometryConverters.h>
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnTuple.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/DataTypeTuple.h>
|
||||
#include <DataTypes/DataTypeCustomGeo.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
|
@ -1,6 +1,22 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/geometryConverters.h>
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnTuple.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/DataTypeTuple.h>
|
||||
#include <DataTypes/DataTypeCustomGeo.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
namespace ErrorCodes
|
||||
|
@ -1,6 +1,24 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/geometryConverters.h>
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnTuple.h>
|
||||
#include <Columns/ColumnConst.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <DataTypes/DataTypesNumber.h>
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/DataTypeTuple.h>
|
||||
#include <DataTypes/DataTypeCustomGeo.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
|
@ -1,6 +1,24 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/geometryConverters.h>
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnTuple.h>
|
||||
#include <Columns/ColumnConst.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <DataTypes/DataTypesNumber.h>
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/DataTypeTuple.h>
|
||||
#include <DataTypes/DataTypeCustomGeo.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
namespace ErrorCodes
|
||||
|
@ -1,6 +1,22 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/geometryConverters.h>
|
||||
#include <Functions/mercatorConverters.h>
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnTuple.h>
|
||||
#include <Columns/ColumnConst.h>
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/DataTypeTuple.h>
|
||||
#include <DataTypes/DataTypeCustomGeo.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <chrono>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -10,29 +26,11 @@ namespace ErrorCodes
|
||||
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||
}
|
||||
|
||||
struct IntersectionCartesian
|
||||
{
|
||||
static inline const char * name = "polygonsIntersectionCartesian";
|
||||
using Point = CartesianPoint;
|
||||
};
|
||||
|
||||
struct IntersectionSpherical
|
||||
{
|
||||
static inline const char * name = "polygonsIntersectionSpherical";
|
||||
using Point = SphericalPoint;
|
||||
};
|
||||
|
||||
struct IntersectionMercator
|
||||
{
|
||||
static inline const char * name = "polygonsIntersectionMercator";
|
||||
using Point = CartesianPoint;
|
||||
};
|
||||
|
||||
template <typename Holder>
|
||||
template <typename Point>
|
||||
class FunctionPolygonsIntersection : public IFunction
|
||||
{
|
||||
public:
|
||||
static inline const char * name = Holder::name;
|
||||
static inline const char * name;
|
||||
|
||||
explicit FunctionPolygonsIntersection() = default;
|
||||
|
||||
@ -64,8 +62,6 @@ public:
|
||||
|
||||
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*result_type*/, size_t input_rows_count) const override
|
||||
{
|
||||
using Point = typename Holder::Point;
|
||||
|
||||
MultiPolygonSerializer<Point> serializer;
|
||||
|
||||
callOnTwoGeometryDataTypes<Point>(arguments[0].type, arguments[1].type, [&](const auto & left_type, const auto & right_type)
|
||||
@ -91,19 +87,10 @@ public:
|
||||
boost::geometry::correct(first[i]);
|
||||
boost::geometry::correct(second[i]);
|
||||
|
||||
if constexpr (std::is_same_v<Holder, IntersectionMercator>)
|
||||
{
|
||||
mercatorForward(first[i]);
|
||||
mercatorForward(second[i]);
|
||||
}
|
||||
|
||||
MultiPolygon<Point> intersection{};
|
||||
/// Main work here.
|
||||
boost::geometry::intersection(first[i], second[i], intersection);
|
||||
|
||||
if constexpr (std::is_same_v<Holder, IntersectionMercator>)
|
||||
mercatorBackward(intersection);
|
||||
|
||||
serializer.add(intersection);
|
||||
}
|
||||
}
|
||||
@ -118,10 +105,18 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
const char * FunctionPolygonsIntersection<CartesianPoint>::name = "polygonsIntersectionCartesian";
|
||||
|
||||
template <>
|
||||
const char * FunctionPolygonsIntersection<SphericalPoint>::name = "polygonsIntersectionSpherical";
|
||||
|
||||
|
||||
void registerFunctionPolygonsIntersection(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionPolygonsIntersection<IntersectionCartesian>>();
|
||||
factory.registerFunction<FunctionPolygonsIntersection<IntersectionSpherical>>();
|
||||
factory.registerFunction<FunctionPolygonsIntersection<IntersectionMercator>>();
|
||||
factory.registerFunction<FunctionPolygonsIntersection<CartesianPoint>>();
|
||||
factory.registerFunction<FunctionPolygonsIntersection<SphericalPoint>>();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,21 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/geometryConverters.h>
|
||||
#include <Functions/mercatorConverters.h>
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnTuple.h>
|
||||
#include <Columns/ColumnConst.h>
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/DataTypeTuple.h>
|
||||
#include <DataTypes/DataTypeCustomGeo.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -11,30 +26,11 @@ namespace ErrorCodes
|
||||
}
|
||||
|
||||
|
||||
struct SymDifferenceCartesian
|
||||
{
|
||||
static inline const char * name = "polygonsSymDifferenceCartesian";
|
||||
using Point = CartesianPoint;
|
||||
};
|
||||
|
||||
struct SymDifferenceSpherical
|
||||
{
|
||||
static inline const char * name = "polygonsSymDifferenceSpherical";
|
||||
using Point = SphericalPoint;
|
||||
};
|
||||
|
||||
struct SymDifferenceMercator
|
||||
{
|
||||
static inline const char * name = "polygonsSymDifferenceMercator";
|
||||
using Point = CartesianPoint;
|
||||
};
|
||||
|
||||
|
||||
template <typename Holder>
|
||||
template <typename Point>
|
||||
class FunctionPolygonsSymDifference : public IFunction
|
||||
{
|
||||
public:
|
||||
static inline const char * name = Holder::name;
|
||||
static const char * name;
|
||||
|
||||
explicit FunctionPolygonsSymDifference() = default;
|
||||
|
||||
@ -65,8 +61,6 @@ public:
|
||||
|
||||
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*result_type*/, size_t input_rows_count) const override
|
||||
{
|
||||
using Point = typename Holder::Point;
|
||||
|
||||
MultiPolygonSerializer<Point> serializer;
|
||||
|
||||
callOnTwoGeometryDataTypes<Point>(arguments[0].type, arguments[1].type, [&](const auto & left_type, const auto & right_type)
|
||||
@ -90,18 +84,9 @@ public:
|
||||
boost::geometry::correct(first[i]);
|
||||
boost::geometry::correct(second[i]);
|
||||
|
||||
if constexpr (std::is_same_v<Holder, SymDifferenceMercator>)
|
||||
{
|
||||
mercatorForward(first[i]);
|
||||
mercatorForward(second[i]);
|
||||
}
|
||||
|
||||
MultiPolygon<Point> sym_difference{};
|
||||
boost::geometry::sym_difference(first[i], second[i], sym_difference);
|
||||
|
||||
if constexpr (std::is_same_v<Holder, SymDifferenceMercator>)
|
||||
mercatorBackward(sym_difference);
|
||||
|
||||
serializer.add(sym_difference);
|
||||
}
|
||||
}
|
||||
@ -116,11 +101,16 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
const char * FunctionPolygonsSymDifference<CartesianPoint>::name = "polygonsSymDifferenceCartesian";
|
||||
|
||||
template <>
|
||||
const char * FunctionPolygonsSymDifference<SphericalPoint>::name = "polygonsSymDifferenceSpherical";
|
||||
|
||||
void registerFunctionPolygonsSymDifference(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionPolygonsSymDifference<SymDifferenceCartesian>>();
|
||||
factory.registerFunction<FunctionPolygonsSymDifference<SymDifferenceSpherical>>();
|
||||
factory.registerFunction<FunctionPolygonsSymDifference<SymDifferenceMercator>>();
|
||||
factory.registerFunction<FunctionPolygonsSymDifference<CartesianPoint>>();
|
||||
factory.registerFunction<FunctionPolygonsSymDifference<SphericalPoint>>();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,21 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/geometryConverters.h>
|
||||
#include <Functions/mercatorConverters.h>
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnTuple.h>
|
||||
#include <Columns/ColumnConst.h>
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/DataTypeTuple.h>
|
||||
#include <DataTypes/DataTypeCustomGeo.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -11,30 +26,11 @@ namespace ErrorCodes
|
||||
}
|
||||
|
||||
|
||||
struct UnionCartesian
|
||||
{
|
||||
static inline const char * name = "polygonsUnionCartesian";
|
||||
using Point = CartesianPoint;
|
||||
};
|
||||
|
||||
struct UnionSpherical
|
||||
{
|
||||
static inline const char * name = "polygonsUnionSpherical";
|
||||
using Point = SphericalPoint;
|
||||
};
|
||||
|
||||
struct UnionMercator
|
||||
{
|
||||
static inline const char * name = "polygonsUnionMercator";
|
||||
using Point = CartesianPoint;
|
||||
};
|
||||
|
||||
|
||||
template <typename Holder>
|
||||
template <typename Point>
|
||||
class FunctionPolygonsUnion : public IFunction
|
||||
{
|
||||
public:
|
||||
static inline const char * name = Holder::name ;
|
||||
static inline const char * name;
|
||||
|
||||
explicit FunctionPolygonsUnion() = default;
|
||||
|
||||
@ -65,7 +61,6 @@ public:
|
||||
|
||||
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*result_type*/, size_t input_rows_count) const override
|
||||
{
|
||||
using Point = typename Holder::Point;
|
||||
MultiPolygonSerializer<Point> serializer;
|
||||
|
||||
callOnTwoGeometryDataTypes<Point>(arguments[0].type, arguments[1].type, [&](const auto & left_type, const auto & right_type)
|
||||
@ -91,19 +86,10 @@ public:
|
||||
boost::geometry::correct(first[i]);
|
||||
boost::geometry::correct(second[i]);
|
||||
|
||||
if constexpr (std::is_same_v<Holder, UnionMercator>)
|
||||
{
|
||||
mercatorForward(first[i]);
|
||||
mercatorForward(second[i]);
|
||||
}
|
||||
|
||||
MultiPolygon<Point> polygons_union{};
|
||||
/// Main work here.
|
||||
boost::geometry::union_(first[i], second[i], polygons_union);
|
||||
|
||||
if constexpr (std::is_same_v<Holder, UnionMercator>)
|
||||
mercatorBackward(polygons_union);
|
||||
|
||||
serializer.add(polygons_union);
|
||||
}
|
||||
}
|
||||
@ -118,12 +104,17 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
const char * FunctionPolygonsUnion<CartesianPoint>::name = "polygonsUnionCartesian";
|
||||
|
||||
template <>
|
||||
const char * FunctionPolygonsUnion<SphericalPoint>::name = "polygonsUnionSpherical";
|
||||
|
||||
|
||||
void registerFunctionPolygonsUnion(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionPolygonsUnion<UnionCartesian>>();
|
||||
factory.registerFunction<FunctionPolygonsUnion<UnionSpherical>>();
|
||||
factory.registerFunction<FunctionPolygonsUnion<UnionMercator>>();
|
||||
factory.registerFunction<FunctionPolygonsUnion<CartesianPoint>>();
|
||||
factory.registerFunction<FunctionPolygonsUnion<SphericalPoint>>();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,23 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/geometryConverters.h>
|
||||
#include <Functions/mercatorConverters.h>
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
|
||||
#include <common/logger_useful.h>
|
||||
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnTuple.h>
|
||||
#include <Columns/ColumnConst.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <DataTypes/DataTypesNumber.h>
|
||||
#include <DataTypes/DataTypeArray.h>
|
||||
#include <DataTypes/DataTypeTuple.h>
|
||||
#include <DataTypes/DataTypeCustomGeo.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -10,29 +27,12 @@ namespace ErrorCodes
|
||||
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||
}
|
||||
|
||||
struct WithinCartesian
|
||||
{
|
||||
static inline const char * name = "polygonsWithinCartesian";
|
||||
using Point = CartesianPoint;
|
||||
};
|
||||
|
||||
struct WithinSpherical
|
||||
{
|
||||
static inline const char * name = "polygonsWithinSpherical";
|
||||
using Point = SphericalPoint;
|
||||
};
|
||||
|
||||
struct WithinMercator
|
||||
{
|
||||
static inline const char * name = "polygonsWithinMercator";
|
||||
using Point = CartesianPoint;
|
||||
};
|
||||
|
||||
template <typename Holder>
|
||||
template <typename Point>
|
||||
class FunctionPolygonsWithin : public IFunction
|
||||
{
|
||||
public:
|
||||
static inline const char * name = Holder::name;
|
||||
static inline const char * name;
|
||||
|
||||
explicit FunctionPolygonsWithin() = default;
|
||||
|
||||
@ -63,7 +63,6 @@ public:
|
||||
|
||||
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*result_type*/, size_t input_rows_count) const override
|
||||
{
|
||||
using Point = typename Holder::Point;
|
||||
auto res_column = ColumnUInt8::create();
|
||||
auto & res_data = res_column->getData();
|
||||
res_data.reserve(input_rows_count);
|
||||
@ -89,12 +88,6 @@ public:
|
||||
boost::geometry::correct(first[i]);
|
||||
boost::geometry::correct(second[i]);
|
||||
|
||||
if constexpr (std::is_same_v<Holder, WithinMercator>)
|
||||
{
|
||||
mercatorForward(first[i]);
|
||||
mercatorForward(second[i]);
|
||||
}
|
||||
|
||||
res_data.emplace_back(boost::geometry::within(first[i], second[i]));
|
||||
}
|
||||
}
|
||||
@ -109,11 +102,18 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
const char * FunctionPolygonsWithin<CartesianPoint>::name = "polygonsWithinCartesian";
|
||||
|
||||
template <>
|
||||
const char * FunctionPolygonsWithin<SphericalPoint>::name = "polygonsWithinSpherical";
|
||||
|
||||
|
||||
void registerFunctionPolygonsWithin(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionPolygonsWithin<WithinCartesian>>();
|
||||
factory.registerFunction<FunctionPolygonsWithin<WithinSpherical>>();
|
||||
factory.registerFunction<FunctionPolygonsWithin<WithinMercator>>();
|
||||
factory.registerFunction<FunctionPolygonsWithin<CartesianPoint>>();
|
||||
factory.registerFunction<FunctionPolygonsWithin<SphericalPoint>>();
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -335,7 +335,6 @@ SRCS(
|
||||
map.cpp
|
||||
match.cpp
|
||||
materialize.cpp
|
||||
mercatorConverters.cpp
|
||||
minus.cpp
|
||||
modulo.cpp
|
||||
moduloOrZero.cpp
|
||||
|
@ -2,6 +2,7 @@
|
||||
1
|
||||
0
|
||||
1
|
||||
<<<<<<< HEAD
|
||||
0
|
||||
1
|
||||
-------- MultiPolygon with Polygon
|
||||
@ -13,3 +14,5 @@
|
||||
-------- Polygon with Polygon with Holes
|
||||
0
|
||||
0
|
||||
=======
|
||||
>>>>>>> parent of d4258922d1... more mercator
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,8 +1,6 @@
|
||||
--------
|
||||
[[[(1,2.9),(1,4),(4,4),(4,1),(2.9,1),(3,0),(0,0),(0,3),(1,2.9)]]]
|
||||
--------
|
||||
--------
|
||||
[[[(4.3666052904432435,50.84337386140151),(4.366227,50.840809),(4.344961,50.833264),(4.338074,50.848677),(4.346693,50.858306),(4.3526804582393535,50.856658100365976),(4.3613577,50.8651821),(4.3613148,50.8651279),(4.3904543,50.8564867),(4.3830299,50.8428851),(4.3666052904432435,50.84337386140151)]]]
|
||||
<<<<<<< HEAD
|
||||
--------
|
||||
[[[(4.366505261795747,50.843273415405),(4.3661270000000005,50.840709),(4.344861,50.83316399999998),(4.337974,50.84857699999999),(4.346593,50.858205999999996),(4.352580404040105,50.85655765067624),(4.3612577,50.86508209999998),(4.361214800000001,50.8650279),(4.3903543,50.85638669999999),(4.382929900000001,50.842785099999986),(4.366505261795747,50.843273415405)]]]
|
||||
-------- MultiPolygon with Polygon
|
||||
@ -14,3 +12,5 @@ MULTIPOLYGON(((24.3676 61.4597,26.6527 61.1007,26.8725 61.7106,30.5639 61.0582,3
|
||||
-------- Polygon with Polygon with Holes
|
||||
MULTIPOLYGON(((24.3677 61.4598,26.6528 61.1008,26.8726 61.7107,30.564 61.0583,31.3989 62.0215,36.0132 61.1432,36.8921 62.0009,42.6489 60.6301,43.5718 61.3757,47.0435 59.8889,49.5923 60.0868,49.1528 58.1707,51.9214 57.9148,50.2515 56.1455,52.6685 55.826,51.6577 54.2909,52.8882 53.9302,50.647 53.0148,51.394 52.4828,48.0542 51.1793,49.2847 50.5414,47.1753 49.153,43.9233 49.8096,42.561 48.7779,36.936 49.6676,35.2661 48.7489,32.8052 49.5252,27.2241 48.9802,26.1255 50.4015,21.2036 50.205,20.0171 51.5634,17.4683 53.0148,19.4458 54.0852,19.4458 55.8753,19.5776 57.4922,19.5776 58.6769,24.3677 61.4598),(24.4556 59.4227,21.2036 58.4937,21.3354 56.897,21.5991 55.9246,25.2026 55.9984,28.8501 57.0646,27.0923 57.8448,28.8062 59.1759,26.2573 59.1759,24.4556 59.4227),(32.6512 57.792,32.9378 57.2699,36.7912 59.6986,35.9475 59.7758,32.6512 57.792),(33.2446 56.7729,34.2635 56.6767,37.6322 58.7797,37.2876 58.7226,37.2102 59.1452,33.2446 56.7729),(36.1815 56.4715,41.168 59.0834,40.9299 59.2404,40.8804 59.2644,40.2079 59.1718,35.4536 56.5531,36.1815 56.4715),(30.7705 55.0525,30.2092 54.6331,30.2394 53.6774,31.5682 54.7333,30.7705 55.0525),(33.8733 53.1922,34.3351 53.53,33.5144 53.9057,32.5603 53.1989,33.8733 53.1922),(31.1968 52.1649,29.7861 52.1466,30.5785 52.7531,30.3098 53.0028,29.3931 52.2763,29.4171 55.606,29.1577 55.7518,22.5659 55.1286,22.5659 53.5403,22.0386 51.4814,26.2573 51.4266,30.1245 50.5414,32.1899 51.1793,31.1968 52.1649),(31.1682 53.1903,32.6907 54.2663,32.2591 54.4483,30.5408 53.1811,31.1682 53.1903),(39.4328 55.9511,37.2766 54.4948,37.7431 53.9104,41.4519 56.3413,39.4328 55.9511),(40.9691 57.677,42.2498 58.3455,41.5887 58.8012,38.1759 56.9472,39.0894 57.2553,40.9691 57.677),(37.1934 55.4694,36.5845 55.3291,36.7219 55.1665,37.1934 55.4694),(32.2964 58.4175,34.2247 59.6064,31.9702 58.9727,32.2964 58.4175),(35.9681 52.2157,34.9585 51.4814,36.5405 50.4015,39.6606 50.2893,39.7925 52.1335,41.77 50.6808,44.4946 51.9713,47.3071 52.5095,44.0552 53.5403,46.604 53.6967,47.6147 55.4041,45.3735 55.4041,44.4212 55.8594,44.4146 55.3097,40.0925 52.1652,38.3395 52.1652,43.0243 55.3269,43.0243 56.2614,37.1608 52.2393,35.9681 52.2157)))
|
||||
MULTIPOLYGON(((24.3676 61.4597,26.6527 61.1007,26.8725 61.7106,30.5639 61.0582,31.3988 62.0214,36.0131 61.1431,36.892 62.0008,42.6488 60.63,43.5717 61.3756,47.0434 59.8888,49.5922 60.0867,49.1527 58.1706,51.9213 57.9147,50.2514 56.1454,52.6684 55.8259,51.6576 54.2908,52.8881 53.9301,50.6469 53.0147,51.3939 52.4827,48.0541 51.1792,49.2846 50.5413,47.1752 49.1529,43.9232 49.8095,42.5609 48.7778,36.9359 49.6675,35.266 48.7488,32.8051 49.5251,27.224 48.9801,26.1254 50.4014,21.2035 50.2049,20.017 51.5633,17.4682 53.0147,19.4457 54.0851,19.4457 55.8752,19.5775 57.4921,19.5775 58.6768,24.3676 61.4597),(24.4555 59.4226,21.2035 58.4936,21.3353 56.8969,21.599 55.9245,25.2025 55.9983,28.85 57.0645,27.0922 57.8447,28.8061 59.1758,26.2572 59.1758,24.4555 59.4226),(32.6773 57.7269,32.9811 57.1783,36.8295 59.693,35.9663 59.7703,32.6773 57.7269),(33.4587 56.7498,34.5347 56.6377,37.9197 58.8184,37.2875 58.7225,37.2249 59.0621,33.4587 56.7498),(36.5672 56.4248,41.1674 59.0793,40.9293 59.24,40.8796 59.2641,40.276 59.1737,35.8287 56.5023,36.5672 56.4248),(30.7975 55.0249,30.2091 54.633,30.2393 53.6773,31.6568 54.6786,30.7975 55.0249),(34.0091 53.173,34.4539 53.4687,33.6753 53.8276,32.7039 53.173,34.0091 53.173),(31.1809 52.1644,29.786 52.1465,30.6237 52.6993,30.3667 52.9437,29.393 52.2762,29.4184 55.6047,29.1576 55.7517,22.5658 55.1285,22.5658 53.5402,22.0385 51.4813,26.2572 51.4265,30.1244 50.5413,32.1898 51.1792,31.1809 52.1644),(31.3501 53.173,32.9056 54.17,32.4672 54.3493,30.7047 53.173,31.3501 53.173),(39.7202 55.9646,37.3607 54.3795,37.8015 53.8302,41.577 56.336,39.7202 55.9646),(41.2147 57.7149,42.2607 58.3313,41.5893 58.7925,38.9459 57.2058,39.0893 57.2552,41.2147 57.7149),(37.6798 55.5522,36.5844 55.329,36.8394 55.0196,37.6798 55.5522),(32.3127 58.3747,34.2648 59.6073,31.9701 58.9726,32.3127 58.3747),(35.9939 52.2136,34.9584 51.4813,36.5404 50.4014,39.6605 50.2892,39.7924 52.1334,41.7699 50.6807,44.4945 51.9712,47.307 52.5094,44.0551 53.5402,46.6039 53.6966,47.6146 55.404,45.3734 55.404,44.4214 55.8488,44.4145 55.3096,40.0924 52.1651,38.3394 52.1651,43.0242 55.3268,43.0242 56.2613,37.1607 52.2392,35.9939 52.2136)))
|
||||
=======
|
||||
>>>>>>> parent of d4258922d1... more mercator
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,9 +1,8 @@
|
||||
--------
|
||||
[[[(1,2.9),(2,2.6),(2.6,2),(2.9,1),(1,1),(1,2.9)]]]
|
||||
[]
|
||||
--------
|
||||
[]
|
||||
[[[(4.3666052904432435,50.84337386140151),(4.3602419,50.8435626),(4.349556,50.8535879),(4.3526804582393535,50.856658100365976),(4.367945,50.852455),(4.3666052904432435,50.84337386140151)]]]
|
||||
<<<<<<< HEAD
|
||||
--------
|
||||
[]
|
||||
[[[(4.366505261795747,50.843273415405),(4.3601419,50.8434626),(4.349456,50.8534879),(4.352580404040105,50.85655765067624),(4.367845,50.85235499999999),(4.366505261795747,50.843273415405)]]]
|
||||
@ -16,3 +15,5 @@ MULTIPOLYGON(((33.106 56.9503,32.9595 56.9433,33.1372 56.8932,33.2006 56.7767,33
|
||||
-------- Polygon with Polygon with Holes
|
||||
MULTIPOLYGON(((32.6512 57.792,30.3301 56.1942,30.2394 55.2753,32.9378 57.2699,33.2007 56.7768,33.2446 56.7729,30.7705 55.0525,29.5972 55.5037,29.4171 55.606,29.4536 59.7796,30.5719 59.9919,30.4812 58.8542,32.3249 59.9465,33.6548 59.9465,30.179 57.9196,30.179 56.9764,32.2964 58.4175,32.6512 57.792)),((35.9475 59.7758,35.1343 59.8448,34.2247 59.6064,34.8637 59.9768,36.2843 59.9616,35.9475 59.7758)),((36.7912 59.6986,37.2817 59.9768,38.7325 59.9465,37.2102 59.1452,37.1118 59.6677,36.7912 59.6986)),((34.2635 56.6767,35.4536 56.5531,32.2591 54.4483,31.5682 54.7333,34.2635 56.6767)),((36.1815 56.4715,36.6724 56.4139,38.1759 56.9472,33.5144 53.9057,33.1128 54.0852,32.6907 54.2663,36.1815 56.4715)),((33.8733 53.1922,35.0903 53.1731,34.3351 53.53,36.7219 55.1665,37.2766 54.4948,34.2895 52.2208,32.5969 52.2208,33.8733 53.1922)),((31.1968 52.1649,30.5785 52.7531,31.1682 53.1903,32.5603 53.1989,31.2368 52.1652,31.1968 52.1649)),((30.3098 53.0028,30.1245 53.1731,30.5408 53.1811,30.3098 53.0028)),((37.6322 58.7797,39.7299 59.9314,44.4751 59.81,44.4212 55.8594,42.8247 56.5837,41.4519 56.3413,43.0243 57.2554,43.0243 58.0797,39.4328 55.9511,37.1934 55.4694,40.9691 57.677,42.6929 58.0314,42.2498 58.3455,42.5105 58.477,41.6944 58.8542,41.5887 58.8012,41.168 59.0834,41.2108 59.1035,40.9299 59.2404,40.8911 59.2659,40.8804 59.2644,40.6366 59.3817,40.2079 59.1718,37.6322 58.7797)),((35.9681 52.2157,35.4682 52.2022,37.7431 53.9104,37.9907 53.5925,35.9681 52.2157)))
|
||||
MULTIPOLYGON(((32.6773 57.7269,30.33 56.1941,30.2393 55.2752,32.9811 57.1783,33.2006 56.7767,33.4587 56.7498,30.7975 55.0249,29.5971 55.5036,29.4184 55.6047,29.4535 59.7795,30.5718 59.9918,30.4811 58.8541,32.3248 59.9464,33.6547 59.9464,30.1789 57.9195,30.1789 56.9763,32.3127 58.3747,32.6773 57.7269)),((35.9663 59.7703,35.1342 59.8447,34.2648 59.6073,34.8636 59.9767,36.2842 59.9615,35.9663 59.7703)),((36.8295 59.693,37.2816 59.9767,38.7324 59.9464,37.2249 59.0621,37.1117 59.6676,36.8295 59.693)),((34.5347 56.6377,35.8287 56.5023,32.4672 54.3493,31.6568 54.6786,34.5347 56.6377)),((36.5672 56.4248,36.6723 56.4138,38.9459 57.2058,33.6753 53.8276,33.1127 54.0851,32.9056 54.17,36.5672 56.4248)),((34.0091 53.173,35.0902 53.173,34.4539 53.4687,36.8394 55.0196,37.3607 54.3795,34.2894 52.2207,32.5968 52.2207,34.0091 53.173)),((31.1809 52.1644,30.6237 52.6993,31.3501 53.173,32.7039 53.173,31.2367 52.1651,31.1809 52.1644)),((30.3667 52.9437,30.1244 53.173,30.7047 53.173,30.3667 52.9437)),((37.9197 58.8184,39.7298 59.9313,44.475 59.8099,44.4214 55.8488,42.8246 56.5836,41.577 56.336,43.0242 57.2553,43.0242 58.0796,39.7202 55.9646,37.6798 55.5522,41.2147 57.7149,42.6928 58.0313,42.2607 58.3313,42.5104 58.4769,41.6943 58.8541,41.5893 58.7925,41.1674 59.0793,41.2107 59.1034,40.9293 59.24,40.891 59.2658,40.8796 59.2641,40.6365 59.3816,40.276 59.1737,37.9197 58.8184)),((35.9939 52.2136,35.4681 52.2021,37.8015 53.8302,37.9906 53.5924,35.9939 52.2136)))
|
||||
=======
|
||||
>>>>>>> parent of d4258922d1... more mercator
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user