X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/9afb35449b066fdef6b4af3b63e30e7f4eb4c5cf..421b6113898ed5d80fd00a7f953cdbb9dbf2d4c5:/db/functions/quadtile.c?ds=inline diff --git a/db/functions/quadtile.c b/db/functions/quadtile.c index d60189245..29758edc6 100644 --- a/db/functions/quadtile.c +++ b/db/functions/quadtile.c @@ -1,8 +1,21 @@ +#ifndef USE_MYSQL +#ifndef USE_PGSQL +#error One of USE_MYSQL or USE_PGSQL must be defined +#endif +#endif + +#include +#include + +#ifdef USE_MYSQL +#ifdef USE_PGSQL +#error ONLY one of USE_MYSQL and USE_PGSQL should be defined +#endif + #include #include #include #include -#include my_bool tile_for_point_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { @@ -29,3 +42,35 @@ long long tile_for_point(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char * return xy2tile(lon2x(lon / 10000000.0), lat2y(lat / 10000000.0)); } +#endif + +#ifdef USE_PGSQL +#ifdef USE_MYSQL +#error ONLY one of USE_MYSQL and USE_PGSQL should be defined +#endif + +#include +#include + +Datum +tile_for_point(PG_FUNCTION_ARGS) +{ + double lat = PG_GETARG_INT32(0) / 10000000.0; + double lon = PG_GETARG_INT32(1) / 10000000.0; + + PG_RETURN_INT64(xy2tile(lon2x(lon), lat2y(lat))); +} + +PG_FUNCTION_INFO_V1(tile_for_point); + +/* + * To bind this into PGSQL, try something like: + * + * CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 + * AS '/path/to/rails-port/db/functions/libpgosm', 'tile_for_point' + * LANGUAGE C STRICT; + * + * (without all the *s) + */ + +#endif