6 my_bool maptile_for_point_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
8 if ( args->arg_count != 3 ||
9 args->arg_type[0] != INT_RESULT ||
10 args->arg_type[1] != INT_RESULT ||
11 args->arg_type[2] != INT_RESULT )
13 strcpy( message, "Your maptile_for_point arguments are bogus!" );
20 void maptile_for_point_deinit(UDF_INIT *initid)
25 long long maptile_for_point(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
27 double lat = *(long long *)args->args[0] / 10000000.0;
28 double lon = *(long long *)args->args[1] / 10000000.0;
29 long long zoom = *(long long *)args->args[2];
30 double scale = pow(2, zoom);
31 double r_per_d = M_PI / 180;
35 x = floor((lon + 180.0) * scale / 360.0);
36 y = floor((1 - log(tan(lat * r_per_d) + 1.0 / cos(lat * r_per_d)) / M_PI) * scale / 2.0);
38 return (x << zoom) | y;