-
Notifications
You must be signed in to change notification settings - Fork 5
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
Suggestion to include a function for cell area #4
Comments
Solved (!), the functions developed at osm-codes/s2geom-PoC can be used here: CREATE or replace FUNCTION s2_token_exact_area(token text, ret_meters boolean DEFAULT false) RETURNS float8 AS $f$
import s2sphere
kEarthRadiusMeters = 6371010
steradians = s2sphere.Cell( s2sphere.CellId.from_token(token) ).exact_area()
return (steradians*kEarthRadiusMeters*kEarthRadiusMeters) if ret_meters else steradians
$f$ LANGUAGE plpython3u IMMUTABLE;
COMMENT ON function s2_cellid_exact_area
IS 'Exact area in steradians of a cell-Token, and approximated (better for small cells) in meters';
CREATE or replace FUNCTION s2_cellid_exact_area(id0 bigint, ret_meters boolean DEFAULT false) RETURNS float8
AS $f$
import s2sphere
id = s2sphere.CellId(
int.from_bytes( id0.to_bytes(8,'big',signed=True), 'big', signed=False )
)
kEarthRadiusMeters = 6371010
steradians = s2sphere.Cell( id ).exact_area()
return (steradians*kEarthRadiusMeters*kEarthRadiusMeters) if ret_meters else steradians
$f$ LANGUAGE plpython3u IMMUTABLE;
COMMENT ON function s2_cellid_exact_area
IS 'Exact area in steradians of a cell-ID, and approximated (better for small cells) in meters'; Another important function, to work with any "geo library" (e.g. Turf) or PostGIS, is |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also sidewalklabs/s2sphere#38
The text was updated successfully, but these errors were encountered: