2013-05-06 21:24:49 +04:00
|
|
|
package geos
|
|
|
|
|
|
|
|
/*
|
|
|
|
#cgo LDFLAGS: -lgeos_c
|
|
|
|
#include "geos_c.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-05-23 19:53:58 +04:00
|
|
|
extern void goLogString(char *msg);
|
2013-05-24 14:28:22 +04:00
|
|
|
extern void goSendQueryResult(size_t, void *);
|
2013-05-06 21:24:49 +04:00
|
|
|
|
|
|
|
void debug_wrap(const char *fmt, ...) {
|
|
|
|
va_list a_list;
|
|
|
|
va_start(a_list, fmt);
|
|
|
|
|
|
|
|
char buf[100];
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, a_list);
|
|
|
|
va_end(a_list);
|
2013-05-23 19:53:58 +04:00
|
|
|
goLogString((char *)&buf);
|
2013-05-06 21:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
GEOSContextHandle_t initGEOS_r_debug() {
|
|
|
|
return initGEOS_r(debug_wrap, debug_wrap);
|
|
|
|
}
|
2013-05-15 11:49:38 +04:00
|
|
|
|
|
|
|
void initGEOS_debug() {
|
|
|
|
return initGEOS(debug_wrap, debug_wrap);
|
|
|
|
}
|
2013-05-24 14:28:22 +04:00
|
|
|
|
|
|
|
// wrap goIndexSendQueryResult
|
|
|
|
void IndexQuerySendCallback(void *item, void *userdata) {
|
|
|
|
goIndexSendQueryResult((size_t)item, userdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexAdd(
|
|
|
|
GEOSContextHandle_t handle,
|
|
|
|
GEOSSTRtree *tree,
|
|
|
|
const GEOSGeometry *g,
|
|
|
|
size_t id)
|
|
|
|
{
|
|
|
|
// instead of storing a void *, we just store our id
|
|
|
|
// this is safe since GEOS doesn't access the item pointer
|
|
|
|
GEOSSTRtree_insert_r(handle, tree, g, (void *)id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// query with our custom callback
|
|
|
|
void IndexQuery(
|
|
|
|
GEOSContextHandle_t handle,
|
|
|
|
GEOSSTRtree *tree,
|
|
|
|
const GEOSGeometry *g,
|
|
|
|
void *userdata)
|
|
|
|
{
|
|
|
|
GEOSSTRtree_query_r(handle, tree, g, IndexQuerySendCallback, userdata);
|
|
|
|
}
|
2013-05-06 21:24:49 +04:00
|
|
|
*/
|
|
|
|
import "C"
|