[CP][FEAT MERGE]SDO_GEOMETRY & MYSQL GIS EXPR IMPLEMENT
This commit is contained in:
@ -20,6 +20,13 @@
|
||||
#include "lib/geo/ob_geo_bin_traits.h"
|
||||
#include "lib/json_type/ob_json_common.h"
|
||||
#include "lib/random/ob_random.h"
|
||||
#include "lib/geo/ob_geo_utils.h"
|
||||
#include "lib/geo/ob_geo_box_clip_visitor.h"
|
||||
#include "lib/geo/ob_geo_to_tree_visitor.h"
|
||||
#include "lib/geo/ob_geo_to_wkt_visitor.h"
|
||||
#include "sql/engine/expr/ob_geo_expr_utils.h"
|
||||
#include "lib/geo/ob_wkt_parser.h"
|
||||
#include "lib/geo/ob_geo_common.h"
|
||||
#undef private
|
||||
|
||||
#include <sys/time.h>
|
||||
@ -624,7 +631,304 @@ TEST_F(TestGeoTree, intersection_op)
|
||||
}
|
||||
}
|
||||
|
||||
void wkt_to_tree_geo(const ObString &wkt, ObArenaAllocator &allocator, ObGeometry *&geo_tree)
|
||||
{
|
||||
ObGeometry *geo = nullptr;
|
||||
ASSERT_EQ(ObWktParser::parse_wkt(allocator, wkt, geo, true, false), OB_SUCCESS);
|
||||
ObGeoToTreeVisitor tree_visitor(&allocator);
|
||||
ASSERT_EQ(geo->do_visit(tree_visitor), OB_SUCCESS);
|
||||
geo_tree = tree_visitor.get_geometry();
|
||||
}
|
||||
|
||||
void tree_geo_to_wkt(ObArenaAllocator &allocator, ObGeometry *geo_tree, ObString &wkt_cal)
|
||||
{
|
||||
bool is_geo_empty = false;
|
||||
ASSERT_EQ(sql::ObGeoExprUtils::check_empty(geo_tree, is_geo_empty), OB_SUCCESS);
|
||||
if (is_geo_empty) {
|
||||
wkt_cal = "EMPTY";
|
||||
} else {
|
||||
ObGeometry *geo_bin = NULL;
|
||||
ASSERT_EQ(ObGeoTypeUtil::tree_to_bin(allocator, geo_tree, geo_bin, nullptr), OB_SUCCESS);
|
||||
ObGeoToWktVisitor visitor(&allocator);
|
||||
ASSERT_EQ(geo_bin->do_visit(visitor), OB_SUCCESS);
|
||||
visitor.get_wkt(wkt_cal);
|
||||
}
|
||||
}
|
||||
|
||||
void clip_visitor_test(const ObString &wkt, const ObString &wkt_res, ObGeogBox &box)
|
||||
{
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObGeometry *geo_tree = nullptr;
|
||||
wkt_to_tree_geo(wkt, allocator, geo_tree);
|
||||
|
||||
ObGeometry *geo_res = nullptr;
|
||||
ObGeoBoxClipVisitor clip_visitor(box, allocator);
|
||||
ASSERT_EQ(geo_tree->do_visit(clip_visitor), OB_SUCCESS);
|
||||
ASSERT_EQ(clip_visitor.get_geometry(geo_res), OB_SUCCESS);
|
||||
ASSERT_EQ(geo_res == nullptr, false);
|
||||
|
||||
ObString wkt_cal;
|
||||
tree_geo_to_wkt(allocator, geo_res, wkt_cal);
|
||||
ASSERT_EQ(wkt_cal == wkt_res, true);
|
||||
}
|
||||
|
||||
TEST_F(TestGeoTree, clip_visitor)
|
||||
{
|
||||
ObGeogBox box1 = {0, 10, 0, 10, 0, 0};
|
||||
// linestring
|
||||
clip_visitor_test("LINESTRING(1 1,1 9,9 9,9 1)", "LINESTRING(1 1,1 9,9 9,9 1)", box1);
|
||||
clip_visitor_test("LINESTRING(-1 -9,-1 11,9 11)", "EMPTY", box1);
|
||||
clip_visitor_test("LINESTRING(-1 5,5 5,9 9)", "LINESTRING(0 5,5 5,9 9)", box1);
|
||||
clip_visitor_test("LINESTRING(5 5,8 5,12 5)", "LINESTRING(5 5,8 5,10 5)", box1);
|
||||
clip_visitor_test("LINESTRING(5 -1,5 5,1 2,-3 2,1 6)", "MULTILINESTRING((5 0,5 5,1 2,0 2),(0 5,1 6))", box1);
|
||||
clip_visitor_test("LINESTRING(0 3,0 5,0 7)", "EMPTY", box1);
|
||||
clip_visitor_test("LINESTRING(0 3,0 5,-1 7)", "EMPTY", box1);
|
||||
clip_visitor_test("LINESTRING(0 3,0 5,2 7)", "LINESTRING(0 5,2 7)", box1);
|
||||
clip_visitor_test("LINESTRING(2 1,0 0,1 2)", "LINESTRING(2 1,0 0,1 2)", box1);
|
||||
clip_visitor_test("LINESTRING(3 3,0 3,0 5,2 7)", "MULTILINESTRING((3 3,0 3),(0 5,2 7))", box1);
|
||||
clip_visitor_test("LINESTRING(5 5,10 5,20 5)", "LINESTRING(5 5,10 5)", box1);
|
||||
clip_visitor_test("LINESTRING(3 3,0 6,3 9)", "LINESTRING(3 3,0 6,3 9)", box1);
|
||||
clip_visitor_test("LINESTRING(-1 -1,3 1,3 3,-1 -1)", "LINESTRING(1 0,3 1,3 3,0 0)", box1);
|
||||
|
||||
// polygon
|
||||
clip_visitor_test("POLYGON((5 5,5 6,6 6,6 5,5 5))", "POLYGON((5 5,5 6,6 6,6 5,5 5))", box1);
|
||||
clip_visitor_test("POLYGON((15 15,15 16,16 16,16 15,15 15))", "EMPTY", box1);
|
||||
clip_visitor_test("POLYGON((-1 -1,-1 11,11 11,11 -1,-1 -1))", "POLYGON((0 0,0 10,10 10,10 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((-1 -1,-1 5,5 5,5 -1,-1 -1))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((-2 -2,-2 5,5 5,5 -2,-2 -2), (3 3,4 4,4 2,3 3))", "POLYGON((0 0,0 5,5 5,5 0,0 0),(3 3,4 4,4 2,3 3))", box1);
|
||||
clip_visitor_test("POLYGON((-2 -2,-2 5,5 5,5 -2,-2 -2), (-1 -1,3 1,3 3,-1 -1))",
|
||||
"POLYGON((0 0,0 5,5 5,5 0,1 0,3 1,3 3,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((0 0,10 0,5 10,0 0))", "POLYGON((0 0,5 10,10 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((5 10,0 0,10 0,5 10))", "POLYGON((0 0,5 10,10 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((-5 -5,5 5,5 -5,-5 -5))", "POLYGON((0 0,5 5,5 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((0 0,0 10,10 10,0 0))", "POLYGON((0 0,0 10,10 10,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((0 5,0 10,10 10,0 5))", "POLYGON((0 5,0 10,10 10,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((0 10,10 10,5 0,0 10))", "POLYGON((0 10,10 10,5 0,0 10))", box1);
|
||||
clip_visitor_test("POLYGON((0 10,10 10,5 5,0 10))", "POLYGON((0 10,10 10,5 5,0 10))", box1);
|
||||
clip_visitor_test("POLYGON((0 10,5 10,0 5,0 10))", "POLYGON((0 5,0 10,5 10,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((0 10,10 5,0 5,0 10))", "POLYGON((0 5,0 10,10 5,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((0 10,10 0,0 5,0 10))", "POLYGON((0 5,0 10,10 0,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((0 10,5 0,0 5,0 10))", "POLYGON((0 5,0 10,5 0,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((0 10,5 5,0 5,0 10))", "POLYGON((0 5,0 10,5 5,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((0 10,7 7,3 3,0 10))", "POLYGON((0 10,7 7,3 3,0 10))", box1);
|
||||
clip_visitor_test("POLYGON((0 10,5 5,5 0,0 10))", "POLYGON((0 10,5 5,5 0,0 10))", box1);
|
||||
clip_visitor_test("POLYGON((0 10,10 5,5 0,0 10))", "POLYGON((0 10,10 5,5 0,0 10))", box1);
|
||||
clip_visitor_test("POLYGON((2 5,5 10,7 5,2 5))",
|
||||
"POLYGON((2 5,5 10,7 5,2 5))", box1);
|
||||
clip_visitor_test("POLYGON((0 5,5 10,5 5,0 5))",
|
||||
"POLYGON((0 5,5 10,5 5,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((0 5,5 10,10 5,0 5))",
|
||||
"POLYGON((0 5,5 10,10 5,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((0 5,5 7,10 5,0 5))",
|
||||
"POLYGON((0 5,5 7,10 5,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((-5 10,0 15,0 10,-5 10))", "EMPTY", box1);
|
||||
clip_visitor_test("POLYGON((-5 10,0 5,-5 0,-5 10))", "EMPTY", box1);
|
||||
clip_visitor_test("POLYGON((-5 5,0 10,0 0,-5 5))", "EMPTY", box1);
|
||||
clip_visitor_test("POLYGON((-5 5,0 10,0 5,-5 5))", "EMPTY", box1);
|
||||
clip_visitor_test("POLYGON((-5 5,0 7,0 3,-5 5))", "EMPTY", box1);
|
||||
clip_visitor_test("POLYGON((5 5,-5 0,-5 10,5 5))",
|
||||
"POLYGON((0 2.5,0 7.5,5 5,0 2.5))", box1);
|
||||
clip_visitor_test("POLYGON((5 0,-5 0,-5 10,5 0))",
|
||||
"POLYGON((0 0,0 5,5 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((10 0,-10 0,-10 10,10 0))",
|
||||
"POLYGON((0 0,0 5,10 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((5 0,-5 5,-5 10,5 0))",
|
||||
"POLYGON((0 2.5,0 5,5 0,0 2.5))", box1);
|
||||
clip_visitor_test("POLYGON((10 5,-10 0,-10 10,10 5))",
|
||||
"POLYGON((0 2.5,0 7.5,10 5,0 2.5))", box1);
|
||||
clip_visitor_test("POLYGON((10 10,-10 0,-10 5,10 10))",
|
||||
"POLYGON((0 5,0 7.5,10 10,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((5 5,-5 -5,-5 15,5 5))",
|
||||
"POLYGON((0 0,0 10,5 5,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((10 5,-10 -5,-10 15,10 5))",
|
||||
"POLYGON((0 0,0 10,10 5,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((5 0,-5 0,-5 20,5 0))",
|
||||
"POLYGON((0 0,0 10,5 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((10 0,-10 0,-10 20,10 0))",
|
||||
"POLYGON((0 0,0 10,10 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((5 5,-10 5,0 15,5 5))",
|
||||
"POLYGON((0 5,0 10,2.5 10,5 5,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((5 5,-5 -5,0 15,5 5))",
|
||||
"POLYGON((0 0,0 10,2.5 10,5 5,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((5 5,-15 -20,-15 30,5 5))",
|
||||
"POLYGON((0 0,0 10,1 10,5 5,1 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((5 7,5 3,-5 5,5 7))",
|
||||
"POLYGON((0 4,0 6,5 7,5 3,0 4))", box1);
|
||||
clip_visitor_test("POLYGON((5 7,5 3,-5 13,5 7))",
|
||||
"POLYGON((0 8,0 10,5 7,5 3,0 8))", box1);
|
||||
clip_visitor_test("POLYGON((6 6,4 4,-4 14,6 6))",
|
||||
"POLYGON((0 9,0 10,1.0000000000000007 10,6 6,4 4,0 9))", box1);
|
||||
clip_visitor_test("POLYGON((-2 -2,-2 12,12 12,12 -2,-2 -2),(-1 -1,11 -1,11 11,-1 11,-1 -1))",
|
||||
"EMPTY", box1);
|
||||
clip_visitor_test("POLYGON((-2 -2,-2 12,12 12,12 -2,-2 -2),(1 1,9 1,9 9,1 9,1 1))",
|
||||
"POLYGON((0 0,0 10,10 10,10 0,0 0),(1 1,9 1,9 9,1 9,1 1))", box1);
|
||||
clip_visitor_test("POLYGON((5 5,15 5,15 -5,5 -5,5 5),(8 1,8 -1,9 -1,9 1,8 1))",
|
||||
"POLYGON((5 0,5 5,10 5,10 0,9 0,9 1,8 1,8 0,5 0))", box1);
|
||||
clip_visitor_test("POLYGON((-6 5,5 5,5 -6,-6 5))",
|
||||
"POLYGON((0 0,0 5,5 5,5 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((-15 -15,-15 15,15 15,15 -15,-15 -15),(-5 5,-5 -5,5 -5,5 5,-5 5))",
|
||||
"POLYGON((0 5,0 10,10 10,10 0,5 0,5 5,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((-15 -15,-15 15,15 15,15 -15,-15 -15),(-6 5,5 -6,5 5,-6 5))",
|
||||
"POLYGON((0 5,0 10,10 10,10 0,5 0,5 5,0 5))", box1);
|
||||
clip_visitor_test("POLYGON((-15 -15,-15 15,15 15,15 -15,-15 -15),(-5 5,-6 5,-6 6,-5 6,-5 5))",
|
||||
"POLYGON((0 0,0 10,10 10,10 0,0 0))", box1);
|
||||
clip_visitor_test("POLYGON((-15 -15,-15 15,15 15,15 -15,-15 -15),(0 5,-1 5,-1 6,0 6,0 5))",
|
||||
"POLYGON((0 0,0 10,10 10,10 0,0 0))", box1);
|
||||
ObGeogBox box2 = {10, 100, 10, 100, 0, 0};
|
||||
clip_visitor_test("POLYGON((50 50,200 50,200 200,50 200,50 50))", // CCW
|
||||
"POLYGON((50 50,50 100,100 100,100 50,50 50))", box2);
|
||||
clip_visitor_test("POLYGON((50 50,50 200,200 200,200 50,50 50))", // CW
|
||||
"POLYGON((50 50,50 100,100 100,100 50,50 50))", box2);
|
||||
// box1
|
||||
clip_visitor_test("POLYGON("
|
||||
"(-10 2,-10 8,8 8,8 2,-10 2)," // CW
|
||||
"(-5 6,-5 4,5 4,5 6,-5 6)" // CCW
|
||||
")",
|
||||
"POLYGON((0 2,0 4,5 4,5 6,0 6,0 8,8 8,8 2,0 2))", box1);
|
||||
clip_visitor_test("POLYGON("
|
||||
"(-10 2,-10 8,8 8,8 2,-10 2)," // CW
|
||||
"(-5 6,5 6,5 4,-5 4,-5 6)" // CW
|
||||
")",
|
||||
"POLYGON((0 2,0 4,5 4,5 6,0 6,0 8,8 8,8 2,0 2))", box1);
|
||||
clip_visitor_test("POLYGON("
|
||||
"(-10 2,8 2,8 8,-10 8,-10 2)," // CCW
|
||||
"(-5 6,5 6,5 4,-5 4,-5 6)" // CW
|
||||
")",
|
||||
"POLYGON((0 2,0 4,5 4,5 6,0 6,0 8,8 8,8 2,0 2))", box1);
|
||||
clip_visitor_test("POLYGON("
|
||||
"(-10 -10,-10 20,20 20,20 -10,-10 -10)," // CW
|
||||
"(-5 -5,0 -5,0 0,-5 0,-5 -5)" // CCW
|
||||
")",
|
||||
"POLYGON((0 0,0 10,10 10,10 0,0 0))", box1);
|
||||
ObGeogBox box3 = {3.0481343214686657e-14, 20000000.000000, -20000000.000000, -1.000000, 0, 0};
|
||||
clip_visitor_test("POLYGON((3.0481343214686657e-14 -20000000, 200000000 -20000000, 200000000 -1, 3.0481343214686657e-14 -1, 3.0481343214686657e-14 -20000000))",
|
||||
"POLYGON((0.000000000000030481343214686657 -20000000,0.000000000000030481343214686657 -1,20000000 -1,20000000 -20000000,0.000000000000030481343214686657 -20000000))", box3);
|
||||
// EMPTY
|
||||
clip_visitor_test("GEOMETRYCOLLECTION EMPTY", "EMPTY", box1);
|
||||
}
|
||||
|
||||
void affine_visitor_test(const ObString &wkt, const ObString &wkt_res, ObAffineMatrix &affine)
|
||||
{
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObGeometry *geo_tree = nullptr;
|
||||
wkt_to_tree_geo(wkt, allocator, geo_tree);
|
||||
ASSERT_EQ(ObGeoMVTUtil::affine_transformation(geo_tree, affine), OB_SUCCESS);
|
||||
|
||||
ObString wkt_cal;
|
||||
tree_geo_to_wkt(allocator, geo_tree, wkt_cal);
|
||||
ASSERT_EQ(wkt_cal == wkt_res, true);
|
||||
}
|
||||
|
||||
TEST_F(TestGeoTree, affine_visitor)
|
||||
{
|
||||
ObAffineMatrix affine = {1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 4096, 0};
|
||||
affine_visitor_test("MULTILINESTRING((1 1, 501 501, 1001 1001),(2 2, 502 502, 1002 1002))",
|
||||
"MULTILINESTRING((1 4095,501 3595,1001 3095),(2 4094,502 3594,1002 3094))", affine);
|
||||
affine_visitor_test("POLYGON ((0 0, 10 0, 10 5, 0 -5, 0 0))",
|
||||
"POLYGON((0 4096,10 4096,10 4091,0 4101,0 4096))", affine);
|
||||
ObAffineMatrix affine2 = {1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 100, 0};
|
||||
affine_visitor_test("LINESTRING(0 0, 2 20, -2 40, -4 60, 4 80, 0 100)",
|
||||
"LINESTRING(0 100,2 80,-2 60,-4 40,4 20,0 0)", affine2);
|
||||
ObAffineMatrix affine3 = {1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 10, 0};
|
||||
affine_visitor_test("POLYGON((10 10, 10 0, 0 0, 0 10, 10 10),(9 9, 1 9, 1 1, 9 1, 9 9),(8 8, 8 2, 2 2, 2 8, 8 8),(7 7, 7 3, 3 3, 3 7, 7 7))",
|
||||
"POLYGON((10 0,10 10,0 10,0 0,10 0),(9 1,1 1,1 9,9 9,9 1),(8 2,8 8,2 8,2 2,8 2),(7 3,7 7,3 7,3 3,7 3))", affine3);
|
||||
// POLYGON((-8231396.69199339 4979982.17443372,-8231396.69199339 4980355.83678553,-8231365.02893734 4980355.83678553,-8231365.02893734 4979982.17443372,-8231396.69199339 4979982.17443372))
|
||||
ObAffineMatrix affine4 = {0.41539995335806329, 0, 0, 0, -0.41539995335802404, 0, 0, 0, 1, 3422112.7441855143, 2068718.1395343679, 0};
|
||||
affine_visitor_test("MULTIPOLYGON(((-8231365.02893734 4980355.83678553,-8231394.82332406 4980186.31880185,-8231367.43081065 4979982.17443372,-8231396.69199339 4980227.59327083,-8231365.02893734 4980355.83678553)))",
|
||||
"MULTIPOLYGON(((2804.095091749914 -121.44277270394377,2791.718504895922 -51.02501018997282,2803.097353688907 33.77655080938712,2790.942259743344 -68.17042267904617,2804.095091749914 -121.44277270394377)))", affine4);
|
||||
}
|
||||
|
||||
void grid_visitor_test(const ObString &wkt, const ObString &wkt_res, double size)
|
||||
{
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObGeometry *geo_tree = nullptr;
|
||||
wkt_to_tree_geo(wkt, allocator, geo_tree);
|
||||
|
||||
ObGeoGrid grid = {0, 0, 0, 0, 0, 0};
|
||||
grid.x_size = grid.y_size = size;
|
||||
ASSERT_EQ(ObGeoMVTUtil::snap_to_grid(geo_tree, grid, false), OB_SUCCESS);
|
||||
|
||||
ObString wkt_cal;
|
||||
tree_geo_to_wkt(allocator, geo_tree, wkt_cal);
|
||||
ASSERT_EQ(wkt_cal == wkt_res, true);
|
||||
}
|
||||
|
||||
TEST_F(TestGeoTree, grid_visitor)
|
||||
{
|
||||
grid_visitor_test("LINESTRING(0 100,2 80,-2 60,-4 40,4 20,0 0)",
|
||||
"LINESTRING(0 100,2 80,-2 60,-4 40,4 20,0 0)", 1);
|
||||
grid_visitor_test("LINESTRING(0 0,1 1,2 2,3 3,4 4,5 5)", "LINESTRING(0 0,2 2,4 4)", 2);
|
||||
grid_visitor_test("POINT(5.1423999999 5.1423999999)", "POINT(5.1424 5.1424)", 0.0001);
|
||||
grid_visitor_test("POINT(5 5)", "POINT(0 0)", 20);
|
||||
grid_visitor_test("MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)))", "EMPTY", 20);
|
||||
// different from PG, PG keeps duplicate point in multipoint
|
||||
grid_visitor_test("MULTIPOINT(0 0,1 1, 2 2, 3 3, 4 4, 5 5)", "MULTIPOINT((0 0),(2 2),(4 4))", 2);
|
||||
grid_visitor_test("MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4, 4 5, 5 5, 5 4, 4 4)))",
|
||||
"MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)))", 2);
|
||||
grid_visitor_test("MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4, 4 5, 5 5, 5 4, 4 4)))",
|
||||
"EMPTY", 20);
|
||||
grid_visitor_test("MULTIPOLYGON(((2804.095091749914 -121.44277270394377,2791.718504895922 -51.02501018997282,2803.097353688907 33.77655080938712,2790.942259743344 -68.17042267904617,2804.095091749914 -121.44277270394377)))",
|
||||
"MULTIPOLYGON(((2804 -121,2792 -51,2803 34,2791 -68,2804 -121)))", 1);
|
||||
}
|
||||
|
||||
void simplify_visitor_test(const ObString &wkt, const ObString &wkt_res, double tolerance, bool keep_collapsed)
|
||||
{
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObGeometry *geo_tree = nullptr;
|
||||
wkt_to_tree_geo(wkt, allocator, geo_tree);
|
||||
|
||||
ASSERT_EQ(ObGeoMVTUtil::simplify_geometry(geo_tree, tolerance, keep_collapsed), OB_SUCCESS);
|
||||
|
||||
ObString wkt_cal;
|
||||
tree_geo_to_wkt(allocator, geo_tree, wkt_cal);
|
||||
ASSERT_EQ(wkt_cal == wkt_res, true);
|
||||
}
|
||||
|
||||
TEST_F(TestGeoTree, simplify_visitor)
|
||||
{
|
||||
simplify_visitor_test("POLYGON((10 0,10 10,0 10,0 0,10 0),(9 1,1 1,1 9,9 9,9 1),(8 2,8 8,2 8,2 2,8 2),(7 3,7 7,3 7,3 3,7 3))",
|
||||
"POLYGON((10 0,10 10,0 10,0 0,10 0),(9 1,1 1,1 9,9 9,9 1),(8 2,8 8,2 8,2 2,8 2),(7 3,7 7,3 7,3 3,7 3))", 0, false);
|
||||
simplify_visitor_test("MULTILINESTRING((1 4095,501 3595,1001 3095),(2 4094,502 3594,1002 3094))",
|
||||
"MULTILINESTRING((1 4095,1001 3095),(2 4094,1002 3094))", 0, false);
|
||||
simplify_visitor_test("LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)", "LINESTRING(0 0,0 0)", 10, true);
|
||||
simplify_visitor_test("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", "POLYGON((0 0,1 0,1 1,0 0))", 10, true);
|
||||
simplify_visitor_test("LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)", "EMPTY", 10, false);
|
||||
simplify_visitor_test("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", "EMPTY", 10, false);
|
||||
simplify_visitor_test("LINESTRING(0 0, 50 1.00001, 100 0)", "LINESTRING(0 0,50 1.00001,100 0)", 1, false);
|
||||
simplify_visitor_test("LINESTRING(0 0,50 0.99999,100 0)", "LINESTRING(0 0,100 0)", 1, false);
|
||||
simplify_visitor_test("POLYGON("
|
||||
"(0 0, 100 0, 100 100, 0 100, 0 0),"
|
||||
"(1 1, 1 5, 5 5, 5 1, 1 1),"
|
||||
"(20 20, 20 40, 40 40, 40 20, 20 20)"
|
||||
")", "POLYGON((0 0,100 0,100 100,0 100,0 0),(20 20,20 40,40 40,40 20,20 20))", 10, false);
|
||||
simplify_visitor_test("POLYGON("
|
||||
"(0 0, 100 0, 100 100, 0 100, 0 0),"
|
||||
"(20 20, 20 40, 40 40, 40 20, 20 20),"
|
||||
"(1 1, 1 5, 5 5, 5 1, 1 1)"
|
||||
")", "POLYGON((0 0,100 0,100 100,0 100,0 0),(20 20,20 40,40 40,40 20,20 20))", 10, false);
|
||||
simplify_visitor_test("POLYGON("
|
||||
"(0 0, 100 0, 100 100, 0 100, 0 0),"
|
||||
"(20 20, 20 40, 40 40, 40 20, 20 20),"
|
||||
"(1 1, 1 5, 5 5, 5 1, 1 1)"
|
||||
")", "EMPTY", 100, false);
|
||||
}
|
||||
|
||||
TEST_F(TestGeoTree, ewkt_with_null)
|
||||
{
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObGeometry *geo_tree = nullptr;
|
||||
wkt_to_tree_geo("POINT(1 1)", allocator, geo_tree);
|
||||
geo_tree->set_srid(UINT32_MAX);
|
||||
ObGeometry *geo_bin = NULL;
|
||||
ASSERT_EQ(ObGeoTypeUtil::tree_to_bin(allocator, geo_tree, geo_bin, nullptr), OB_SUCCESS);
|
||||
ObWkbBuffer buffer(allocator);
|
||||
ASSERT_EQ(buffer.append(static_cast<uint32_t>(UINT32_MAX)), OB_SUCCESS);
|
||||
ASSERT_EQ(buffer.append(geo_bin->val(), geo_bin->length()), OB_SUCCESS);
|
||||
ObString wkt_cal;
|
||||
ASSERT_EQ(ObGeoTypeUtil::geo_to_ewkt(buffer.string(), wkt_cal, allocator, 14), OB_SUCCESS);
|
||||
ObString wkt_res = "SRID=NULL;POINT(1 1)";
|
||||
ASSERT_EQ(wkt_cal == wkt_res, true);
|
||||
}
|
||||
|
||||
} // namespace common
|
||||
} // namespace oceanbase
|
||||
@ -632,5 +936,8 @@ TEST_F(TestGeoTree, intersection_op)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
// system("rm -f test_geo_tree.log");
|
||||
// OB_LOGGER.set_file_name("test_geo_tree.log");
|
||||
OB_LOGGER.set_log_level("DEBUG");
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
Reference in New Issue
Block a user