Comments (3)
I'm not sure if S2Polygon::GetCellUnionBound actually removes holes from the CellUnion
or not
I was a bit disappointed to see that the Go Port (p *Polygon) CellUnionBound() function returns the CellUnion of the Cap! So it's just returning a coverage of outer rings and not considering interior rings
from s2.
I might have had the wrong assumptions about RegionCoverer
, I assumed it would cover the surface of the shape rather than the exterior boundary, looking at the C++ code that doesn't seem to be the case.
#include "s2/s2point.h"
#include "s2/s2cell_id.h"
#include "s2/s2builder.h"
#include "s2/s2builderutil_s2polygon_layer.h"
#include "s2/s2polygon.h"
#include "s2/s2loop.h"
#include "s2/s2text_format.h"
#include "s2/s2region.h"
#include "s2/s2region_coverer.h"
using s2builderutil::S2PolygonLayer;
using s2textformat::MakeLoopOrDie;
using s2textformat::MakePolygonOrDie;
using s2textformat::ToString;
using absl::make_unique;
using std::cout;
using std::endl;
string CellUnionTokens(const S2CellUnion &cell_union)
{
string out;
for (S2CellId cell_id : cell_union)
{
if (!out.empty())
out += ",";
out += cell_id.ToToken();
}
return out;
}
int main()
{
S2Builder::Options options;
S2Builder builder(options);
S2Polygon output;
builder.StartLayer(make_unique<S2PolygonLayer>(&output));
auto outer = MakeLoopOrDie("-32.364:153.207, -35.364:153.207, -35.364:158.207");
builder.AddLoop(*outer);
cout << "-- outer --" << endl;
cout << ToString(*outer) << endl;
auto inner1 = MakeLoopOrDie("-34.364:155.207, -34.364:154.207, -33.364:154.207");
builder.AddLoop(*inner1);
cout << "-- inner1 --" << endl;
cout << ToString(*inner1) << endl;
// auto inner2 = MakeLoopOrDie("-34.364:157.207, -34.364:156.207, -33.364:156.207");
// builder.AddLoop(*inner2);
// cout << "-- inner2 --" << endl;
// cout << ToString(*inner2) << endl;
cout << "-- build --" << endl;
S2Error error;
builder.Build(&error);
cout << error << endl;
cout << "-- output --" << endl;
cout << ToString(output) << endl;
S2RegionCoverer coverer;
S2CellUnion ret = coverer.GetCovering(output);
cout << "-- cell union --" << endl;
cout << CellUnionTokens(ret) << endl;
return 0;
}
-- outer --
-32.364:153.207, -35.364:153.207, -35.364:158.207
-- inner1 --
-34.364:155.207, -34.364:154.207, -33.364:154.207
-- build --
-- output --
-32.364:153.207, -35.364:153.207, -35.364:158.207;
-33.364:154.207, -34.364:154.207, -34.364:155.207
-- cell union --
6b63,6b65,6b6f,6b71,6b77,6b7c,6c82c,6c9d
from s2.
I found this function GetInteriorCovering()
which solves my issue
auto outer = MakeLoopOrDie("-35.364:153.207, -35.364:158.207, -32.364:158.207, -32.364:153.207");
auto inner1 = MakeLoopOrDie("-34.364:154.207, -34.364:155.207, -33.364:155.207, -33.364:154.207");
auto inner2 = MakeLoopOrDie("-34.364:156.207, -34.364:157.207, -33.364:157.207, -33.364:156.207");
S2RegionCoverer coverer;
coverer.mutable_options()->set_min_level(0);
coverer.mutable_options()->set_max_level(16);
coverer.mutable_options()->set_max_cells(100);
S2CellUnion outerCells = coverer.GetCovering(*outer);
S2CellUnion inner1Cells = coverer.GetInteriorCovering(*inner1);
S2CellUnion inner2Cells = coverer.GetInteriorCovering(*inner2);
auto output = outerCells.Difference(inner1Cells).Difference(inner2Cells);
cout << CellUnionTokens(output) << endl;
from s2.
Related Issues (13)
- Windows Install HOT 4
- Can I use this library to make a UDF in BigQuery? HOT 2
- Missing Expected Exports HOT 2
- cellunion contains method not working HOT 1
- Add pre-built binary for node 14 HOT 2
- Add check for unsupported platforms HOT 1
- Windows support
- builder: segmentation fault HOT 3
- s2-v0.0.4-node-v93-linux-x64.tar.gz does not exist HOT 2
- Typos in Readme HOT 7
- build: fatal error: absl/hash/hash.h not found HOT 1
- Deprecation issues - external dependencies HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from s2.