]> granicus.if.org Git - postgis/commitdiff
added geometry(text) conversion function
authorDavid Blasby <dblasby@gmail.com>
Fri, 24 Aug 2001 21:02:11 +0000 (21:02 +0000)
committerDavid Blasby <dblasby@gmail.com>
Fri, 24 Aug 2001 21:02:11 +0000 (21:02 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@57 b70326c6-7e19-0410-871a-916f4a2858ee

postgis.sql.in
postgis_debug.c
postgis_inout.c
postgis_ops.c

index 097d70b036418be1214c3f93db0bcd9bd460bc9b..b7a1c9ef6f13a1028e8aed991214ac8830141503 100644 (file)
@@ -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@'
index ac97f8e3fcd9496a597af8f036454ef7a70b01d8..ccc04a4b91f48533866a30fa2121d76b0e0bb99e 100644 (file)
@@ -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);
+
+}
+
+
index 13af3ac986059b83bb9838b7d888a83230bd7dcb..caf540fad876785470378ee8390b08cf218b37f1 100644 (file)
@@ -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
+}
+
index 280578c9622e2264d00afafbfb131083a4140d4a..5823b5cb35e5b52a642547a7291a3763068f9035 100644 (file)
@@ -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
+}
+