-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[c++] WKB geometry utilities (#3149)
* Add serialization/deserialization support for geometry entities * Add default constructors * Extract geometry utilities into separate namespace Move template function implementation outside of header files * lint format * Bump C++ version * Replace lambdas with struct overloading operator() * Revert C++ version bump * Split write operator declaration * Add named constants * Moved geometry out of source directory Address PR comments
- Loading branch information
1 parent
176bbf8
commit 7381508
Showing
21 changed files
with
1,126 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef TILEDBSOMA_GEOMETRY_BASE_H | ||
#define TILEDBSOMA_GEOMETRY_BASE_H | ||
|
||
#include <math.h> | ||
#include <memory> | ||
#include <optional> | ||
#include <vector> | ||
|
||
namespace tiledbsoma::geometry { | ||
|
||
struct BasePoint { | ||
BasePoint( | ||
double_t x, | ||
double_t y, | ||
std::optional<double_t> z = std::nullopt, | ||
std::optional<double_t> m = std::nullopt) | ||
: x(x) | ||
, y(y) | ||
, z(z) | ||
, m(m) { | ||
} | ||
|
||
double_t x; | ||
double_t y; | ||
std::optional<double_t> z; | ||
std::optional<double_t> m; | ||
}; | ||
} // namespace tiledbsoma::geometry | ||
|
||
#endif // TILEDBSOMA_GEOMETRY_BASE_H |
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,42 @@ | ||
#ifndef TILEDBSOMA_GEOMETRY_H | ||
#define TILEDBSOMA_GEOMETRY_H | ||
|
||
#include <variant> | ||
|
||
#include "linestring.h" | ||
#include "multilinestring.h" | ||
#include "multipoint.h" | ||
#include "multipolygon.h" | ||
#include "point.h" | ||
#include "polygon.h" | ||
|
||
namespace tiledbsoma::geometry { | ||
|
||
enum GeometryType : uint32_t { | ||
POINT = 1, | ||
LINESTRING = 2, | ||
POLYGON = 3, | ||
MULTIPOINT = 4, | ||
MULTILINESTRING = 5, | ||
MULTIPOLYGON = 6, | ||
GEOMETRYCOLLECTION = 7 | ||
}; | ||
|
||
using BinaryBuffer = std::vector<uint8_t>; | ||
|
||
struct GeometryCollection; | ||
using GenericGeometry = std::variant< | ||
Point, | ||
LineString, | ||
Polygon, | ||
MultiPoint, | ||
MultiLineString, | ||
MultiPolygon, | ||
GeometryCollection>; | ||
|
||
struct GeometryCollection : public std::vector<GenericGeometry> { | ||
using std::vector<GenericGeometry>::vector; | ||
}; | ||
} // namespace tiledbsoma::geometry | ||
|
||
#endif // TILEDBSOMA_GEOMETRY_H |
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,10 @@ | ||
#include "linestring.h" | ||
|
||
namespace tiledbsoma::geometry { | ||
LineString::LineString(std::vector<BasePoint>&& points) | ||
: points(points) { | ||
} | ||
|
||
LineString::~LineString() { | ||
} | ||
} // namespace tiledbsoma::geometry |
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,19 @@ | ||
#ifndef TILEDBSOMA_LINESTRING_H | ||
#define TILEDBSOMA_LINESTRING_H | ||
|
||
#include <vector> | ||
|
||
#include "base.h" | ||
|
||
namespace tiledbsoma::geometry { | ||
|
||
class LineString { | ||
public: | ||
LineString(std::vector<BasePoint>&& points = std::vector<BasePoint>()); | ||
~LineString(); | ||
|
||
std::vector<BasePoint> points; | ||
}; | ||
} // namespace tiledbsoma::geometry | ||
|
||
#endif // TILEDBSOMA_LINESTRING_H |
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,10 @@ | ||
#include "multilinestring.h" | ||
|
||
namespace tiledbsoma::geometry { | ||
MultiLineString::MultiLineString(std::vector<LineString>&& linestrings) | ||
: linestrings(linestrings) { | ||
} | ||
|
||
MultiLineString::~MultiLineString() { | ||
} | ||
} // namespace tiledbsoma::geometry |
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,19 @@ | ||
#ifndef TILEDBSOMA_MULTILINESTRING_H | ||
#define TILEDBSOMA_MULTILINESTRING_H | ||
|
||
#include <vector> | ||
|
||
#include "linestring.h" | ||
|
||
namespace tiledbsoma::geometry { | ||
class MultiLineString { | ||
public: | ||
MultiLineString( | ||
std::vector<LineString>&& linestring = std::vector<LineString>()); | ||
~MultiLineString(); | ||
|
||
std::vector<LineString> linestrings; | ||
}; | ||
} // namespace tiledbsoma::geometry | ||
|
||
#endif // TILEDBSOMA_MULTILINESTRING_H |
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,10 @@ | ||
#include "multipoint.h" | ||
|
||
namespace tiledbsoma::geometry { | ||
MultiPoint::MultiPoint(std::vector<Point>&& points) | ||
: points(points) { | ||
} | ||
|
||
MultiPoint::~MultiPoint() { | ||
} | ||
} // namespace tiledbsoma::geometry |
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,19 @@ | ||
#ifndef TILEDBSOMA_MULTIPOINT_H | ||
#define TILEDBSOMA_MULTIPOINT_H | ||
|
||
#include <vector> | ||
|
||
#include "point.h" | ||
|
||
namespace tiledbsoma::geometry { | ||
class MultiPoint { | ||
public: | ||
MultiPoint(std::vector<Point>&& points = std::vector<Point>()); | ||
~MultiPoint(); | ||
|
||
std::vector<Point> points; | ||
}; | ||
|
||
} // namespace tiledbsoma::geometry | ||
|
||
#endif // TILEDBSOMA_MULTIPOINT_H |
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,10 @@ | ||
#include "multipolygon.h" | ||
|
||
namespace tiledbsoma::geometry { | ||
MultiPolygon::MultiPolygon(std::vector<Polygon>&& polygons) | ||
: polygons(polygons) { | ||
} | ||
|
||
MultiPolygon::~MultiPolygon() { | ||
} | ||
} // namespace tiledbsoma::geometry |
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,18 @@ | ||
#ifndef TILEDBSOMA_MULTIPOLYGON_H | ||
#define TILEDBSOMA_MULTIPOLYGON_H | ||
|
||
#include <vector> | ||
|
||
#include "polygon.h" | ||
|
||
namespace tiledbsoma::geometry { | ||
class MultiPolygon { | ||
public: | ||
MultiPolygon(std::vector<Polygon>&& polygons = std::vector<Polygon>()); | ||
~MultiPolygon(); | ||
|
||
std::vector<Polygon> polygons; | ||
}; | ||
} // namespace tiledbsoma::geometry | ||
|
||
#endif // TILEDBSOMA_MULTIPOLYGON_H |
Oops, something went wrong.