]> git.openstreetmap.org Git - rails.git/blob - db/functions/quadtile.c
Merge branch 'master' into feature/add-communities-page
[rails.git] / db / functions / quadtile.c
1 #include <math.h>
2 #include <quad_tile.h>
3 #include <postgres.h>
4 #include <fmgr.h>
5
6 Datum
7 tile_for_point(PG_FUNCTION_ARGS)
8 {
9   double lat = PG_GETARG_INT32(0) / 10000000.0;
10   double lon = PG_GETARG_INT32(1) / 10000000.0;
11
12   PG_RETURN_INT64(xy2tile(lon2x(lon), lat2y(lat)));
13 }
14
15 PG_FUNCTION_INFO_V1(tile_for_point);
16
17 /*
18  * To bind this into PGSQL, try something like:
19  *
20  * CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8
21  *  AS '/path/to/rails-port/db/functions/libpgosm', 'tile_for_point'
22  *  LANGUAGE C STRICT;
23  *
24  * (without all the *s)
25  */
26
27 #ifdef PG_MODULE_MAGIC
28 PG_MODULE_MAGIC;
29 #endif