]> git.openstreetmap.org Git - rails.git/commitdiff
Add a maptile_for_point() function for MySQL to work out which slippy
authorTom Hughes <tom@compton.nu>
Tue, 9 Oct 2007 22:59:32 +0000 (22:59 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 9 Oct 2007 22:59:32 +0000 (22:59 +0000)
map tile a given point lies in.

db/README
db/functions/Makefile
db/functions/maptile.c [new file with mode: 0644]

index 03e95fff3907442ecdbee9ae6688708fb6a768a5..4e705e8fb31a1f760a815b4f53f28bd4404fa718 100644 (file)
--- a/db/README
+++ b/db/README
@@ -32,11 +32,6 @@ Run this command in the db/functions directory:
 
 $ make
 
 
 $ 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
 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
@@ -50,12 +45,8 @@ $ mysql -u <uid> -p openstreetmap
 
 (change <uid> with appropriate username of administrative user eg. root )
 
 
 (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
 > exit
 
 Creating database skeleton tables
index 2f2abe5252ffee1a511c6fc84d411fb95981c402..7652862faf55b5bfad71eddf7e56184e5dc62efc 100644 (file)
@@ -7,8 +7,11 @@ else
     LDFLAGS=-shared
 endif
 
     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
 
 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
diff --git a/db/functions/maptile.c b/db/functions/maptile.c
new file mode 100644 (file)
index 0000000..f96f9c2
--- /dev/null
@@ -0,0 +1,39 @@
+#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;
+}