Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geo spatial: 2. geography functions #2979

Merged
merged 5 commits into from Oct 12, 2021

Conversation

@jievince jievince changed the title Geo spatial: 2. Add geo functions Geo spatial: 2. Add geography functions Sep 29, 2021
@jievince jievince added the wip Solution: work in progress label Sep 29, 2021
@Sophie-Xie Sophie-Xie added this to the v2.6.0 milestone Sep 29, 2021
@jievince jievince changed the title Geo spatial: 2. Add geography functions Geo spatial: 2. geography functions Oct 4, 2021
@jievince jievince force-pushed the geo-spatial-functions branch 7 times, most recently from 4d52a75 to 340401e Compare October 8, 2021 03:35
@jievince jievince added the cherry-pick-v2.6 PR: need cherry-pick to this version label Oct 8, 2021
@jievince jievince force-pushed the geo-spatial-functions branch 4 times, most recently from 1adae70 to 5e9d5c5 Compare October 10, 2021 08:22
@jievince jievince added ready-for-testing PR: ready for the CI test and removed wip Solution: work in progress labels Oct 10, 2021
@jievince jievince force-pushed the geo-spatial-functions branch 5 times, most recently from 996532c to 53b8b2b Compare October 11, 2021 06:06
@codecov-commenter
Copy link

Codecov Report

Merging #2979 (8beac94) into master (e642c05) will decrease coverage by 0.14%.
The diff coverage is 71.79%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2979      +/-   ##
==========================================
- Coverage   84.34%   84.20%   -0.15%     
==========================================
  Files        1283     1296      +13     
  Lines      113684   115342    +1658     
==========================================
+ Hits        95891    97122    +1231     
- Misses      17793    18220     +427     
Impacted Files Coverage Δ
src/common/geo/io/wkb/WKBReader.h 100.00% <ø> (ø)
src/common/geo/io/wkb/WKBWriter.h 100.00% <ø> (ø)
src/common/geo/io/wkt/WKTWriter.h 100.00% <ø> (ø)
src/graph/visitor/DeduceTypeVisitor.h 100.00% <ø> (ø)
src/storage/admin/AdminTaskManager.h 100.00% <ø> (ø)
src/storage/admin/AdminTaskProcessor.cpp 0.00% <0.00%> (ø)
src/common/geo/function/S2Util.cpp 18.18% <18.18%> (ø)
src/storage/admin/AdminTaskManager.cpp 49.55% <34.28%> (-1.18%) ⬇️
src/common/function/FunctionManager.cpp 75.42% <35.29%> (-4.98%) ⬇️
src/common/datatypes/GeographyOps-inl.h 37.06% <37.94%> (+4.37%) ⬆️
... and 55 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64721f1...8beac94. Read the comment docs.

src/common/datatypes/Geography.cpp Outdated Show resolved Hide resolved

bool Coordinate::isValid() const { return std::abs(x) <= 180.0 && std::abs(y) <= 90.0; }

void Point::normalize() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coord.normalize() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method Coordinate::normalize is not used now.
For the illegal coordinate, we want to report an error directly, rather than normalize it for the user

src/common/datatypes/Geography.cpp Outdated Show resolved Hide resolved
};

struct Point {
Coordinate coord;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use x,y here directly, do we really need the coordinate struct ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two modeling approaches:
1:
Point: Coordinate;
LineString: A list of Coordinate;
Polygon: Lists of list of Coordinate;
2:
Point;
LineString: A list of Point;
Polygon: Lists of LineString.

Both are ok, but almost all geo libraries take the first approach

src/common/geo/function/Intersects.h Outdated Show resolved Hide resolved
Copy link
Contributor

@CPWstatic CPWstatic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

switch (shape()) {
case GeoShape::POINT: {
const auto& point = geom->point();
return std::abs(point.coord.x) <= 180.0 && std::abs(point.coord.y) <= 90.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a macro or constexpr for representing the magic number 180.0 and 90.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

src/common/datatypes/Geography.cpp Show resolved Hide resolved
void __clear() { clear(); }

// TODO(jie) compare double correctly
bool operator==(const Coordinate& rhs) const { return x == rhs.x && y == rhs.y; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abs(x - rhs) < eps

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -302,6 +308,94 @@ std::unordered_map<std::string, std::vector<TypeSignature>> FunctionManager::typ
TypeSignature({Value::Type::DATASET, Value::Type::INT, Value::Type::STRING},
Value::Type::__EMPTY__),
}},
// These geo functions of the ST prefix follow the Simple Feature Access and SQL/MM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does ST means?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SQL/MM standard uses consistently the prefix ST for all tables, views, types, methods, and function names. The prefix stood originally for Spatial and Temporal. It was intended in the early stages of the standard development to define a combination of temporal and spatial extension.
See https://stackoverflow.com/questions/7234679/what-is-st-in-postgis

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost all SQL databases use this standard when implementing geo spatial.

Copy link
Contributor

@yixinglu yixinglu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@critical27 critical27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM

@critical27 critical27 merged commit d8e5539 into vesoft-inc:master Oct 12, 2021
Sophie-Xie pushed a commit that referenced this pull request Oct 12, 2021
* Geo spatial: 2. Add geo functions

* add ByteOrderDataIOStream

* add s2 util test

* let Geography store variant

* address yee's comments
@jievince jievince mentioned this pull request Oct 12, 2021
@jievince jievince deleted the geo-spatial-functions branch October 13, 2021 01:56
@jievince jievince added the doc affected PR: improvements or additions to documentation label Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-v2.6 PR: need cherry-pick to this version doc affected PR: improvements or additions to documentation ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants