Skip to content

Instantly share code, notes, and snippets.

@leonmvd
Created February 11, 2022 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonmvd/ffb893b2cd98e9bd61d64a47075b56bc to your computer and use it in GitHub Desktop.
Save leonmvd/ffb893b2cd98e9bd61d64a47075b56bc to your computer and use it in GitHub Desktop.
Calculate cbs vierkanstatistieken cell id
-- function that calculates the CBS Vierkantstatistieken grid cell for point coordinates in RD new.
create or replace function get_cbsvierkantid(fn_geom geometry, i_dist int) returns text as $$
select
'E' ||
((st_x(fn_geom)::numeric - (st_x(fn_geom)::numeric % i_dist)) / 100)::int ||
'N' ||
((st_y(fn_geom)::numeric - (st_y(fn_geom)::numeric % i_dist)) / 100)::int
as cbs_vierkant_id
;
$$ language sql;
-- example for 500x500 grid
select get_cbsvierkantid(st_geomfromtext('POINT(233544.795083973 581928.166658598)'),500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment