osm-codes / s2geom-poc Goto Github PK
View Code? Open in Web Editor NEWProof of Concept for PostgreSQL implementation of S2geometry functions, based on AfieldTrails/s2-postgis
Proof of Concept for PostgreSQL implementation of S2geometry functions, based on AfieldTrails/s2-postgis
For example https://github.com/countingCrow/simple-s2-port can be tested by an script of asserts generated by SQL.
Each cell ID of S2 Geometry can be represented geometrically, so, this representation can be expessed as a GeoJSON polygon.
We need a funcion that return the GeoJSON of a cell, and similar function that returns the Union of a set of cells, as multipolygon.
Supposing that areas returned by S2 functions are offered in steradians... As this comment at C++ source s2/s2testing.h
the actual metric for a cell is obtained by integrating the differential quantity,
which is not constant across the cell. Therefore cells at low levels
(bigger cells) have smaller variations
and the implementation of conversion functions at s2testing.cc:
const double S2Testing::kEarthRadiusKm = 6371.01;
double S2Testing::AreaToMeters2(double steradians) {
return 1e6 * AreaToKm2(steradians);
}
double S2Testing::AreaToKm2(double steradians) {
return steradians * kEarthRadiusKm * kEarthRadiusKm;
}
About kEarthRadiusKm
, seems the "Average distance from center to surface", that can be 6,371.230 km by wikipedia. Nominal value: 6.3781ร10^6 m but in ellipsoid can range from 6,357 to 6,378 km. Ideal is the "Median distance from center to surface", so 6371010 m is near it.
The area in steradians is useful for precise corrections and integration (and/or positioning each cell in its correct altitude). For any other use the m2 is the standard, like PostGIS functions.
The sugestion is to add a flag in the *_exact_area()
functions (like ST_Area) to be true for m2 and false for steradians.
There are an error on assert02 line 11, all areas are equal (and same as a leaf area). Seems that it is a problem with s2_cellid_parent( s2_cellid_from_latlng(-23.55041,-46.63394), 1+i*5)
, but the test below, using tokens (the test on token area transform was good) show that is not:
WITH cells AS (
SELECT 1+i*5 as level,
s2_cellid_parent( s2_cellid_from_latlng(-23.55041,-46.63394), 1+i*5) pt1_id,
s2_cellid_parent( s2_cellid_from_latlng(15,15), 1+i*5) pt2_id
FROM generate_series(0,4) t(i)
)
SELECT level, pt1_id, pt2_id,
s2_token_from_cellid(pt1_id) "pt1_token",
s2_token_from_cellid(pt2_id) "pt2_token"
FROM cells;
level | pt1_id | pt2_id | pt1_token | pt2_token |
---|---|---|---|---|
1 | -7782220156096217088 | 1441151880758558720 | 94 | 14 |
6 | -7723954835917111296 | 1230327123202277376 | 94cf | 1113 |
11 | -7724137629725229056 | 1230478580929003520 | 94ce59c | 111389c |
16 | -7724137722872332288 | 1230478344437366784 | 94ce59aa5 | 11138988f |
21 | -7724137722769309696 | 1230478344653635584 | 94ce59aa5624 | 11138988fce4 |
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.