github-actions[bot] commented on code in PR #22933: URL: https://github.com/apache/doris/pull/22933#discussion_r1293072968
########## be/src/geo/util/GeoCircle.h: ########## @@ -0,0 +1,57 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCIRCLE_H +#define DORIS_GEOCIRCLE_H + +#include "GeoPoint.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +class S2Cap; + +namespace doris { +class GeoCircle : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCircle); + +public: + GeoCircle(); + ~GeoCircle() override; + + GeoParseStatus to_s2cap(double lng, double lat, double radius); + + GeoShapeType type() const override { return GEO_SHAPE_CIRCLE; } Review Comment: warning: function 'type' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] GeoShapeType type() const override { return GEO_SHAPE_CIRCLE; } ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; + std::size_t num_point = 0; + for (const auto& g : geometries) { + num_point += g->get_num_point(); + } + return num_point; +} + +std::unique_ptr<GeoShape> GeoCollection::boundary() const { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (is_empty()) { + collection->set_empty(); + return collection; + } + + for (const auto& g : geometries) { + std::unique_ptr<GeoShape> shape = g->boundary(); + if (!shape->is_empty()) collection->add_one_geometry(shape.release()); Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion if (!shape->is_empty()) { collection->add_one_geometry(shape.release()); } ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion if (is_empty()) { return 0; } ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; + std::size_t num_point = 0; + for (const auto& g : geometries) { + num_point += g->get_num_point(); + } + return num_point; +} + +std::unique_ptr<GeoShape> GeoCollection::boundary() const { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (is_empty()) { + collection->set_empty(); + return collection; + } + + for (const auto& g : geometries) { + std::unique_ptr<GeoShape> shape = g->boundary(); + if (!shape->is_empty()) collection->add_one_geometry(shape.release()); + } + if (collection->get_num_geometries() == 0) collection->set_empty(); + return collection; + + //to_homogenize 还有问题 + //return collection->to_homogenize(); +} + +std::unique_ptr<GeoCollection> GeoCollection::to_homogenize() { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + + for (const auto& g : geometries) { + switch (g->type()) { + case GEO_SHAPE_POINT: { + multi_point->add_one_geometry(g.get()); + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + multi_linestring->add_one_geometry(linestring); + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + multi_polygon->add_one_geometry(polygon); + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + multi_point->add_one_geometry(point); + } + break; + } + case GEO_SHAPE_MULTI_LINE_STRING: { + const GeoMultiLineString* multi_linestring_tmp = + dynamic_cast<const GeoMultiLineString*>(g.get()); + for (int i = 0; i < multi_linestring_tmp->get_num_line(); ++i) { + GeoLineString* linestring = + dynamic_cast<GeoLineString*>(multi_linestring_tmp->get_geometries_n(i)); + multi_linestring->add_one_geometry(linestring); + } + break; + } + case GEO_SHAPE_MULTI_POLYGON: { + const GeoMultiPolygon* multi_polygon_tmp = + dynamic_cast<const GeoMultiPolygon*>(g.get()); + for (int i = 0; i < multi_polygon_tmp->get_num_polygon(); ++i) { + GeoPolygon* polygon = + dynamic_cast<GeoPolygon*>(multi_polygon_tmp->get_geometries_n(i)); + multi_polygon->add_one_geometry(polygon); + } + break; + } + default: { + //这里应该输出告警日志 + return nullptr; + } + } + } + + std::unique_ptr<GeoCollection> res_collection = GeoCollection::create_unique(); + + if (multi_point->get_num_point() == 1) { + GeoPoint* point = (GeoPoint*)multi_point->get_geometries_n(0); + res_collection->add_one_geometry(point); + } else if (multi_point->get_num_point() > 1) { + res_collection->add_one_geometry(multi_point.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_linestring->get_num_line() == 1) { + GeoLineString* linestring = (GeoLineString*)multi_linestring->get_geometries_n(0); + res_collection->add_one_geometry(linestring); + } else if (multi_linestring->get_num_line() > 1) { + res_collection->add_one_geometry(multi_linestring.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_polygon->get_num_polygon() == 1) { + GeoPolygon* polygon = (GeoPolygon*)multi_polygon->get_geometries_n(0); + res_collection->add_one_geometry(polygon); + } else if (multi_polygon->get_num_polygon() > 1) { + res_collection->add_one_geometry(multi_polygon.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + return res_collection; +} + +bool GeoCollection::add_to_s2shape_index(MutableS2ShapeIndex& S2shape_index) const { + if (is_empty()) return false; + for (const auto& g : geometries) { + if (g->is_empty() || !g->is_valid()) continue; + switch (g->type()) { + case GEO_SHAPE_POINT: { + GeoPoint* point = dynamic_cast<GeoPoint*>(g.get()); + if (point->is_empty()) continue; + if (!point->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + if (linestring->is_empty()) continue; + if (!linestring->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + if (polygon->is_empty()) continue; + if (!polygon->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + if (point->is_empty()) continue; + if (!point->add_to_s2shape_index(S2shape_index)) { + return false; + } + } + break; + } + case GEO_SHAPE_MULTI_LINE_STRING: { + const GeoMultiLineString* multi_linestring_tmp = + dynamic_cast<const GeoMultiLineString*>(g.get()); + for (int i = 0; i < multi_linestring_tmp->get_num_line(); ++i) { + GeoLineString* line_string = + dynamic_cast<GeoLineString*>(multi_linestring_tmp->get_geometries_n(i)); + if (line_string->is_empty()) continue; + if (!line_string->add_to_s2shape_index(S2shape_index)) { + return false; + } + } + break; + } + case GEO_SHAPE_MULTI_POLYGON: { + const GeoMultiPolygon* multi_polygon_tmp = + dynamic_cast<const GeoMultiPolygon*>(g.get()); + for (int i = 0; i < multi_polygon_tmp->get_num_polygon(); ++i) { + GeoPolygon* polygon = + dynamic_cast<GeoPolygon*>(multi_polygon_tmp->get_geometries_n(i)); + if (polygon->is_empty()) continue; + if (!polygon->add_to_s2shape_index(S2shape_index)) { + return false; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion empty()) { continue; } ``` ########## be/src/geo/util/GeoCollection.h: ########## @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCOLLECTION_H +#define DORIS_GEOCOLLECTION_H + +#include "GeoLineString.h" +#include "GeoPoint.h" +#include "GeoPolygon.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +namespace doris { +class GeoCollection : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCollection); + +public: + using const_iterator = std::vector<std::unique_ptr<GeoShape>>::const_iterator; + + using iterator = std::vector<std::unique_ptr<GeoShape>>::iterator; + + const_iterator begin() const { return geometries.begin(); }; + + const_iterator end() const { return geometries.end(); }; + + GeoCollection(); + ~GeoCollection() override; + + GeoShapeType type() const override { return GEO_SHAPE_GEOMETRY_COLLECTION; } Review Comment: warning: function 'type' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] GeoShapeType type() const override { return GEO_SHAPE_GEOMETRY_COLLECTION; } ``` ########## be/src/geo/util/GeoCircle.h: ########## @@ -0,0 +1,57 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCIRCLE_H +#define DORIS_GEOCIRCLE_H + +#include "GeoPoint.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +class S2Cap; + +namespace doris { +class GeoCircle : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCircle); + +public: + GeoCircle(); + ~GeoCircle() override; + + GeoParseStatus to_s2cap(double lng, double lat, double radius); + + GeoShapeType type() const override { return GEO_SHAPE_CIRCLE; } + + [[nodiscard]] int get_dimension() const override { return 2; } + + bool contains(const GeoShape* rhs) const override; + std::string as_wkt() const override; + + double get_area() const; + + std::unique_ptr<GeoShape> boundary() const override; Review Comment: warning: function 'boundary' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] std::unique_ptr<GeoShape> boundary() const override; ``` ########## be/src/geo/util/GeoCollection.h: ########## @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCOLLECTION_H +#define DORIS_GEOCOLLECTION_H + +#include "GeoLineString.h" +#include "GeoPoint.h" +#include "GeoPolygon.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +namespace doris { +class GeoCollection : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCollection); + +public: + using const_iterator = std::vector<std::unique_ptr<GeoShape>>::const_iterator; + + using iterator = std::vector<std::unique_ptr<GeoShape>>::iterator; + + const_iterator begin() const { return geometries.begin(); }; + + const_iterator end() const { return geometries.end(); }; + + GeoCollection(); + ~GeoCollection() override; + + GeoShapeType type() const override { return GEO_SHAPE_GEOMETRY_COLLECTION; } + + bool is_valid() const override; Review Comment: warning: function 'is_valid' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] bool is_valid() const override; ``` ########## be/src/geo/util/GeoCollection.h: ########## @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCOLLECTION_H +#define DORIS_GEOCOLLECTION_H + +#include "GeoLineString.h" +#include "GeoPoint.h" +#include "GeoPolygon.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +namespace doris { +class GeoCollection : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCollection); + +public: + using const_iterator = std::vector<std::unique_ptr<GeoShape>>::const_iterator; + + using iterator = std::vector<std::unique_ptr<GeoShape>>::iterator; + + const_iterator begin() const { return geometries.begin(); }; + + const_iterator end() const { return geometries.end(); }; + + GeoCollection(); + ~GeoCollection() override; + + GeoShapeType type() const override { return GEO_SHAPE_GEOMETRY_COLLECTION; } + + bool is_valid() const override; + + bool is_closed() const override; + + void encode_to(std::string* buf) { GeoShape::encode_to(buf); }; + + [[nodiscard]] int get_dimension() const override { + if (get_num_geometries() == 0) { + return -1; + } + + int dim = get_geometries_n(0)->get_dimension(); + for (int i = 1; i < get_num_geometries(); i++) { + if (dim < get_geometries_n(i)->get_dimension()) { + dim = get_geometries_n(i)->get_dimension(); + } + } + + return dim; + } + + GeoParseStatus add_one_geometry(GeoShape* shape); + + // Returns the number of geometries in this collection + std::size_t get_num_geometries() const override; Review Comment: warning: function 'get_num_geometries' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] std::size_t get_num_geometries() const override; ``` ########## be/src/geo/util/GeoLineString.cpp: ########## @@ -0,0 +1,194 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoLineString.h" + +#include <s2/s2polyline.h> +#include <s2/util/coding/coder.h> + +#include <vector> + +#include "GeoMultiPoint.h" + +namespace doris { + +GeoLineString::GeoLineString() = default; +GeoLineString::~GeoLineString() = default; + +// remove adjacent duplicate points +static void remove_duplicate_points(std::vector<S2Point>* points) { + int lhs = 0; + int rhs = 1; + for (; rhs < points->size(); ++rhs) { + if ((*points)[rhs] != (*points)[lhs]) { Review Comment: warning: ISO C++20 considers use of overloaded operator '!=' (with operand types '__gnu_cxx::__alloc_traits<std::allocator<Vector3<double>>, Vector3<double>>::value_type' (aka 'Vector3<double>') and '__gnu_cxx::__alloc_traits<std::allocator<Vector3<double>>, Vector3<double>>::value_type') to be ambiguous despite there being a unique best viable function with non-reversed arguments [clang-diagnostic-ambiguous-reversed-operator] ```cpp if ((*points)[rhs] != (*points)[lhs]) { ^ ``` <details> <summary>Additional context</summary> **thirdparty/installed/include/s2/util/math/vector.h:104:** candidate function with non-reversed arguments ```cpp bool operator!=(const D& b) const { return !(AsD() == b); } ^ ``` **thirdparty/installed/include/s2/util/math/vector.h:100:** ambiguous candidate function with reversed arguments ```cpp bool operator==(const D& b) const { ^ ``` </details> ########## be/src/geo/util/GeoCollection.h: ########## @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCOLLECTION_H +#define DORIS_GEOCOLLECTION_H + +#include "GeoLineString.h" +#include "GeoPoint.h" +#include "GeoPolygon.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +namespace doris { +class GeoCollection : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCollection); + +public: + using const_iterator = std::vector<std::unique_ptr<GeoShape>>::const_iterator; + + using iterator = std::vector<std::unique_ptr<GeoShape>>::iterator; + + const_iterator begin() const { return geometries.begin(); }; Review Comment: warning: function 'begin' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] const_iterator begin() const { return geometries.begin(); }; ``` ########## be/src/geo/util/GeoCollection.h: ########## @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCOLLECTION_H +#define DORIS_GEOCOLLECTION_H + +#include "GeoLineString.h" +#include "GeoPoint.h" +#include "GeoPolygon.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +namespace doris { +class GeoCollection : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCollection); + +public: + using const_iterator = std::vector<std::unique_ptr<GeoShape>>::const_iterator; + + using iterator = std::vector<std::unique_ptr<GeoShape>>::iterator; + + const_iterator begin() const { return geometries.begin(); }; + + const_iterator end() const { return geometries.end(); }; Review Comment: warning: function 'end' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] const_iterator end() const { return geometries.end(); }; ``` ########## be/src/geo/util/GeoCircle.h: ########## @@ -0,0 +1,57 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCIRCLE_H +#define DORIS_GEOCIRCLE_H + +#include "GeoPoint.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +class S2Cap; + +namespace doris { +class GeoCircle : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCircle); + +public: + GeoCircle(); + ~GeoCircle() override; + + GeoParseStatus to_s2cap(double lng, double lat, double radius); + + GeoShapeType type() const override { return GEO_SHAPE_CIRCLE; } + + [[nodiscard]] int get_dimension() const override { return 2; } + + bool contains(const GeoShape* rhs) const override; + std::string as_wkt() const override; + + double get_area() const; Review Comment: warning: function 'get_area' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] double get_area() const; ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; + std::size_t num_point = 0; + for (const auto& g : geometries) { + num_point += g->get_num_point(); + } + return num_point; +} + +std::unique_ptr<GeoShape> GeoCollection::boundary() const { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (is_empty()) { + collection->set_empty(); + return collection; + } + + for (const auto& g : geometries) { + std::unique_ptr<GeoShape> shape = g->boundary(); + if (!shape->is_empty()) collection->add_one_geometry(shape.release()); + } + if (collection->get_num_geometries() == 0) collection->set_empty(); + return collection; + + //to_homogenize 还有问题 + //return collection->to_homogenize(); +} + +std::unique_ptr<GeoCollection> GeoCollection::to_homogenize() { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + + for (const auto& g : geometries) { + switch (g->type()) { + case GEO_SHAPE_POINT: { + multi_point->add_one_geometry(g.get()); + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + multi_linestring->add_one_geometry(linestring); + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + multi_polygon->add_one_geometry(polygon); + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + multi_point->add_one_geometry(point); + } + break; + } + case GEO_SHAPE_MULTI_LINE_STRING: { + const GeoMultiLineString* multi_linestring_tmp = + dynamic_cast<const GeoMultiLineString*>(g.get()); + for (int i = 0; i < multi_linestring_tmp->get_num_line(); ++i) { + GeoLineString* linestring = + dynamic_cast<GeoLineString*>(multi_linestring_tmp->get_geometries_n(i)); + multi_linestring->add_one_geometry(linestring); + } + break; + } + case GEO_SHAPE_MULTI_POLYGON: { + const GeoMultiPolygon* multi_polygon_tmp = + dynamic_cast<const GeoMultiPolygon*>(g.get()); + for (int i = 0; i < multi_polygon_tmp->get_num_polygon(); ++i) { + GeoPolygon* polygon = + dynamic_cast<GeoPolygon*>(multi_polygon_tmp->get_geometries_n(i)); + multi_polygon->add_one_geometry(polygon); + } + break; + } + default: { + //这里应该输出告警日志 + return nullptr; + } + } + } + + std::unique_ptr<GeoCollection> res_collection = GeoCollection::create_unique(); + + if (multi_point->get_num_point() == 1) { + GeoPoint* point = (GeoPoint*)multi_point->get_geometries_n(0); + res_collection->add_one_geometry(point); + } else if (multi_point->get_num_point() > 1) { + res_collection->add_one_geometry(multi_point.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_linestring->get_num_line() == 1) { + GeoLineString* linestring = (GeoLineString*)multi_linestring->get_geometries_n(0); + res_collection->add_one_geometry(linestring); + } else if (multi_linestring->get_num_line() > 1) { + res_collection->add_one_geometry(multi_linestring.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_polygon->get_num_polygon() == 1) { + GeoPolygon* polygon = (GeoPolygon*)multi_polygon->get_geometries_n(0); + res_collection->add_one_geometry(polygon); + } else if (multi_polygon->get_num_polygon() > 1) { + res_collection->add_one_geometry(multi_polygon.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + return res_collection; +} + +bool GeoCollection::add_to_s2shape_index(MutableS2ShapeIndex& S2shape_index) const { + if (is_empty()) return false; + for (const auto& g : geometries) { + if (g->is_empty() || !g->is_valid()) continue; + switch (g->type()) { + case GEO_SHAPE_POINT: { + GeoPoint* point = dynamic_cast<GeoPoint*>(g.get()); Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion !g->is_valid()) { continue; } ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; + std::size_t num_point = 0; + for (const auto& g : geometries) { + num_point += g->get_num_point(); + } + return num_point; +} + +std::unique_ptr<GeoShape> GeoCollection::boundary() const { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (is_empty()) { + collection->set_empty(); + return collection; + } + + for (const auto& g : geometries) { + std::unique_ptr<GeoShape> shape = g->boundary(); + if (!shape->is_empty()) collection->add_one_geometry(shape.release()); + } + if (collection->get_num_geometries() == 0) collection->set_empty(); Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion if (collection->get_num_geometries() == 0) { collection->set_empty(); } ``` ########## be/src/geo/util/GeoCircle.h: ########## @@ -0,0 +1,57 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCIRCLE_H +#define DORIS_GEOCIRCLE_H + +#include "GeoPoint.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +class S2Cap; + +namespace doris { +class GeoCircle : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCircle); + +public: + GeoCircle(); + ~GeoCircle() override; + + GeoParseStatus to_s2cap(double lng, double lat, double radius); + + GeoShapeType type() const override { return GEO_SHAPE_CIRCLE; } + + [[nodiscard]] int get_dimension() const override { return 2; } + + bool contains(const GeoShape* rhs) const override; + std::string as_wkt() const override; Review Comment: warning: function 'as_wkt' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] std::string as_wkt() const override; ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; + std::size_t num_point = 0; + for (const auto& g : geometries) { + num_point += g->get_num_point(); + } + return num_point; +} + +std::unique_ptr<GeoShape> GeoCollection::boundary() const { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (is_empty()) { + collection->set_empty(); + return collection; + } + + for (const auto& g : geometries) { + std::unique_ptr<GeoShape> shape = g->boundary(); + if (!shape->is_empty()) collection->add_one_geometry(shape.release()); + } + if (collection->get_num_geometries() == 0) collection->set_empty(); + return collection; + + //to_homogenize 还有问题 + //return collection->to_homogenize(); +} + +std::unique_ptr<GeoCollection> GeoCollection::to_homogenize() { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + + for (const auto& g : geometries) { + switch (g->type()) { + case GEO_SHAPE_POINT: { + multi_point->add_one_geometry(g.get()); + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + multi_linestring->add_one_geometry(linestring); + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + multi_polygon->add_one_geometry(polygon); + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + multi_point->add_one_geometry(point); + } + break; + } + case GEO_SHAPE_MULTI_LINE_STRING: { + const GeoMultiLineString* multi_linestring_tmp = + dynamic_cast<const GeoMultiLineString*>(g.get()); + for (int i = 0; i < multi_linestring_tmp->get_num_line(); ++i) { + GeoLineString* linestring = + dynamic_cast<GeoLineString*>(multi_linestring_tmp->get_geometries_n(i)); + multi_linestring->add_one_geometry(linestring); + } + break; + } + case GEO_SHAPE_MULTI_POLYGON: { + const GeoMultiPolygon* multi_polygon_tmp = + dynamic_cast<const GeoMultiPolygon*>(g.get()); + for (int i = 0; i < multi_polygon_tmp->get_num_polygon(); ++i) { + GeoPolygon* polygon = + dynamic_cast<GeoPolygon*>(multi_polygon_tmp->get_geometries_n(i)); + multi_polygon->add_one_geometry(polygon); + } + break; + } + default: { + //这里应该输出告警日志 + return nullptr; + } + } + } + + std::unique_ptr<GeoCollection> res_collection = GeoCollection::create_unique(); + + if (multi_point->get_num_point() == 1) { + GeoPoint* point = (GeoPoint*)multi_point->get_geometries_n(0); + res_collection->add_one_geometry(point); + } else if (multi_point->get_num_point() > 1) { + res_collection->add_one_geometry(multi_point.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_linestring->get_num_line() == 1) { + GeoLineString* linestring = (GeoLineString*)multi_linestring->get_geometries_n(0); + res_collection->add_one_geometry(linestring); + } else if (multi_linestring->get_num_line() > 1) { + res_collection->add_one_geometry(multi_linestring.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_polygon->get_num_polygon() == 1) { + GeoPolygon* polygon = (GeoPolygon*)multi_polygon->get_geometries_n(0); + res_collection->add_one_geometry(polygon); + } else if (multi_polygon->get_num_polygon() > 1) { + res_collection->add_one_geometry(multi_polygon.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + return res_collection; +} + +bool GeoCollection::add_to_s2shape_index(MutableS2ShapeIndex& S2shape_index) const { + if (is_empty()) return false; + for (const auto& g : geometries) { + if (g->is_empty() || !g->is_valid()) continue; + switch (g->type()) { + case GEO_SHAPE_POINT: { + GeoPoint* point = dynamic_cast<GeoPoint*>(g.get()); + if (point->is_empty()) continue; + if (!point->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + if (linestring->is_empty()) continue; + if (!linestring->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + if (polygon->is_empty()) continue; + if (!polygon->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + if (point->is_empty()) continue; + if (!point->add_to_s2shape_index(S2shape_index)) { + return false; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion s_empty()) { continue; } ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; + std::size_t num_point = 0; + for (const auto& g : geometries) { + num_point += g->get_num_point(); + } + return num_point; +} + +std::unique_ptr<GeoShape> GeoCollection::boundary() const { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (is_empty()) { + collection->set_empty(); + return collection; + } + + for (const auto& g : geometries) { + std::unique_ptr<GeoShape> shape = g->boundary(); + if (!shape->is_empty()) collection->add_one_geometry(shape.release()); + } + if (collection->get_num_geometries() == 0) collection->set_empty(); + return collection; + + //to_homogenize 还有问题 + //return collection->to_homogenize(); +} + +std::unique_ptr<GeoCollection> GeoCollection::to_homogenize() { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + + for (const auto& g : geometries) { + switch (g->type()) { + case GEO_SHAPE_POINT: { + multi_point->add_one_geometry(g.get()); + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + multi_linestring->add_one_geometry(linestring); + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + multi_polygon->add_one_geometry(polygon); + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + multi_point->add_one_geometry(point); + } + break; + } + case GEO_SHAPE_MULTI_LINE_STRING: { + const GeoMultiLineString* multi_linestring_tmp = + dynamic_cast<const GeoMultiLineString*>(g.get()); + for (int i = 0; i < multi_linestring_tmp->get_num_line(); ++i) { + GeoLineString* linestring = + dynamic_cast<GeoLineString*>(multi_linestring_tmp->get_geometries_n(i)); + multi_linestring->add_one_geometry(linestring); + } + break; + } + case GEO_SHAPE_MULTI_POLYGON: { + const GeoMultiPolygon* multi_polygon_tmp = + dynamic_cast<const GeoMultiPolygon*>(g.get()); + for (int i = 0; i < multi_polygon_tmp->get_num_polygon(); ++i) { + GeoPolygon* polygon = + dynamic_cast<GeoPolygon*>(multi_polygon_tmp->get_geometries_n(i)); + multi_polygon->add_one_geometry(polygon); + } + break; + } + default: { + //这里应该输出告警日志 + return nullptr; + } + } + } + + std::unique_ptr<GeoCollection> res_collection = GeoCollection::create_unique(); + + if (multi_point->get_num_point() == 1) { + GeoPoint* point = (GeoPoint*)multi_point->get_geometries_n(0); + res_collection->add_one_geometry(point); + } else if (multi_point->get_num_point() > 1) { + res_collection->add_one_geometry(multi_point.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_linestring->get_num_line() == 1) { + GeoLineString* linestring = (GeoLineString*)multi_linestring->get_geometries_n(0); + res_collection->add_one_geometry(linestring); + } else if (multi_linestring->get_num_line() > 1) { + res_collection->add_one_geometry(multi_linestring.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_polygon->get_num_polygon() == 1) { + GeoPolygon* polygon = (GeoPolygon*)multi_polygon->get_geometries_n(0); + res_collection->add_one_geometry(polygon); + } else if (multi_polygon->get_num_polygon() > 1) { + res_collection->add_one_geometry(multi_polygon.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + return res_collection; +} + +bool GeoCollection::add_to_s2shape_index(MutableS2ShapeIndex& S2shape_index) const { + if (is_empty()) return false; + for (const auto& g : geometries) { + if (g->is_empty() || !g->is_valid()) continue; + switch (g->type()) { + case GEO_SHAPE_POINT: { + GeoPoint* point = dynamic_cast<GeoPoint*>(g.get()); + if (point->is_empty()) continue; + if (!point->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + if (linestring->is_empty()) continue; + if (!linestring->add_to_s2shape_index(S2shape_index)) { + return false; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion _empty()) { continue; } ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; + std::size_t num_point = 0; + for (const auto& g : geometries) { + num_point += g->get_num_point(); + } + return num_point; +} + +std::unique_ptr<GeoShape> GeoCollection::boundary() const { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (is_empty()) { + collection->set_empty(); + return collection; + } + + for (const auto& g : geometries) { + std::unique_ptr<GeoShape> shape = g->boundary(); + if (!shape->is_empty()) collection->add_one_geometry(shape.release()); + } + if (collection->get_num_geometries() == 0) collection->set_empty(); + return collection; + + //to_homogenize 还有问题 + //return collection->to_homogenize(); +} + +std::unique_ptr<GeoCollection> GeoCollection::to_homogenize() { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + + for (const auto& g : geometries) { + switch (g->type()) { + case GEO_SHAPE_POINT: { + multi_point->add_one_geometry(g.get()); + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + multi_linestring->add_one_geometry(linestring); + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + multi_polygon->add_one_geometry(polygon); + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + multi_point->add_one_geometry(point); + } + break; + } + case GEO_SHAPE_MULTI_LINE_STRING: { + const GeoMultiLineString* multi_linestring_tmp = + dynamic_cast<const GeoMultiLineString*>(g.get()); + for (int i = 0; i < multi_linestring_tmp->get_num_line(); ++i) { + GeoLineString* linestring = + dynamic_cast<GeoLineString*>(multi_linestring_tmp->get_geometries_n(i)); + multi_linestring->add_one_geometry(linestring); + } + break; + } + case GEO_SHAPE_MULTI_POLYGON: { + const GeoMultiPolygon* multi_polygon_tmp = + dynamic_cast<const GeoMultiPolygon*>(g.get()); + for (int i = 0; i < multi_polygon_tmp->get_num_polygon(); ++i) { + GeoPolygon* polygon = + dynamic_cast<GeoPolygon*>(multi_polygon_tmp->get_geometries_n(i)); + multi_polygon->add_one_geometry(polygon); + } + break; + } + default: { + //这里应该输出告警日志 + return nullptr; + } + } + } + + std::unique_ptr<GeoCollection> res_collection = GeoCollection::create_unique(); + + if (multi_point->get_num_point() == 1) { + GeoPoint* point = (GeoPoint*)multi_point->get_geometries_n(0); + res_collection->add_one_geometry(point); + } else if (multi_point->get_num_point() > 1) { + res_collection->add_one_geometry(multi_point.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_linestring->get_num_line() == 1) { + GeoLineString* linestring = (GeoLineString*)multi_linestring->get_geometries_n(0); + res_collection->add_one_geometry(linestring); + } else if (multi_linestring->get_num_line() > 1) { + res_collection->add_one_geometry(multi_linestring.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_polygon->get_num_polygon() == 1) { + GeoPolygon* polygon = (GeoPolygon*)multi_polygon->get_geometries_n(0); + res_collection->add_one_geometry(polygon); + } else if (multi_polygon->get_num_polygon() > 1) { + res_collection->add_one_geometry(multi_polygon.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + return res_collection; +} + +bool GeoCollection::add_to_s2shape_index(MutableS2ShapeIndex& S2shape_index) const { + if (is_empty()) return false; + for (const auto& g : geometries) { + if (g->is_empty() || !g->is_valid()) continue; + switch (g->type()) { + case GEO_SHAPE_POINT: { + GeoPoint* point = dynamic_cast<GeoPoint*>(g.get()); + if (point->is_empty()) continue; + if (!point->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + if (linestring->is_empty()) continue; + if (!linestring->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + if (polygon->is_empty()) continue; + if (!polygon->add_to_s2shape_index(S2shape_index)) { + return false; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion >is_empty()) { continue; } ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; + std::size_t num_point = 0; + for (const auto& g : geometries) { + num_point += g->get_num_point(); + } + return num_point; +} + +std::unique_ptr<GeoShape> GeoCollection::boundary() const { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (is_empty()) { + collection->set_empty(); + return collection; + } + + for (const auto& g : geometries) { + std::unique_ptr<GeoShape> shape = g->boundary(); + if (!shape->is_empty()) collection->add_one_geometry(shape.release()); + } + if (collection->get_num_geometries() == 0) collection->set_empty(); + return collection; + + //to_homogenize 还有问题 + //return collection->to_homogenize(); +} + +std::unique_ptr<GeoCollection> GeoCollection::to_homogenize() { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + + for (const auto& g : geometries) { + switch (g->type()) { + case GEO_SHAPE_POINT: { + multi_point->add_one_geometry(g.get()); + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + multi_linestring->add_one_geometry(linestring); + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + multi_polygon->add_one_geometry(polygon); + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + multi_point->add_one_geometry(point); + } + break; + } + case GEO_SHAPE_MULTI_LINE_STRING: { + const GeoMultiLineString* multi_linestring_tmp = + dynamic_cast<const GeoMultiLineString*>(g.get()); + for (int i = 0; i < multi_linestring_tmp->get_num_line(); ++i) { + GeoLineString* linestring = + dynamic_cast<GeoLineString*>(multi_linestring_tmp->get_geometries_n(i)); + multi_linestring->add_one_geometry(linestring); + } + break; + } + case GEO_SHAPE_MULTI_POLYGON: { + const GeoMultiPolygon* multi_polygon_tmp = + dynamic_cast<const GeoMultiPolygon*>(g.get()); + for (int i = 0; i < multi_polygon_tmp->get_num_polygon(); ++i) { + GeoPolygon* polygon = + dynamic_cast<GeoPolygon*>(multi_polygon_tmp->get_geometries_n(i)); + multi_polygon->add_one_geometry(polygon); + } + break; + } + default: { + //这里应该输出告警日志 + return nullptr; + } + } + } + + std::unique_ptr<GeoCollection> res_collection = GeoCollection::create_unique(); + + if (multi_point->get_num_point() == 1) { + GeoPoint* point = (GeoPoint*)multi_point->get_geometries_n(0); + res_collection->add_one_geometry(point); + } else if (multi_point->get_num_point() > 1) { + res_collection->add_one_geometry(multi_point.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_linestring->get_num_line() == 1) { + GeoLineString* linestring = (GeoLineString*)multi_linestring->get_geometries_n(0); + res_collection->add_one_geometry(linestring); + } else if (multi_linestring->get_num_line() > 1) { + res_collection->add_one_geometry(multi_linestring.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_polygon->get_num_polygon() == 1) { + GeoPolygon* polygon = (GeoPolygon*)multi_polygon->get_geometries_n(0); + res_collection->add_one_geometry(polygon); + } else if (multi_polygon->get_num_polygon() > 1) { + res_collection->add_one_geometry(multi_polygon.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + return res_collection; +} + +bool GeoCollection::add_to_s2shape_index(MutableS2ShapeIndex& S2shape_index) const { + if (is_empty()) return false; + for (const auto& g : geometries) { + if (g->is_empty() || !g->is_valid()) continue; + switch (g->type()) { + case GEO_SHAPE_POINT: { + GeoPoint* point = dynamic_cast<GeoPoint*>(g.get()); + if (point->is_empty()) continue; + if (!point->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + if (linestring->is_empty()) continue; + if (!linestring->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + if (polygon->is_empty()) continue; + if (!polygon->add_to_s2shape_index(S2shape_index)) { + return false; + } + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + if (point->is_empty()) continue; + if (!point->add_to_s2shape_index(S2shape_index)) { + return false; + } + } + break; + } + case GEO_SHAPE_MULTI_LINE_STRING: { + const GeoMultiLineString* multi_linestring_tmp = + dynamic_cast<const GeoMultiLineString*>(g.get()); + for (int i = 0; i < multi_linestring_tmp->get_num_line(); ++i) { + GeoLineString* line_string = + dynamic_cast<GeoLineString*>(multi_linestring_tmp->get_geometries_n(i)); + if (line_string->is_empty()) continue; + if (!line_string->add_to_s2shape_index(S2shape_index)) { + return false; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion y()) { continue; } ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; + std::size_t num_point = 0; + for (const auto& g : geometries) { + num_point += g->get_num_point(); + } + return num_point; +} + +std::unique_ptr<GeoShape> GeoCollection::boundary() const { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (is_empty()) { + collection->set_empty(); + return collection; + } + + for (const auto& g : geometries) { + std::unique_ptr<GeoShape> shape = g->boundary(); + if (!shape->is_empty()) collection->add_one_geometry(shape.release()); + } + if (collection->get_num_geometries() == 0) collection->set_empty(); + return collection; + + //to_homogenize 还有问题 + //return collection->to_homogenize(); +} + +std::unique_ptr<GeoCollection> GeoCollection::to_homogenize() { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + + for (const auto& g : geometries) { + switch (g->type()) { + case GEO_SHAPE_POINT: { + multi_point->add_one_geometry(g.get()); + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + multi_linestring->add_one_geometry(linestring); + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + multi_polygon->add_one_geometry(polygon); + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + multi_point->add_one_geometry(point); + } + break; + } + case GEO_SHAPE_MULTI_LINE_STRING: { + const GeoMultiLineString* multi_linestring_tmp = + dynamic_cast<const GeoMultiLineString*>(g.get()); + for (int i = 0; i < multi_linestring_tmp->get_num_line(); ++i) { + GeoLineString* linestring = + dynamic_cast<GeoLineString*>(multi_linestring_tmp->get_geometries_n(i)); + multi_linestring->add_one_geometry(linestring); + } + break; + } + case GEO_SHAPE_MULTI_POLYGON: { + const GeoMultiPolygon* multi_polygon_tmp = + dynamic_cast<const GeoMultiPolygon*>(g.get()); + for (int i = 0; i < multi_polygon_tmp->get_num_polygon(); ++i) { + GeoPolygon* polygon = + dynamic_cast<GeoPolygon*>(multi_polygon_tmp->get_geometries_n(i)); + multi_polygon->add_one_geometry(polygon); + } + break; + } + default: { + //这里应该输出告警日志 + return nullptr; + } + } + } + + std::unique_ptr<GeoCollection> res_collection = GeoCollection::create_unique(); + + if (multi_point->get_num_point() == 1) { + GeoPoint* point = (GeoPoint*)multi_point->get_geometries_n(0); + res_collection->add_one_geometry(point); + } else if (multi_point->get_num_point() > 1) { + res_collection->add_one_geometry(multi_point.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_linestring->get_num_line() == 1) { + GeoLineString* linestring = (GeoLineString*)multi_linestring->get_geometries_n(0); + res_collection->add_one_geometry(linestring); + } else if (multi_linestring->get_num_line() > 1) { + res_collection->add_one_geometry(multi_linestring.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_polygon->get_num_polygon() == 1) { + GeoPolygon* polygon = (GeoPolygon*)multi_polygon->get_geometries_n(0); + res_collection->add_one_geometry(polygon); + } else if (multi_polygon->get_num_polygon() > 1) { + res_collection->add_one_geometry(multi_polygon.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + return res_collection; +} + +bool GeoCollection::add_to_s2shape_index(MutableS2ShapeIndex& S2shape_index) const { + if (is_empty()) return false; + for (const auto& g : geometries) { + if (g->is_empty() || !g->is_valid()) continue; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion index) const { { } ``` ########## be/src/geo/util/GeoCollection.cpp: ########## @@ -0,0 +1,352 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "GeoCollection.h" + +#include <sstream> + +#include "GeoMultiLineString.h" +#include "GeoMultiPoint.h" +#include "GeoMultiPolygon.h" + +namespace doris { + +GeoCollection::GeoCollection() = default; +GeoCollection::~GeoCollection() = default; + +bool GeoCollection::is_valid() const { + for (const auto& g : geometries) { + if (!g->is_valid()) { + return false; + } + } + return true; +} + +bool GeoCollection::is_closed() const { + for (const auto& g : geometries) { + if (!g->is_closed()) { + return false; + } + } + return true; +} + +GeoParseStatus GeoCollection::add_one_geometry(GeoShape* shape) { + geometries.emplace_back(std::unique_ptr<GeoShape>(shape)); + return GEO_PARSE_OK; +} + +std::size_t GeoCollection::get_num_geometries() const { + return geometries.size(); +} + +GeoShape* GeoCollection::get_geometries_n(std::size_t n) const { + return geometries[n].get(); +} + +std::string GeoCollection::as_wkt() const { + std::stringstream ss; + ss << "GEOMETRYCOLLECTION "; + + if (is_empty()) { + ss << "EMPTY"; + return ss.str(); + } + ss << "("; + + for (int i = 0; i < geometries.size(); ++i) { + ss << geometries[i]->as_wkt(); + if (i != geometries.size() - 1) { + ss << ","; + } + } + ss << ")"; + return ss.str(); +} + +bool GeoCollection::contains(const GeoShape* rhs) const { + switch (rhs->type()) { + case GEO_SHAPE_POINT: { + const GeoPoint* point = (const GeoPoint*)rhs; + for (const auto& g : geometries) { + if (!g->contains(point)) { + return false; + } + } + return true; + } + case GEO_SHAPE_LINE_STRING: { + const GeoLineString* line = (const GeoLineString*)rhs; + for (const auto& g : geometries) { + if (!g->contains(line)) { + return false; + } + } + return true; + } + case GEO_SHAPE_POLYGON: { + const GeoPolygon* polygon = (const GeoPolygon*)rhs; + for (const auto& g : geometries) { + if (!g->contains(polygon)) { + return false; + } + } + return true; + } + case GEO_SHAPE_MULTI_POINT: + case GEO_SHAPE_MULTI_LINE_STRING: + case GEO_SHAPE_MULTI_POLYGON: + case GEO_SHAPE_GEOMETRY_COLLECTION: { + const GeoCollection* collection = (const GeoCollection*)rhs; + for (const auto& g1 : collection->geometries) { + for (const auto& g2 : geometries) { + if (!g2->contains(g1.get())) { + return false; + } + } + } + return true; + } + default: + return false; + } +} + +std::size_t GeoCollection::get_num_point() const { + if (is_empty()) return 0; + std::size_t num_point = 0; + for (const auto& g : geometries) { + num_point += g->get_num_point(); + } + return num_point; +} + +std::unique_ptr<GeoShape> GeoCollection::boundary() const { + std::unique_ptr<GeoCollection> collection = GeoCollection::create_unique(); + if (is_empty()) { + collection->set_empty(); + return collection; + } + + for (const auto& g : geometries) { + std::unique_ptr<GeoShape> shape = g->boundary(); + if (!shape->is_empty()) collection->add_one_geometry(shape.release()); + } + if (collection->get_num_geometries() == 0) collection->set_empty(); + return collection; + + //to_homogenize 还有问题 + //return collection->to_homogenize(); +} + +std::unique_ptr<GeoCollection> GeoCollection::to_homogenize() { + std::unique_ptr<GeoMultiPoint> multi_point = GeoMultiPoint::create_unique(); + std::unique_ptr<GeoMultiLineString> multi_linestring = GeoMultiLineString::create_unique(); + std::unique_ptr<GeoMultiPolygon> multi_polygon = GeoMultiPolygon::create_unique(); + + for (const auto& g : geometries) { + switch (g->type()) { + case GEO_SHAPE_POINT: { + multi_point->add_one_geometry(g.get()); + break; + } + case GEO_SHAPE_LINE_STRING: { + GeoLineString* linestring = dynamic_cast<GeoLineString*>(g.get()); + multi_linestring->add_one_geometry(linestring); + break; + } + case GEO_SHAPE_POLYGON: { + GeoPolygon* polygon = dynamic_cast<GeoPolygon*>(g.get()); + multi_polygon->add_one_geometry(polygon); + break; + } + case GEO_SHAPE_MULTI_POINT: { + const GeoMultiPoint* multi_point_tmp = dynamic_cast<const GeoMultiPoint*>(g.get()); + for (int i = 0; i < multi_point_tmp->get_num_point(); ++i) { + GeoPoint* point = dynamic_cast<GeoPoint*>(multi_point_tmp->get_geometries_n(i)); + multi_point->add_one_geometry(point); + } + break; + } + case GEO_SHAPE_MULTI_LINE_STRING: { + const GeoMultiLineString* multi_linestring_tmp = + dynamic_cast<const GeoMultiLineString*>(g.get()); + for (int i = 0; i < multi_linestring_tmp->get_num_line(); ++i) { + GeoLineString* linestring = + dynamic_cast<GeoLineString*>(multi_linestring_tmp->get_geometries_n(i)); + multi_linestring->add_one_geometry(linestring); + } + break; + } + case GEO_SHAPE_MULTI_POLYGON: { + const GeoMultiPolygon* multi_polygon_tmp = + dynamic_cast<const GeoMultiPolygon*>(g.get()); + for (int i = 0; i < multi_polygon_tmp->get_num_polygon(); ++i) { + GeoPolygon* polygon = + dynamic_cast<GeoPolygon*>(multi_polygon_tmp->get_geometries_n(i)); + multi_polygon->add_one_geometry(polygon); + } + break; + } + default: { + //这里应该输出告警日志 + return nullptr; + } + } + } + + std::unique_ptr<GeoCollection> res_collection = GeoCollection::create_unique(); + + if (multi_point->get_num_point() == 1) { + GeoPoint* point = (GeoPoint*)multi_point->get_geometries_n(0); + res_collection->add_one_geometry(point); + } else if (multi_point->get_num_point() > 1) { + res_collection->add_one_geometry(multi_point.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_linestring->get_num_line() == 1) { + GeoLineString* linestring = (GeoLineString*)multi_linestring->get_geometries_n(0); + res_collection->add_one_geometry(linestring); + } else if (multi_linestring->get_num_line() > 1) { + res_collection->add_one_geometry(multi_linestring.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + if (multi_polygon->get_num_polygon() == 1) { + GeoPolygon* polygon = (GeoPolygon*)multi_polygon->get_geometries_n(0); + res_collection->add_one_geometry(polygon); + } else if (multi_polygon->get_num_polygon() > 1) { + res_collection->add_one_geometry(multi_polygon.release()); + } + /* + * else { + * 这里应该输出告警日志 + * } + */ + + return res_collection; +} + +bool GeoCollection::add_to_s2shape_index(MutableS2ShapeIndex& S2shape_index) const { + if (is_empty()) return false; + for (const auto& g : geometries) { + if (g->is_empty() || !g->is_valid()) continue; + switch (g->type()) { + case GEO_SHAPE_POINT: { + GeoPoint* point = dynamic_cast<GeoPoint*>(g.get()); + if (point->is_empty()) continue; + if (!point->add_to_s2shape_index(S2shape_index)) { + return false; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion t->is_empty()) { continue; } ``` ########## be/src/geo/util/GeoCollection.h: ########## @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCOLLECTION_H +#define DORIS_GEOCOLLECTION_H + +#include "GeoLineString.h" +#include "GeoPoint.h" +#include "GeoPolygon.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +namespace doris { +class GeoCollection : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCollection); + +public: + using const_iterator = std::vector<std::unique_ptr<GeoShape>>::const_iterator; + + using iterator = std::vector<std::unique_ptr<GeoShape>>::iterator; + + const_iterator begin() const { return geometries.begin(); }; + + const_iterator end() const { return geometries.end(); }; + + GeoCollection(); + ~GeoCollection() override; + + GeoShapeType type() const override { return GEO_SHAPE_GEOMETRY_COLLECTION; } + + bool is_valid() const override; + + bool is_closed() const override; Review Comment: warning: function 'is_closed' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] bool is_closed() const override; ``` ########## be/src/geo/util/GeoCollection.h: ########## @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCOLLECTION_H +#define DORIS_GEOCOLLECTION_H + +#include "GeoLineString.h" +#include "GeoPoint.h" +#include "GeoPolygon.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +namespace doris { +class GeoCollection : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCollection); + +public: + using const_iterator = std::vector<std::unique_ptr<GeoShape>>::const_iterator; + + using iterator = std::vector<std::unique_ptr<GeoShape>>::iterator; + + const_iterator begin() const { return geometries.begin(); }; + + const_iterator end() const { return geometries.end(); }; + + GeoCollection(); + ~GeoCollection() override; + + GeoShapeType type() const override { return GEO_SHAPE_GEOMETRY_COLLECTION; } + + bool is_valid() const override; + + bool is_closed() const override; + + void encode_to(std::string* buf) { GeoShape::encode_to(buf); }; + + [[nodiscard]] int get_dimension() const override { + if (get_num_geometries() == 0) { + return -1; + } + + int dim = get_geometries_n(0)->get_dimension(); + for (int i = 1; i < get_num_geometries(); i++) { + if (dim < get_geometries_n(i)->get_dimension()) { + dim = get_geometries_n(i)->get_dimension(); + } + } + + return dim; + } + + GeoParseStatus add_one_geometry(GeoShape* shape); + + // Returns the number of geometries in this collection + std::size_t get_num_geometries() const override; + + // Returns the number of geometries in this collection + GeoShape* get_geometries_n(std::size_t n) const override; Review Comment: warning: function 'get_geometries_n' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] GeoShape* get_geometries_n(std::size_t n) const override; ``` ########## be/src/geo/util/GeoCollection.h: ########## @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCOLLECTION_H +#define DORIS_GEOCOLLECTION_H + +#include "GeoLineString.h" +#include "GeoPoint.h" +#include "GeoPolygon.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +namespace doris { +class GeoCollection : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCollection); + +public: + using const_iterator = std::vector<std::unique_ptr<GeoShape>>::const_iterator; + + using iterator = std::vector<std::unique_ptr<GeoShape>>::iterator; + + const_iterator begin() const { return geometries.begin(); }; + + const_iterator end() const { return geometries.end(); }; + + GeoCollection(); + ~GeoCollection() override; + + GeoShapeType type() const override { return GEO_SHAPE_GEOMETRY_COLLECTION; } + + bool is_valid() const override; + + bool is_closed() const override; + + void encode_to(std::string* buf) { GeoShape::encode_to(buf); }; + + [[nodiscard]] int get_dimension() const override { + if (get_num_geometries() == 0) { + return -1; + } + + int dim = get_geometries_n(0)->get_dimension(); + for (int i = 1; i < get_num_geometries(); i++) { + if (dim < get_geometries_n(i)->get_dimension()) { + dim = get_geometries_n(i)->get_dimension(); + } + } + + return dim; + } + + GeoParseStatus add_one_geometry(GeoShape* shape); + + // Returns the number of geometries in this collection + std::size_t get_num_geometries() const override; + + // Returns the number of geometries in this collection + GeoShape* get_geometries_n(std::size_t n) const override; + + std::string as_wkt() const override; + + bool contains(const GeoShape* rhs) const override; + + [[nodiscard]] std::size_t get_num_point() const override; + + std::unique_ptr<GeoShape> boundary() const override; Review Comment: warning: function 'boundary' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] std::unique_ptr<GeoShape> boundary() const override; ``` ########## be/src/geo/util/GeoCollection.h: ########## @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef DORIS_GEOCOLLECTION_H +#define DORIS_GEOCOLLECTION_H + +#include "GeoLineString.h" +#include "GeoPoint.h" +#include "GeoPolygon.h" +#include "GeoShape.h" +#include "common/factory_creator.h" + +namespace doris { +class GeoCollection : public GeoShape { + ENABLE_FACTORY_CREATOR(GeoCollection); + +public: + using const_iterator = std::vector<std::unique_ptr<GeoShape>>::const_iterator; + + using iterator = std::vector<std::unique_ptr<GeoShape>>::iterator; + + const_iterator begin() const { return geometries.begin(); }; + + const_iterator end() const { return geometries.end(); }; + + GeoCollection(); + ~GeoCollection() override; + + GeoShapeType type() const override { return GEO_SHAPE_GEOMETRY_COLLECTION; } + + bool is_valid() const override; + + bool is_closed() const override; + + void encode_to(std::string* buf) { GeoShape::encode_to(buf); }; + + [[nodiscard]] int get_dimension() const override { + if (get_num_geometries() == 0) { + return -1; + } + + int dim = get_geometries_n(0)->get_dimension(); + for (int i = 1; i < get_num_geometries(); i++) { + if (dim < get_geometries_n(i)->get_dimension()) { + dim = get_geometries_n(i)->get_dimension(); + } + } + + return dim; + } + + GeoParseStatus add_one_geometry(GeoShape* shape); + + // Returns the number of geometries in this collection + std::size_t get_num_geometries() const override; + + // Returns the number of geometries in this collection + GeoShape* get_geometries_n(std::size_t n) const override; + + std::string as_wkt() const override; Review Comment: warning: function 'as_wkt' should be marked [[nodiscard]] [modernize-use-nodiscard] ```suggestion [[nodiscard]] std::string as_wkt() const override; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org