diff --git a/src/common/datatypes/Geography.cpp b/src/common/datatypes/Geography.cpp index 3318c89f087..a91039695b6 100644 --- a/src/common/datatypes/Geography.cpp +++ b/src/common/datatypes/Geography.cpp @@ -23,8 +23,19 @@ StatusOr Geography::fromWKT(const std::string& wkt) { auto geomRet = WKTReader().read(wkt); NG_RETURN_IF_ERROR(geomRet); auto geom = geomRet.value(); - auto wkb = WKBWriter().write(geom); - return Geography(wkb); + if (!geom.isValid()) { + return Status::Error("It's not valid"); + } + auto bytes = WKBWriter().write(geom); + return Geography(bytes); +} + +StatusOr Geography::fromGeometry(const Geometry& geom) { + if (!geom.isValid()) { + return Status::Error("It's not valid"); + } + auto bytes = WKBWriter().write(geom); + return Geography(bytes); } GeoShape Geography::shape() const { diff --git a/src/common/datatypes/Geography.h b/src/common/datatypes/Geography.h index 241f8c5a09d..6e7665ead93 100644 --- a/src/common/datatypes/Geography.h +++ b/src/common/datatypes/Geography.h @@ -41,7 +41,9 @@ struct Geography { Geography() = default; + // Factory method static StatusOr fromWKT(const std::string& wkt); + static StatusOr fromGeometry(const Geometry& geom); GeoShape shape() const; diff --git a/src/common/datatypes/test/ValueTest.cpp b/src/common/datatypes/test/ValueTest.cpp index b6a345ef065..41bf44f9a01 100644 --- a/src/common/datatypes/test/ValueTest.cpp +++ b/src/common/datatypes/test/ValueTest.cpp @@ -18,6 +18,7 @@ #include "common/datatypes/Set.h" #include "common/datatypes/Value.h" #include "common/datatypes/Vertex.h" +#include "common/geo/io/Geometry.h" namespace nebula { @@ -1156,12 +1157,19 @@ TEST(Value, Ctor) { Value vMap(Map({{"a", 9}, {"b", 10}})); EXPECT_TRUE(vMap.isMap()); // TODO(jie) Add more geography value test - Value vGeoPoint(Geography::fromWKT("POINT(0 1)").value()); - EXPECT_TRUE(vGeoPoint.isGeography()); - Value vGeoLine(Geography::fromWKT("LINESTRING(0 1,2 7)").value()); - EXPECT_TRUE(vGeoLine.isGeography()); - Value vGeoPolygon(Geography::fromWKT("POLYGON((0 1,2 3,4 5,6 7,0 1),(2 4,5 6,3 8,2 4))").value()); - EXPECT_TRUE(vGeoPolygon.isGeography()); + Geometry geomPoint(Point(Coordinate(3, 7))); + Value vGeogPoint{Geography::fromGeometry(geomPoint).value()}; + EXPECT_TRUE(vGeogPoint.isGeography()); + Geometry geomLine(LineString(std::vector{Coordinate(0, 1), Coordinate(2, 7)})); + Value vGeogLine{Geography::fromGeometry(geomLine).value()}; + EXPECT_TRUE(vGeogLine.isGeography()); + Geometry geomPolygon(Polygon(std::vector>{ + std::vector{ + Coordinate(0, 1), Coordinate(2, 3), Coordinate(4, 5), Coordinate(6, 7), Coordinate(0, 1)}, + std::vector{ + Coordinate(2, 4), Coordinate(5, 6), Coordinate(3, 8), Coordinate(2, 4)}})); + Value vGeogPolygon{Geography::fromGeometry(geomPolygon).value()}; + EXPECT_TRUE(vGeogPolygon.isGeography()); // Disabled // Lead to compile error // Value v(nullptr); diff --git a/src/common/function/CMakeLists.txt b/src/common/function/CMakeLists.txt index f7c01e8ebb3..e32d8cabed4 100644 --- a/src/common/function/CMakeLists.txt +++ b/src/common/function/CMakeLists.txt @@ -6,6 +6,10 @@ nebula_add_library( function_manager_obj OBJECT FunctionManager.cpp + ../geo/function/Covers.cpp + ../geo/function/Distance.cpp + ../geo/function/DWithin.cpp + ../geo/function/Intersects.cpp ) nebula_add_library( diff --git a/src/common/function/FunctionManager.cpp b/src/common/function/FunctionManager.cpp index e17c04aed32..4c80997f54e 100644 --- a/src/common/function/FunctionManager.cpp +++ b/src/common/function/FunctionManager.cpp @@ -2306,24 +2306,24 @@ FunctionManager::FunctionManager() { return geog; }; } - { - auto &attr = functions_["st_geogfromwkb"]; - attr.minArity_ = 1; - attr.maxArity_ = 1; - attr.isPure_ = true; - attr.body_ = [](const auto &args) -> Value { - if (!args[0].get().isStr()) { // wkb is byte sequence - return Value::kNullBadType; - } - const std::string &wkb = args[0].get().getStr(); - auto geogRet = Geography::fromWKB(wkb); - if (!geogRet.ok()) { - return Value::kNullBadData; - } - auto geog = std::move(geogRet.value()); - return geog; - }; - } + // { + // auto &attr = functions_["st_geogfromwkb"]; + // attr.minArity_ = 1; + // attr.maxArity_ = 1; + // attr.isPure_ = true; + // attr.body_ = [](const auto &args) -> Value { + // if (!args[0].get().isStr()) { // wkb is byte sequence + // return Value::kNullBadType; + // } + // const std::string &wkb = args[0].get().getStr(); + // auto geogRet = Geography::fromWKB(wkb); + // if (!geogRet.ok()) { + // return Value::kNullBadData; + // } + // auto geog = std::move(geogRet.value()); + // return geog; + // }; + // } { auto &attr = functions_["st_intersects"]; attr.minArity_ = 2; diff --git a/src/common/geo/GeoUtils.h b/src/common/geo/GeoUtils.h index b3d0c083786..146841f40d9 100644 --- a/src/common/geo/GeoUtils.h +++ b/src/common/geo/GeoUtils.h @@ -11,6 +11,7 @@ #include "common/base/StatusOr.h" #include "common/datatypes/Geography.h" +#include "common/geo/GeoShape.h" #include "common/geo/io/Geometry.h" namespace nebula { @@ -30,7 +31,7 @@ class GeoUtils final { case GeoShape::LINESTRING: { const auto& lineString = geom.lineString(); auto coordList = lineString.coordList; - if (UNLIKELY(coordList.size() < 2)) { + if (coordList.size() < 2) { LOG(ERROR) << "LineString must have at least 2 coordinates"; return nullptr; } @@ -51,16 +52,17 @@ class GeoUtils final { } case GeoShape::POLYGON: { const auto& polygon = geom.polygon(); - uint32_t numRings = polygon.numRings(); + uint32_t numCoordList = polygon.numCoordList(); std::vector> s2Loops; - s2Loops.reserve(numRings); - for (size_t i = 0; i < numRings; ++i) { + s2Loops.reserve(numCoordList); + for (size_t i = 0; i < numCoordList; ++i) { auto coordList = polygon.coordListList[i]; - if (UNLIKELY(coordList.size() < 4)) { + if (coordList.size() < 4) { LOG(ERROR) << "Polygon's LinearRing must have at least 4 coordinates"; return nullptr; } - if (UNLIKELY(isLoopClosed(coordList))) { + if (!isLoopClosed(coordList)) { + LOG(ERROR) << "Polygon's LinearRing must be closed"; return nullptr; } removeAdjacentDuplicateCoordinates(coordList); diff --git a/src/common/geo/function/Covers.cpp b/src/common/geo/function/Covers.cpp index 932efdcf11c..f431fc768ce 100644 --- a/src/common/geo/function/Covers.cpp +++ b/src/common/geo/function/Covers.cpp @@ -69,12 +69,19 @@ bool covers(const Geography& a, const Geography& b) { case GeoShape::POLYGON: return aPolygon->Contains(static_cast(bRegion.get())); case GeoShape::UNKNOWN: - default: + default: { LOG(ERROR) << "Geography shapes other than Point/LineString/Polygon are not currently supported"; return false; + } } } + case GeoShape::UNKNOWN: + default: { + LOG(ERROR) + << "Geography shapes other than Point/LineString/Polygon are not currently supported"; + return false; + } } return false; diff --git a/src/common/geo/function/DWithin.cpp b/src/common/geo/function/DWithin.cpp index dfb34e67123..2f811cb1b99 100644 --- a/src/common/geo/function/DWithin.cpp +++ b/src/common/geo/function/DWithin.cpp @@ -41,10 +41,11 @@ bool dWithin(const Geography& a, const Geography& b, double distance, bool inclu return s2PointAndS2PolygonAreWithinDistance(aPoint, bPolygon, distance, inclusive); } case GeoShape::UNKNOWN: - default: + default: { LOG(ERROR) << "Geography shapes other than Point/LineString/Polygon are not currently supported"; return false; + } } } case GeoShape::LINESTRING: { @@ -73,10 +74,11 @@ bool dWithin(const Geography& a, const Geography& b, double distance, bool inclu return s2PolylineAndS2PolygonAreWithinDistance(aLine, bPolygon, distance, inclusive); } case GeoShape::UNKNOWN: - default: + default: { LOG(ERROR) << "Geography shapes other than Point/LineString/Polygon are not currently supported"; return false; + } } } case GeoShape::POLYGON: { @@ -102,12 +104,19 @@ bool dWithin(const Geography& a, const Geography& b, double distance, bool inclu S2Earth::ToChordAngle(util::units::Meters(distance))); } case GeoShape::UNKNOWN: - default: + default: { LOG(ERROR) << "Geography shapes other than Point/LineString/Polygon are not currently supported"; return false; + } } } + case GeoShape::UNKNOWN: + default: { + LOG(ERROR) + << "Geography shapes other than Point/LineString/Polygon are not currently supported"; + return false; + } } return false; diff --git a/src/common/geo/function/Distance.cpp b/src/common/geo/function/Distance.cpp index 75d9ab96be3..9f05a0be109 100644 --- a/src/common/geo/function/Distance.cpp +++ b/src/common/geo/function/Distance.cpp @@ -40,10 +40,11 @@ double distance(const Geography& a, const Geography& b) { return distanceOfS2PolygonWithS2Point(bPolygon, aPoint); } case GeoShape::UNKNOWN: - default: + default: { LOG(ERROR) << "Geography shapes other than Point/LineString/Polygon are not currently supported"; - return -1.0; + return false; + } } } case GeoShape::LINESTRING: { @@ -67,10 +68,11 @@ double distance(const Geography& a, const Geography& b) { return distanceOfS2PolygonWithS2Polyline(bPolygon, aLine); } case GeoShape::UNKNOWN: - default: + default: { LOG(ERROR) << "Geography shapes other than Point/LineString/Polygon are not currently supported"; - return -1.0; + return false; + } } } case GeoShape::POLYGON: { @@ -91,12 +93,19 @@ double distance(const Geography& a, const Geography& b) { return S2Earth::ToMeters(query.GetDistance(&target)); } case GeoShape::UNKNOWN: - default: + default: { LOG(ERROR) << "Geography shapes other than Point/LineString/Polygon are not currently supported"; - return -1.0; + return false; + } } } + case GeoShape::UNKNOWN: + default: { + LOG(ERROR) + << "Geography shapes other than Point/LineString/Polygon are not currently supported"; + return false; + } } return false; diff --git a/src/common/geo/function/Intersects.cpp b/src/common/geo/function/Intersects.cpp index a9033305834..488bd674d67 100644 --- a/src/common/geo/function/Intersects.cpp +++ b/src/common/geo/function/Intersects.cpp @@ -36,10 +36,11 @@ bool intersects(const Geography& a, const Geography& b) { return static_cast(bRegion.get()) ->MayIntersect(S2Cell(static_cast(aRegion.get())->point())); case GeoShape::UNKNOWN: - default: + default: { LOG(ERROR) << "Geography shapes other than Point/LineString/Polygon are not currently supported"; return false; + } } } case GeoShape::LINESTRING: { @@ -54,10 +55,11 @@ bool intersects(const Geography& a, const Geography& b) { return static_cast(bRegion.get()) ->Intersects(*static_cast(aRegion.get())); case GeoShape::UNKNOWN: - default: + default: { LOG(ERROR) << "Geography shapes other than Point/LineString/Polygon are not currently supported"; return false; + } } } case GeoShape::POLYGON: { @@ -72,12 +74,19 @@ bool intersects(const Geography& a, const Geography& b) { return static_cast(aRegion.get()) ->Intersects(static_cast(bRegion.get())); case GeoShape::UNKNOWN: - default: + default: { LOG(ERROR) << "Geography shapes other than Point/LineString/Polygon are not currently supported"; return false; + } } } + case GeoShape::UNKNOWN: + default: { + LOG(ERROR) + << "Geography shapes other than Point/LineString/Polygon are not currently supported"; + return false; + } } return false; diff --git a/src/common/geo/io/Geometry.h b/src/common/geo/io/Geometry.h index 174a4f32e48..e41dfd7b606 100644 --- a/src/common/geo/io/Geometry.h +++ b/src/common/geo/io/Geometry.h @@ -26,10 +26,6 @@ struct Coordinate { // TODO(jie) compare double correctly bool operator==(const Coordinate& rhs) const { return x == rhs.x && y == rhs.y; } bool operator!=(const Coordinate& rhs) const { return !(*this == rhs); } - - static bool isValidLng(double lng) { return std::abs(lng) <= 180; } - - static bool isValidLat(double lat) { return std::abs(lat) <= 90; } }; struct Point { @@ -37,7 +33,19 @@ struct Point { explicit Point(const Coordinate& v) : coord(v) {} explicit Point(Coordinate&& v) : coord(std::move(v)) {} - ~Point() {} + ~Point() = default; + + bool isValid() const { + if (std::abs(coord.x) > 180) { + LOG(ERROR) << "Longitude must be between -180 and 180 degrees"; + return false; + } + if (std::abs(coord.y) > 90) { + LOG(ERROR) << "Latitude must be between -90 and 90 degrees"; + return false; + } + return true; + } }; struct LineString { @@ -45,9 +53,17 @@ struct LineString { explicit LineString(const std::vector& v) : coordList(v) {} explicit LineString(std::vector&& v) : coordList(std::move(v)) {} - ~LineString() {} + ~LineString() = default; + + uint32_t numCoord() const { return coordList.size(); } - uint32_t numCoords() const { return coordList.size(); } + bool isValid() const { + if (coordList.size() < 2) { + LOG(ERROR) << "LineString must have at least 2 coordinates"; + return false; + } + return true; + } }; struct Polygon { @@ -55,10 +71,23 @@ struct Polygon { explicit Polygon(const std::vector>& v) : coordListList(v) {} explicit Polygon(std::vector>&& v) : coordListList(std::move(v)) {} - ~Polygon() {} - - uint32_t numRings() const { return coordListList.size(); } - uint32_t numInteriorRing() const { return numRings() - 1; } + ~Polygon() = default; + + uint32_t numCoordList() const { return coordListList.size(); } + + bool isValid() const { + for (const auto& coordList : coordListList) { + if (coordList.size() < 4) { + LOG(ERROR) << "Polygon's LinearRing must have at least 4 coordinates"; + return false; + } + if (coordList.front() != coordList.back()) { + LOG(ERROR) << "Polygon's LinearRing must be closed"; + return false; + } + } + return true; + } }; struct Geometry { @@ -83,6 +112,7 @@ struct Geometry { return GeoShape::UNKNOWN; } } + const Point& point() const { CHECK(std::holds_alternative(geom)); return std::get(geom); @@ -97,6 +127,22 @@ struct Geometry { CHECK(std::holds_alternative(geom)); return std::get(geom); } + + bool isValid() const { + switch (shape()) { + case GeoShape::POINT: + return point().isValid(); + case GeoShape::LINESTRING: + return lineString().isValid(); + case GeoShape::POLYGON: + return polygon().isValid(); + case GeoShape::UNKNOWN: + default: + LOG(ERROR) + << "Geometry shapes other than Point/LineString/Polygon are not currently supported"; + return false; + } + } }; } // namespace nebula diff --git a/src/common/geo/io/wkb/WKBReader.cpp b/src/common/geo/io/wkb/WKBReader.cpp index 8c3223b34bb..a176399cb7f 100644 --- a/src/common/geo/io/wkb/WKBReader.cpp +++ b/src/common/geo/io/wkb/WKBReader.cpp @@ -31,19 +31,19 @@ StatusOr WKBReader::read(const uint8_t *&beg, const uint8_t *end) cons return Point(coord); } case GeoShape::LINESTRING: { - auto numPointsRet = readUint32(beg, end, byteOrder); - NG_RETURN_IF_ERROR(numPointsRet); - uint32_t numPoints = numPointsRet.value(); - auto coordListRet = readCoordinateList(beg, end, byteOrder, numPoints); + auto numCoordRet = readUint32(beg, end, byteOrder); + NG_RETURN_IF_ERROR(numCoordRet); + uint32_t numCoord = numCoordRet.value(); + auto coordListRet = readCoordinateList(beg, end, byteOrder, numCoord); NG_RETURN_IF_ERROR(coordListRet); std::vector coordList = coordListRet.value(); return LineString(coordList); } case GeoShape::POLYGON: { - auto numRingsRet = readUint32(beg, end, byteOrder); - NG_RETURN_IF_ERROR(numRingsRet); - uint32_t numRings = numRingsRet.value(); - auto coordListListRet = readCoordinateListList(beg, end, byteOrder, numRings); + auto numCoordListRet = readUint32(beg, end, byteOrder); + NG_RETURN_IF_ERROR(numCoordListRet); + uint32_t numCoordList = numCoordListRet.value(); + auto coordListListRet = readCoordinateListList(beg, end, byteOrder, numCoordList); NG_RETURN_IF_ERROR(coordListListRet); std::vector> coordListList = coordListListRet.value(); return Polygon(coordListList); @@ -112,10 +112,10 @@ StatusOr>> WKBReader::readCoordinateListList std::vector> coordListList; coordListList.reserve(num); for (size_t i = 0; i < num; ++i) { - auto numPointsRet = readUint32(beg, end, byteOrder); - NG_RETURN_IF_ERROR(numPointsRet); - uint32_t numPoints = numPointsRet.value(); - auto coordListRet = readCoordinateList(beg, end, byteOrder, numPoints); + auto numCoordRet = readUint32(beg, end, byteOrder); + NG_RETURN_IF_ERROR(numCoordRet); + uint32_t numCoord = numCoordRet.value(); + auto coordListRet = readCoordinateList(beg, end, byteOrder, numCoord); NG_RETURN_IF_ERROR(coordListRet); std::vector coordList = coordListRet.value(); coordListList.emplace_back(coordList); diff --git a/src/common/geo/io/wkb/WKBWriter.cpp b/src/common/geo/io/wkb/WKBWriter.cpp index fa28cdf21a6..6bc1b7c6452 100644 --- a/src/common/geo/io/wkb/WKBWriter.cpp +++ b/src/common/geo/io/wkb/WKBWriter.cpp @@ -28,16 +28,16 @@ std::string WKBWriter::write(const Geometry& geom) const { case GeoShape::LINESTRING: { const LineString& line = geom.lineString(); auto coordList = line.coordList; - uint32_t numPoints = coordList.size(); - writeUint32(wkb, numPoints); + uint32_t numCoord = coordList.size(); + writeUint32(wkb, numCoord); writeCoordinateList(wkb, coordList); return wkb; } case GeoShape::POLYGON: { const Polygon& polygon = geom.polygon(); auto coordListList = polygon.coordListList; - uint32_t numRings = coordListList.size(); - writeUint32(wkb, numRings); + uint32_t numCoordList = coordListList.size(); + writeUint32(wkb, numCoordList); writeCoordinateListList(wkb, coordListList); return wkb; } @@ -64,8 +64,8 @@ void WKBWriter::writeCoordinateListList( std::string& wkb, const std::vector>& coordListList) const { for (size_t i = 0; i < coordListList.size(); ++i) { const auto& coordList = coordListList[i]; - uint32_t numPoints = coordList.size(); - writeUint32(wkb, numPoints); + uint32_t numCoord = coordList.size(); + writeUint32(wkb, numCoord); writeCoordinateList(wkb, coordList); } } diff --git a/src/common/geo/io/wkt/WKTWriter.cpp b/src/common/geo/io/wkt/WKTWriter.cpp index 7e992579a84..2b4d8946f44 100644 --- a/src/common/geo/io/wkt/WKTWriter.cpp +++ b/src/common/geo/io/wkt/WKTWriter.cpp @@ -25,8 +25,8 @@ std::string WKTWriter::write(const Geometry& geom) const { wkt.append("LINESTRING"); const LineString& line = geom.lineString(); auto coordList = line.coordList; - uint32_t numPoints = coordList.size(); - UNUSED(numPoints); + uint32_t numCoord = coordList.size(); + UNUSED(numCoord); wkt.append("("); writeCoordinateList(wkt, coordList); wkt.append(")"); @@ -36,8 +36,8 @@ std::string WKTWriter::write(const Geometry& geom) const { wkt.append("POLYGON"); const Polygon& polygon = geom.polygon(); auto coordListList = polygon.coordListList; - uint32_t numRings = coordListList.size(); - UNUSED(numRings); + uint32_t numCoordList = coordListList.size(); + UNUSED(numCoordList); wkt.append("("); writeCoordinateListList(wkt, coordListList); wkt.append(")"); @@ -69,8 +69,8 @@ void WKTWriter::WKTWriter::writeCoordinateListList( std::string& wkt, const std::vector>& coordListList) const { for (size_t i = 0; i < coordListList.size(); ++i) { const auto& coordList = coordListList[i]; - uint32_t numPoints = coordList.size(); - UNUSED(numPoints); + uint32_t numCoord = coordList.size(); + UNUSED(numCoord); wkt.append("("); writeCoordinateList(wkt, coordList); wkt.append(")"); diff --git a/src/common/geo/io/wkt/test/WKTParserTest.cpp b/src/common/geo/io/wkt/test/WKTParserTest.cpp index ef4c4512a28..0dad9b20f7c 100644 --- a/src/common/geo/io/wkt/test/WKTParserTest.cpp +++ b/src/common/geo/io/wkt/test/WKTParserTest.cpp @@ -64,20 +64,6 @@ TEST_F(WKTParserTest, TestWKTParser) { ASSERT_FALSE(result.ok()); EXPECT_EQ(result.status().toString(), "SyntaxError: syntax error near `,'"); } - { - std::string wkt = "POINT(-190 36.842)"; - auto result = parse(wkt); - ASSERT_FALSE(result.ok()); - EXPECT_EQ(result.status().toString(), - "SyntaxError: Longitude must be between -180 and 180 degrees near `-190'"); - } - { - std::string wkt = "POINT(179 91)"; - auto result = parse(wkt); - ASSERT_FALSE(result.ok()); - EXPECT_EQ(result.status().toString(), - "SyntaxError: Latitude must be between -90 and 90 degrees near `91'"); - } // LineString { std::string wkt = "LINESTRING(0 1, 1 2, 2 3, 3 4)"; @@ -95,13 +81,6 @@ TEST_F(WKTParserTest, TestWKTParser) { ASSERT_FALSE(result.ok()); EXPECT_EQ(result.status().toString(), "SyntaxError: syntax error near `)'"); } - { - std::string wkt = "LINESTRING(0 1)"; - auto result = parse(wkt); - ASSERT_FALSE(result.ok()); - EXPECT_EQ(result.status().toString(), - "SyntaxError: LineString must have at least 2 coordinates near `0 1'"); - } // Polygon { std::string wkt = "POLYGON((0 1, 1 2, 2 3, 0 1))"; @@ -125,13 +104,6 @@ TEST_F(WKTParserTest, TestWKTParser) { ASSERT_FALSE(result.ok()); EXPECT_EQ(result.status().toString(), "SyntaxError: syntax error near `)'"); } - { - std::string wkt = "POLYGON((0 1, 1 2, 2 3, 3 4))"; - auto result = parse(wkt); - ASSERT_FALSE(result.ok()); - EXPECT_EQ(result.status().toString(), - "SyntaxError: Polygon's LinearRing must be closed near `(0 1, 1 2, 2 3, 3 4)'"); - } } } // namespace nebula diff --git a/src/common/geo/io/wkt/wkt_parser.yy b/src/common/geo/io/wkt/wkt_parser.yy index ee92a150bd3..e7bdde73526 100644 --- a/src/common/geo/io/wkt/wkt_parser.yy +++ b/src/common/geo/io/wkt/wkt_parser.yy @@ -96,10 +96,6 @@ point linestring : KW_LINESTRING L_PAREN coordinate_list R_PAREN { - if ($3->size() < 2) { - delete $3; - throw nebula::WKTParser::syntax_error(@3, "LineString must have at least 2 coordinates"); - } $$ = new LineString(std::move(*$3)); delete $3; } @@ -107,17 +103,6 @@ linestring polygon : KW_POLYGON L_PAREN coordinate_list_list R_PAREN { - for (size_t i = 0; i < $3->size(); ++i) { - const auto &coordList = (*$3)[i]; - if (coordList.size() < 4) { - delete $3; - throw nebula::WKTParser::syntax_error(@3, "Polygon's LinearRing must have at least 4 coordinates"); - } - if (coordList.front() != coordList.back()) { - delete $3; - throw nebula::WKTParser::syntax_error(@3, "Polygon's LinearRing must be closed"); - } - } $$ = new Polygon(std::move(*$3)); delete $3; } @@ -125,12 +110,6 @@ polygon coordinate : DOUBLE DOUBLE { - if (!Coordinate::isValidLng($1)) { - throw nebula::WKTParser::syntax_error(@1, "Longitude must be between -180 and 180 degrees"); - } - if (!Coordinate::isValidLat($2)) { - throw nebula::WKTParser::syntax_error(@2, "Latitude must be between -90 and 90 degrees"); - } $$.x = $1; $$.y = $2; }