map tile a given point lies in.
$ make
-The above command should work for linux and most other Unix systems
-that use ELF shared objects. For MacOS X you will need to do:
-
-$ make libquadtile.dylib
-
Make sure the db/functions directory is on the MySQL server's library
path and restart the MySQL server. On linux the easiest way to do this
is to create /etc/ld.so.conf.d/osm.conf and place the path to the
(change <uid> with appropriate username of administrative user eg. root )
-> create function tile_for_point returns integer soname 'libquadtile.so';
-> exit
-
-or, for MacOS X:
-
-> create function tile_for_point returns integer soname 'libquadtile.dylib';
+> create function tile_for_point returns integer soname 'libmyosm.so';
+> create function maptile_for_point returns integer soname 'libmyosm.so';
> exit
Creating database skeleton tables
LDFLAGS=-shared
endif
-libquadtile.so: quadtile.o
- cc ${LDFLAGS} -o libquadtile.so quadtile.o
+libmyosm.so: quadtile.o maptile.o
+ cc ${LDFLAGS} -o libmyosm.so quadtile.o maptile.o
quadtile.o: quadtile.c ${QTDIR}/quad_tile.h
cc `mysql_config --include` -I${QTDIR} -fPIC -O3 -c -o quadtile.o quadtile.c
+
+maptile.o: maptile.c
+ cc `mysql_config --include` -fPIC -O3 -c -o maptile.o maptile.c
--- /dev/null
+#include <my_global.h>
+#include <my_sys.h>
+#include <m_string.h>
+#include <mysql.h>
+
+my_bool maptile_for_point_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
+{
+ if ( args->arg_count != 3 ||
+ args->arg_type[0] != INT_RESULT ||
+ args->arg_type[1] != INT_RESULT ||
+ args->arg_type[2] != INT_RESULT )
+ {
+ strcpy( message, "Your maptile_for_point arguments are bogus!" );
+ return 1;
+ }
+
+ return 0;
+}
+
+void maptile_for_point_deinit(UDF_INIT *initid)
+{
+ return;
+}
+
+long long maptile_for_point(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
+{
+ double lat = *(long long *)args->args[0] / 10000000.0;
+ double lon = *(long long *)args->args[1] / 10000000.0;
+ long long zoom = *(long long *)args->args[2];
+ double scale = pow(2, zoom);
+ double r_per_d = M_PI / 180;
+ unsigned int x;
+ unsigned int y;
+
+ x = floor((lon + 180.0) * scale / 360.0);
+ y = floor((1 - log(tan(lat * r_per_d) + 1.0 / cos(lat * r_per_d)) / M_PI) * scale / 2.0);
+
+ return (x << zoom) | y;
+}