Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions be/src/geo/geo_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ enum GeoParseStatus {
GEO_PARSE_POLYGON_NOT_HOLE = 5,
GEO_PARSE_POLYLINE_LACK_VERTICES = 6,
GEO_PARSE_POLYLINE_INVALID = 7,
GEO_PARSE_CIRCLE_INVALID = 8,
GEO_PARSE_WKT_SYNTAX_ERROR = 9,
GEO_PARSE_WKB_SYNTAX_ERROR = 10,
GEO_PARSE_MULTIPOLYGON_OVERLAP = 8,
GEO_PARSE_CIRCLE_INVALID = 9,
GEO_PARSE_WKT_SYNTAX_ERROR = 10,
GEO_PARSE_WKB_SYNTAX_ERROR = 11,
};

std::string to_string(GeoParseStatus status);
Expand Down
442 changes: 415 additions & 27 deletions be/src/geo/geo_types.cpp

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions be/src/geo/geo_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <memory>
#include <string>
#include <vector>

#include "common/factory_creator.h"
#include "geo/geo_common.h"
Expand Down Expand Up @@ -152,6 +153,7 @@ class GeoLine : public GeoShape {

class GeoPolygon : public GeoShape {
ENABLE_FACTORY_CREATOR(GeoPolygon);
friend class GeoMultiPolygon;

public:
GeoPolygon();
Expand Down Expand Up @@ -185,6 +187,36 @@ class GeoPolygon : public GeoShape {
std::unique_ptr<S2Polygon> _polygon;
};

class GeoMultiPolygon : public GeoShape {
ENABLE_FACTORY_CREATOR(GeoMultiPolygon);

public:
GeoMultiPolygon();
~GeoMultiPolygon() override;

GeoParseStatus check_self_intersection();
GeoParseStatus from_coords(const std::vector<GeoCoordinateListList>& list);
const std::vector<std::unique_ptr<GeoCoordinateListList>> to_coords() const;

GeoShapeType type() const override { return GEO_SHAPE_MULTI_POLYGON; }
const std::vector<std::unique_ptr<GeoPolygon>>& polygons() const { return _polygons; }

bool intersects(const GeoShape* rhs) const override;
bool disjoint(const GeoShape* rhs) const override;
bool touches(const GeoShape* rhs) const override;
bool contains(const GeoShape* rhs) const override;
std::string as_wkt() const override;

double getArea() const;

protected:
void encode(std::string* buf) override;
bool decode(const void* data, size_t size) override;

private:
std::vector<std::unique_ptr<GeoPolygon>> _polygons;
};

class GeoCircle : public GeoShape {
ENABLE_FACTORY_CREATOR(GeoCircle);

Expand Down
2 changes: 2 additions & 0 deletions be/src/geo/wkt_parse_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct GeoCoordinateListList {
delete item;
}
}
GeoCoordinateListList() = default;
GeoCoordinateListList(GeoCoordinateListList&& other) : list(std::move(other.list)) {}
void add(GeoCoordinateList* coordinates) { list.push_back(coordinates); }
std::vector<GeoCoordinateList*> list;
};
Expand Down
37 changes: 36 additions & 1 deletion be/src/geo/wkt_yacc.y
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void wkt_error(WktParseContext* ctx, const char* msg) {
doris::GeoCoordinate coordinate_value;
doris::GeoCoordinateList* coordinate_list_value;
doris::GeoCoordinateListList* coordinate_list_list_value;
std::vector<doris::GeoCoordinateListList>* multi_polygon_value;
doris::GeoShape* shape_value;
}

Expand Down Expand Up @@ -67,16 +68,19 @@ void wkt_error(WktParseContext* ctx, const char* msg) {
%token <double_value> NUMERIC

%type <None> shape
%type <shape_value> point linestring polygon
%type <shape_value> point linestring polygon multi_polygon
%type <coordinate_value> coordinate
%type <coordinate_list_value> coordinate_list
%type <coordinate_list_list_value> coordinate_list_list
%type <multi_polygon_value> multi_polygon_list

%destructor { delete $$; } coordinate_list
%destructor { delete $$; } coordinate_list_list
%destructor { delete $$; } point
%destructor { delete $$; } linestring
%destructor { delete $$; } polygon
%destructor { delete $$; } multi_polygon
%destructor { delete $$; } multi_polygon_list

%%

Expand All @@ -87,6 +91,8 @@ shape:
{ ctx->shape = $1; }
| polygon
{ ctx->shape = $1; }
| multi_polygon
{ ctx->shape = $1; }
;

point:
Expand Down Expand Up @@ -129,6 +135,35 @@ polygon:
}
;

multi_polygon:
KW_MULTI_POLYGON '(' multi_polygon_list ')'
{
// to avoid memory leak
std::unique_ptr<std::vector<doris::GeoCoordinateListList>> list($3);
std::unique_ptr<doris::GeoMultiPolygon> multi_polygon = doris::GeoMultiPolygon::create_unique();
ctx->parse_status = multi_polygon->from_coords(*$3);
if (ctx->parse_status != doris::GEO_PARSE_OK) {
YYABORT;
}
$$ = multi_polygon.release();
}
;

multi_polygon_list:
multi_polygon_list ',' '(' coordinate_list_list ')'
{
$1->push_back(std::move(*$4));
delete $4;
$$ = $1;
}
| '(' coordinate_list_list ')'
{
$$ = new std::vector<doris::GeoCoordinateListList>();
$$->push_back(std::move(*$2));
delete $2;
}
;

coordinate_list_list:
coordinate_list_list ',' '(' coordinate_list ')'
{
Expand Down
Loading
Loading