6 maptile_for_point(PG_FUNCTION_ARGS)
8 double lat = PG_GETARG_INT64(0) / 10000000.0;
9 double lon = PG_GETARG_INT64(1) / 10000000.0;
10 int zoom = PG_GETARG_INT32(2);
11 double scale = pow(2, zoom);
12 double r_per_d = M_PI / 180;
16 x = floor((lon + 180.0) * scale / 360.0);
17 y = floor((1 - log(tan(lat * r_per_d) + 1.0 / cos(lat * r_per_d)) / M_PI) * scale / 2.0);
19 PG_RETURN_INT32((x << zoom) | y);
22 PG_FUNCTION_INFO_V1(maptile_for_point);
25 * To bind this into PGSQL, try something like:
27 * CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4
28 * AS '/path/to/rails-port/db/functions/libpgosm', 'maptile_for_point'
31 * (without all the *s)
34 #ifdef PG_MODULE_MAGIC