-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
1,616 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ nebula_add_library( | |
Map.cpp | ||
List.cpp | ||
Set.cpp | ||
Geography.cpp | ||
) | ||
|
||
nebula_add_subdirectory(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* Copyright (c) 2020 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
#include "common/datatypes/Geography.h" | ||
|
||
#include <folly/String.h> | ||
#include <folly/hash/Hash.h> | ||
|
||
#include <cstdint> | ||
|
||
namespace nebula { | ||
|
||
S2Region* Geography::asS2() const { | ||
// auto geom = WKBReader().read(wkb); | ||
// return s2RegionFromGeom(&geom); | ||
return nullptr; | ||
} | ||
|
||
// S2Region* Geography::s2RegionFromGeom(const geos::geom::Geometry* geom) { | ||
// return new S2Region; | ||
// switch (geom->getGeometryTypeId()) { | ||
// case geos::geom::GEOS_POINT: { | ||
// auto *point = static_cast<geos::geom::Point*>(geom); | ||
// auto latlng = S2LatLng::FromDegrees(point->getX(), point->getY()); | ||
// return new S2PointRegion(latlng.toPoint()); | ||
// } | ||
// case geos::geom::GEOS_LINESTRING: { | ||
// auot *lineString = static_cast<geos::geom::LineString*>(geom); | ||
// std::vector<S2Point> s2Points; | ||
// latlngs.reserve(lineString->numPoints()); | ||
// for (size_t i = 0; i < lineString->numPoints(); ++i) { | ||
// auto latlng = lineString->getCoordinateN(i); | ||
// s2Points.emplace_back(S2LatLng::FromDegrees(latlng.x, latlng.y).ToPoint()); | ||
// } | ||
// return new S2Polyline(s2Points); | ||
// } | ||
// case geos::geom::GEOS_POLYGON: { | ||
// auto *polygon = static_cast<geos::geom::Polygon*>(geom); | ||
// size_t ringNum = 1 + polygon->getNumInteriorRing(); | ||
// std::vector<std::unique_ptr<S2Loop>> s2Loops; | ||
// s2Loops.reserve(ringNum); | ||
|
||
// std::vector<const LinearRing*> rings; | ||
// rings.reserve(ringNum); | ||
|
||
// std::vector<S2Point> s2Points; | ||
// for (size_t i = 0; i < rings.size(); ++i) { | ||
// const auto *ring = rings[i]; | ||
// s2Points.clear(); | ||
// s2Points.reserve(ring->numPoints()); | ||
// for (size_t j = 0; j < ring->numPoints(); ++j) { | ||
// auto latlng = ring->getCoordinateN(i); | ||
// s2Points.empalce_back(S2LatLng::FromDegrees(latlng.x, latlng.y).ToPoint()); | ||
// } | ||
// auto *s2Loop = new S2Loop(s2Points); | ||
// s2Loop->Normalize(); | ||
// s2Loops.emplace_back(s2Loop); // make loop be CCW | ||
// return new S2Polygon(s2Loops); | ||
// } | ||
// } | ||
// } | ||
// } | ||
|
||
} // namespace nebula | ||
|
||
namespace std { | ||
|
||
// Inject a customized hash function | ||
std::size_t hash<nebula::Geography>::operator()(const nebula::Geography& h) const noexcept { | ||
return hash<std::string>{}(h.wkb); | ||
} | ||
|
||
} // namespace std |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* Copyright (c) 2020 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <s2/s2point.h> | ||
#include <s2/s2point_region.h> | ||
#include <s2/s2polyline.h> | ||
#include <s2/s2region.h> | ||
|
||
#include <algorithm> | ||
#include <typeinfo> | ||
#include <vector> | ||
|
||
#include "common/datatypes/Value.h" | ||
|
||
class S2Polygon; | ||
|
||
namespace nebula { | ||
|
||
// clang-format off | ||
/* | ||
static const std::unordered_map<ShapeType, S2Region> kShapeTypeToS2Region = { | ||
{ShapeType::Point, S2PointRegion}, // S2PointRegion is a wrapper of S2Point, and it inherits from the S2Region class | ||
{ShapeType::LineString, S2Polyline}, | ||
{ShapeType::Polygon, S2Polygon}, | ||
}; | ||
*/ | ||
// clang-format on | ||
|
||
enum class ShapeType : uint8_t { | ||
Point = 1, | ||
LineString = 2, | ||
Polygon = 3, | ||
}; | ||
|
||
// Do not construct a S2 data when constructing Geography. It's expensive. | ||
// We just construct S2 when doing computation. | ||
struct Geography { | ||
std::string wkb; | ||
|
||
Geography() = default; | ||
explicit Geography(const std::string& validWKB) { | ||
// DCHECK(WKB::isValid(wkb)); | ||
wkb = validWKB; | ||
} | ||
|
||
S2Region* asS2() const; | ||
|
||
ShapeType shape() const { | ||
// auto type = WKBReader.readUint32(wkb.substr(1)); | ||
// DCHECK(type >= 1 && type <= 3); | ||
// return static_cast<ShapeType>(type); | ||
return static_cast<ShapeType>(1); | ||
} | ||
|
||
void clear() { wkb.clear(); } | ||
|
||
void __clear() { clear(); } | ||
|
||
std::string toString() const { return wkb; } | ||
|
||
bool operator==(const Geography& rhs) const { return wkb == rhs.wkb; } | ||
|
||
bool operator!=(const Geography& rhs) const { return !(wkb == rhs.wkb); } | ||
|
||
bool operator<(const Geography& rhs) const { return wkb < rhs.wkb; } | ||
|
||
// private: | ||
// S2Region* s2RegionFromGeom(const geos::geom::Geometry* geom); | ||
}; | ||
|
||
inline std::ostream& operator<<(std::ostream& os, const Geography& g) { return os << g.wkb; } | ||
|
||
} // namespace nebula | ||
|
||
namespace std { | ||
|
||
// Inject a customized hash function | ||
template <> | ||
struct hash<nebula::Geography> { | ||
std::size_t operator()(const nebula::Geography& h) const noexcept; | ||
}; | ||
|
||
} // namespace std |
Oops, something went wrong.