From e26876d52267435f41ab4fe38ac094e9e44e72e1 Mon Sep 17 00:00:00 2001 From: David Blasby Date: Fri, 24 Aug 2001 21:02:11 +0000 Subject: [PATCH] added geometry(text) conversion function git-svn-id: http://svn.osgeo.org/postgis/trunk@57 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis.sql.in | 12 +++++++ postgis_debug.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++- postgis_inout.c | 14 +++++++- postgis_ops.c | 3 +- 4 files changed, 121 insertions(+), 3 deletions(-) diff --git a/postgis.sql.in b/postgis.sql.in index 097d70b03..b7a1c9ef6 100644 --- a/postgis.sql.in +++ b/postgis.sql.in @@ -279,6 +279,12 @@ CREATE FUNCTION geometry(BOX3D) AS '@MODULE_FILENAME@','get_geometry_of_bbox' LANGUAGE 'c' WITH (iscachable,isstrict); +CREATE FUNCTION geometry(text) + RETURNS GEOMETRY + AS '@MODULE_FILENAME@','geometry_text' + LANGUAGE 'c' WITH (iscachable,isstrict); + + CREATE FUNCTION expand(BOX3D,float8) RETURNS BOX3D AS '@MODULE_FILENAME@','expand_bbox' @@ -300,6 +306,12 @@ CREATE FUNCTION asbinary(GEOMETRY,TEXT) ---- Debug (info) functions + +--CREATE FUNCTION index_thing(GEOMETRY) +-- RETURNS BOOL +-- AS '@MODULE_FILENAME@' +-- LANGUAGE 'c' with (isstrict); + CREATE FUNCTION npoints(GEOMETRY) RETURNS INT4 AS '@MODULE_FILENAME@' diff --git a/postgis_debug.c b/postgis_debug.c index ac97f8e3f..ccc04a4b9 100644 --- a/postgis_debug.c +++ b/postgis_debug.c @@ -76,6 +76,11 @@ void print_box(BOX3D *box) printf(" + URT = [%g,%g,%g]\n", box->URT.x, box->URT.y,box->URT.z); } +void print_box2d(BOX *box) +{ + printf (" BOX[%g %g , %g %g] ",box->low.x, box->low.y, box->high.x, box->high.y); +} + //debug function - whats really in that BOX3D? void print_box_oneline(BOX3D *box) { @@ -727,4 +732,92 @@ char *print_geometry(GEOMETRY *geom) void print_point_debug(POINT3D *p) { printf("[%g %g %g]\n",p->x,p->y,p->z); -} \ No newline at end of file +} + + + + +#include "access/gist.h" +#include "access/genam.h" + +//not quite sure how the IndexTuple is set up - should be using its accessors +// instead of just grabbing know-location data. +//You might need to do some locking here to ensure consistency (ie. someone changing the index +// during this search). +static void +gist_dumptree(Relation r, int level, BlockNumber blk, OffsetNumber coff) +{ + Buffer buffer; + Page page; + GISTPageOpaque opaque; + IndexTuple which; + ItemId iid; + OffsetNumber i, + maxoff; + BlockNumber cblk; + char *pred; + int32 srid; + BOX *box; + + pred = (char *) palloc(sizeof(char) * level + 1); + MemSet(pred, '\t', level); + pred[level] = '\0'; + + buffer = ReadBuffer(r, blk); + page = (Page) BufferGetPage(buffer); + opaque = (GISTPageOpaque) PageGetSpecialPointer(page); + + maxoff = PageGetMaxOffsetNumber(page); + + elog(NOTICE, "%sPage: %d %s blk: %d maxoff: %d free: %d", pred, coff, (opaque->flags & F_LEAF) ? "LEAF" : "INTE", (int) blk, (int) maxoff, PageGetFreeSpace(page)); + + for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) + { + iid = PageGetItemId(page, i); + which = (IndexTuple) PageGetItem(page, iid); + cblk = ItemPointerGetBlockNumber(&(which->t_tid)); + + elog(NOTICE, "%s Tuple. blk: %d size: %d", pred, (int) cblk, IndexTupleSize(which)); + + // dump_bytes( which, 56); + + box = (BOX*) &(((char *) which)[16]); + + print_box2d( box) ; printf("\n"); + // srid = * ((int32 *) &(((char *) which)[47])); + // printf( ", srid=%i\n",srid); + + + + if (!(opaque->flags & F_LEAF)) + gist_dumptree(r, level + 1, cblk, i); + } + ReleaseBuffer(buffer); + pfree(pred); +} + + +//currently just calls the dumptree command. +// future: +// 1. have index name as parameter +// 2. check to make sure the given index is actually a gist geometry index +// 3. change gist_dumptree so it accumulates a bbox +// 4. return the accumulated bbox +PG_FUNCTION_INFO_V1(index_thing); +Datum index_thing(PG_FUNCTION_ARGS) +{ + Relation r; + + printf("inside indexthing; sizeof(GEOMETRYKEY) = %i,sizeof(GISTENTRY) = %i\n", sizeof(GEOMETRYKEY) ,sizeof(GISTENTRY)); + + r= index_openr( "quicky" ); +gist_dumptree(r, 0, GISTP_ROOT, 0); +index_close( r ); + + printf("finished indexthing\n"); + + PG_RETURN_BOOL(FALSE); + +} + + diff --git a/postgis_inout.c b/postgis_inout.c index 13af3ac98..caf540fad 100644 --- a/postgis_inout.c +++ b/postgis_inout.c @@ -2780,7 +2780,18 @@ printf("requested NDR\n"); } } +//takes a text argument and parses it to make a geometry +PG_FUNCTION_INFO_V1(geometry_text); +Datum geometry_text(PG_FUNCTION_ARGS) +{ + char *input = (char *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + + input = &input[4]; + PG_RETURN_POINTER ( + DatumGetPointer( DirectFunctionCall1(geometry_in,PointerGetDatum(input))) + ); +} @@ -3042,4 +3053,5 @@ LINE3D *make_line(int npoints, POINT3D *pts, int *size) memcpy( result->points, pts, npoints*sizeof(POINT3D) ); return result; -} \ No newline at end of file +} + diff --git a/postgis_ops.c b/postgis_ops.c index 280578c96..5823b5cb3 100644 --- a/postgis_ops.c +++ b/postgis_ops.c @@ -1292,4 +1292,5 @@ bool rtree_internal_consistent(BOX *key, GISTENTRY *rtree_decompress(PG_FUNCTION_ARGS) { return((GISTENTRY*)PG_GETARG_POINTER(0)); -} \ No newline at end of file +} + -- 2.40.0