Add postgres implementation of tile_for_point function.
This commit is contained in:
parent
a0a6dd3619
commit
55b1ba32e5
3 changed files with 63 additions and 11 deletions
|
@ -12,17 +12,20 @@ all: libmyosm.so libpgosm.so
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.so *.o
|
$(RM) *.so *.o
|
||||||
|
|
||||||
libmyosm.so: quadtile.o maptile-mysql.o
|
libmyosm.so: quadtile-mysql.o maptile-mysql.o
|
||||||
cc ${LDFLAGS} -o libmyosm.so quadtile.o maptile-mysql.o
|
cc ${LDFLAGS} -o libmyosm.so quadtile-mysql.o maptile-mysql.o
|
||||||
|
|
||||||
libpgosm.so: maptile-pgsql.o
|
libpgosm.so: quadtile-pgsql.o maptile-pgsql.o
|
||||||
cc ${LDFLAGS} -o libpgosm.so maptile-pgsql.o
|
cc ${LDFLAGS} -o libpgosm.so quadtile-pgsql.o maptile-pgsql.o
|
||||||
|
|
||||||
quadtile.o: quadtile.c ${QTDIR}/quad_tile.h
|
quadtile-mysql.o: quadtile.c ${QTDIR}/quad_tile.h
|
||||||
cc `mysql_config --include` -I${QTDIR} -fPIC -O3 -c -o quadtile.o quadtile.c
|
cc `mysql_config --include` -I${QTDIR} -fPIC -O3 -DUSE_MYSQL -c -o quadtile-mysql.o quadtile.c
|
||||||
|
|
||||||
|
quadtile-pgsql.o: quadtile.c ${QTDIR}/quad_tile.h
|
||||||
|
cc -I `pg_config --includedir-server` -I${QTDIR} -fPIC -O3 -DUSE_PGSQL -c -o quadtile-pgsql.o quadtile.c
|
||||||
|
|
||||||
maptile-mysql.o: maptile.c
|
maptile-mysql.o: maptile.c
|
||||||
cc `mysql_config --include` -fPIC -O3 -DUSE_MYSQL -c -o maptile-mysql.o maptile.c
|
cc `mysql_config --include` -fPIC -O3 -DUSE_MYSQL -c -o maptile-mysql.o maptile.c
|
||||||
|
|
||||||
maptile-pgsql.o: maptile.c
|
maptile-pgsql.o: maptile.c
|
||||||
cc -I `pg_config --includedir-server` -O3 -fPIC -DUSE_PGSQL -c -o maptile-pgsql.o maptile.c
|
cc -I `pg_config --includedir-server` -fPIC -O3 -DUSE_PGSQL -c -o maptile-pgsql.o maptile.c
|
||||||
|
|
|
@ -55,12 +55,16 @@ long long maptile_for_point(UDF_INIT *initid, UDF_ARGS *args, char *is_null, cha
|
||||||
double lat = *(long long *)args->args[0] / 10000000.0;
|
double lat = *(long long *)args->args[0] / 10000000.0;
|
||||||
double lon = *(long long *)args->args[1] / 10000000.0;
|
double lon = *(long long *)args->args[1] / 10000000.0;
|
||||||
long long zoom = *(long long *)args->args[2];
|
long long zoom = *(long long *)args->args[2];
|
||||||
|
|
||||||
return internal_maptile_for_point(lat, lon, zoom);
|
return internal_maptile_for_point(lat, lon, zoom);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_PGSQL
|
#ifdef USE_PGSQL
|
||||||
|
#ifdef USE_MYSQL
|
||||||
|
#error ONLY one of USE_MYSQL and USE_PGSQL should be defined
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <postgres.h>
|
#include <postgres.h>
|
||||||
#include <fmgr.h>
|
#include <fmgr.h>
|
||||||
|
|
||||||
|
@ -70,7 +74,7 @@ maptile_for_point(PG_FUNCTION_ARGS)
|
||||||
double lat = PG_GETARG_INT64(0) / 10000000.0;
|
double lat = PG_GETARG_INT64(0) / 10000000.0;
|
||||||
double lon = PG_GETARG_INT64(1) / 10000000.0;
|
double lon = PG_GETARG_INT64(1) / 10000000.0;
|
||||||
int zoom = PG_GETARG_INT32(2);
|
int zoom = PG_GETARG_INT32(2);
|
||||||
|
|
||||||
PG_RETURN_INT32(internal_maptile_for_point(lat, lon, zoom));
|
PG_RETURN_INT32(internal_maptile_for_point(lat, lon, zoom));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +83,7 @@ PG_FUNCTION_INFO_V1(maptile_for_point);
|
||||||
/*
|
/*
|
||||||
* To bind this into PGSQL, try something like:
|
* To bind this into PGSQL, try something like:
|
||||||
*
|
*
|
||||||
* CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4
|
* CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4
|
||||||
* AS '/path/to/rails-port/db/functions/libpgosm', 'maptile_for_point'
|
* AS '/path/to/rails-port/db/functions/libpgosm', 'maptile_for_point'
|
||||||
* LANGUAGE C STRICT;
|
* LANGUAGE C STRICT;
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,8 +1,21 @@
|
||||||
|
#ifndef USE_MYSQL
|
||||||
|
#ifndef USE_PGSQL
|
||||||
|
#error One of USE_MYSQL or USE_PGSQL must be defined
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <quad_tile.h>
|
||||||
|
|
||||||
|
#ifdef USE_MYSQL
|
||||||
|
#ifdef USE_PGSQL
|
||||||
|
#error ONLY one of USE_MYSQL and USE_PGSQL should be defined
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <my_global.h>
|
#include <my_global.h>
|
||||||
#include <my_sys.h>
|
#include <my_sys.h>
|
||||||
#include <m_string.h>
|
#include <m_string.h>
|
||||||
#include <mysql.h>
|
#include <mysql.h>
|
||||||
#include <quad_tile.h>
|
|
||||||
|
|
||||||
my_bool tile_for_point_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
|
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));
|
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 <postgres.h>
|
||||||
|
#include <fmgr.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue