X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/cfbdd3f7e1c688e2c875ded9fd847fcc1c3a4caf..8cef62cd2cec4a297e46b4f2a86c9afeadb3b283:/db/functions/quadtile.c diff --git a/db/functions/quadtile.c b/db/functions/quadtile.c index d60189245..472e8cb1e 100644 --- a/db/functions/quadtile.c +++ b/db/functions/quadtile.c @@ -1,31 +1,29 @@ -#include -#include -#include -#include +#include #include +#include +#include -my_bool tile_for_point_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +Datum +tile_for_point(PG_FUNCTION_ARGS) { - if ( args->arg_count != 2 || - args->arg_type[0] != INT_RESULT || - args->arg_type[1] != INT_RESULT ) - { - strcpy( message, "Your tile_for_point arguments are bogus!" ); - return 1; - } + double lat = PG_GETARG_INT32(0) / 10000000.0; + double lon = PG_GETARG_INT32(1) / 10000000.0; - return 0; + PG_RETURN_INT64(xy2tile(lon2x(lon), lat2y(lat))); } -void tile_for_point_deinit(UDF_INIT *initid) -{ - return; -} +PG_FUNCTION_INFO_V1(tile_for_point); -long long tile_for_point(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) -{ - long long lat = *(long long *)args->args[0]; - long long lon = *(long long *)args->args[1]; +/* + * To bind this into PGSQL, try something like: + * + * CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 + * AS '/path/to/openstreetmap-website/db/functions/libpgosm', 'tile_for_point' + * LANGUAGE C STRICT; + * + * (without all the *s) + */ - return xy2tile(lon2x(lon / 10000000.0), lat2y(lat / 10000000.0)); -} +#ifdef PG_MODULE_MAGIC +PG_MODULE_MAGIC; +#endif