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

Script to render examples/screenshot.png #33

Closed
nside opened this issue Apr 14, 2021 · 1 comment
Closed

Script to render examples/screenshot.png #33

nside opened this issue Apr 14, 2021 · 1 comment

Comments

@nside
Copy link
Contributor

nside commented Apr 14, 2021

I'd be interested in that script if you want to publish it. Thanks

@bdon
Copy link
Member

bdon commented Apr 14, 2021

I actually made that in QGIS, but here's the C++ program to export a WKT TSV file of S2 cell geometries:

#include <iostream>
#include <vector>
#include "s2/s2region_coverer.h"
#include "s2/s2latlng.h"
#include "s2/s2latlng_rect.h"
#include "s2/s2polyline.h"
#include "s2/s2loop.h"

using namespace std;

void print(int i, S2Cell &cell) {
    S2LatLng latlng{cell.GetVertex(i)};
    cout << latlng.lng() << " " << latlng.lat();
}

int main(int argc, char* argv[]) {
    ... define points ...
    auto c = std::make_unique<S2Polyline>(points);
    S2RegionCoverer::Options options;
    options.set_max_cells(1024);
    options.set_max_level(16);
    S2RegionCoverer coverer{options};
    for (auto const &cell_id : coverer.GetCovering(*c)) {
	    S2Cell cell{cell_id};
      cout << cell.id().level() << "\t";
	    cout << "POLYGON ((";
	    for (int i = 0; i <= 3; i++) {
		    print(i, cell);
		    cout << ", ";
	    }
	    print(0,cell);
	    cout << "))" << endl;
    }
}

@nside nside closed this as completed Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants