-
#include "postgres.h"
#include <math.h>
#include "lwgeom.h"
+// This is an implementation of the functions defined in lwgeom.h
+
+
+//forward decs
+
extern float nextDown_f(double d);
extern float nextUp_f(double d);
extern double nextDown_d(float d);
} while (0)
+// returns the next smaller or next larger float
+// from x (in direction of y).
float nextafterf_custom(float x, float y)
{
int32_tt hx,hy,ix,iy;
}
+
+//Connvert BOX3D to BOX2D
BOX2DFLOAT4 *box3d_to_box2df(BOX3D *box)
{
BOX2DFLOAT4 *result = (BOX2DFLOAT4*) palloc(sizeof(BOX2DFLOAT4));
}
+//convert postgresql BOX to BOX2D
BOX2DFLOAT4 *box_to_box2df(BOX *box)
{
BOX2DFLOAT4 *result = (BOX2DFLOAT4*) palloc(sizeof(BOX2DFLOAT4));
return result;
}
+// convert BOX2D to BOX3D
BOX3D box2df_to_box3d(BOX2DFLOAT4 *box)
{
BOX3D result;
return result;
}
+
+// convert BOX2D to postgresql BOX
BOX box2df_to_box(BOX2DFLOAT4 *box)
{
BOX result;
return result;
}
+
+// returns a BOX3D that encloses b1 and b2
+// combine_boxes(NULL,A) --> A
+// combine_boxes(A,NULL) --> A
+// combine_boxes(A,B) --> A union B
BOX3D *combine_boxes(BOX3D *b1, BOX3D *b2)
{
BOX3D *result;
return result;
}
+
+// same as getbox2d, but modifies box instead of returning result on the stack
void getbox2d_p(char *serialized_form, BOX2DFLOAT4 *box)
{
int type = (unsigned char) serialized_form[0];
// basic type handling
+// returns true if this type says it has an SRID (S bit set)
bool lwgeom_hasSRID(unsigned char type)
{
return (type & 0x40);
}
+// returns either 2,3, or 4 -- 2=2D, 3=3D, 4=4D
int lwgeom_ndims(unsigned char type)
{
return ( (type & 0x30) >>4) +2;
}
+
+// get base type (ie. POLYGONTYPE)
int lwgeom_getType(unsigned char type)
{
return (type & 0x0F);
}
+
+//construct a type (hasBOX=false)
unsigned char lwgeom_makeType(int ndims, char hasSRID, int type)
{
unsigned char result = type;
return result;
}
+//construct a type
unsigned char lwgeom_makeType_full(int ndims, char hasSRID, int type, bool hasBBOX)
{
unsigned char result = type;
return result;
}
+//returns true if there's a bbox in this LWGEOM (B bit set)
bool lwgeom_hasBBOX(unsigned char type)
{
return (type & 0x80);
return getPoint2d(point->point,0);
}
+// convenience functions to hide the POINTARRAY
POINT3D lwpoint_getPoint3d(LWPOINT *point)
{
POINT3D result;
return lwpoint_deserialize(sub_geom);
}
+// 1st geometry has geom_number = 0
+// if the actual sub-geometry isnt a POINT, null is returned (see _gettype()).
+// if there arent enough geometries, return null.
+// this is fine to call on a point (with geom_num=0), multipoint or geometrycollection
LWPOINT *lwgeom_getpoint_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
{
char *sub_geom;
return lwline_deserialize(sub_geom);
}
+// 1st geometry has geom_number = 0
+// if the actual geometry isnt a LINE, null is returned (see _gettype()).
+// if there arent enough geometries, return null.
+// this is fine to call on a line, multiline or geometrycollection
LWLINE *lwgeom_getline_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
{
char *sub_geom;
return lwpoly_deserialize(sub_geom);
}
+// 1st geometry has geom_number = 0
+// if the actual geometry isnt a POLYGON, null is returned (see _gettype()).
+// if there arent enough geometries, return null.
+// this is fine to call on a polygon, multipolygon or geometrycollection
LWPOLY *lwgeom_getpoly_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
{
char *sub_geom;
return get_uint32(loc);
}
+// how many sub-geometries are there?
+// for point,line,polygon will return 1.
int lwgeom_getnumgeometries_inspected(LWGEOM_INSPECTED *inspected)
{
return inspected->ngeometries;
//get bounding box of LWGEOM (automatically calls the sub-geometries bbox generators)
-//dont forget to pfree()
+//dont forget to pfree() result
BOX3D *lw_geom_getBB(char *serialized_form)
{
LWGEOM_INSPECTED *inspected = lwgeom_inspect(serialized_form);
return result;
}
+//dont forget to pfree() result
BOX3D *lw_geom_getBB_simple(char *serialized_form)
{
char type = lwgeom_getType((unsigned char) serialized_form[0]);
loc +=4;
result = NULL;
-
+ // each sub-type
for (t=0;t<ngeoms;t++)
{
b1 = lw_geom_getBB_simple(loc);
}
-//dont forget to pfree()
+//dont forget to pfree() result
BOX3D *lw_geom_getBB_inspected(LWGEOM_INSPECTED *inspected)
{
int t;
#include "lwgeom.h"
#include "stringBuffer.h"
+// implementation GiST support and basic LWGEOM operations (like &&)
+
//#define DEBUG
//#define DEBUG_GIST
-
+// for debugging
int counter_leaf = 0;
int counter_intern = 0;
if (lwgeom_getnumgeometries(in+4) ==0) // this is the EMPTY geometry
{
-elog(NOTICE,"found an empty geometry");
+//elog(NOTICE,"found an empty geometry");
// dont bother adding this to the index
PG_RETURN_POINTER(entry);
}
//pfree(box3d);
//convert_box3d_to_box_p( &(query->bvol) , &thebox);
//thebox = getBOX2D_cache(query);
- getbox2d_p(query+4, &box);
+ getbox2d_p(query+4, &box);
if (GIST_LEAF(entry))
result = lwgeom_rtree_leaf_consistent((BOX2DFLOAT4 *) DatumGetPointer(entry->key), &box, strategy );
#ifdef DEBUG_GIST5
+//keep track and report info about how many times this is called
if (counter_intern == 0)
{
elog(NOTICE,"search bounding box is: <%.16g %.16g,%.16g %.16g> - size box2d= %i",
((query->ymax>= key->ymax) &&
(query->ymin<= key->ymax)));
#ifdef DEBUG_GIST5
+//keep track and report info about how many times this is called
+
elog(NOTICE,"%i:gist test (leaf) <%.6g %.6g,%.6g %.6g> && <%.6g %.6g,%.6g %.6g> --> %i",counter_leaf,key->xmin,key->ymin,key->xmax,key->ymax,
query->xmin,query->ymin,query->xmax,query->ymax, (int) retval);
#endif
PG_RETURN_POINTER(pageunion);
}
+
+// size of a box is width*height
+// we do this in double precision because width and height can be very very small
+// and it gives screwy results
static float size_box2d(Datum box2d)
{
return result;
}
+// size of a box is width*height
+// we do this in double precision because width and height can be very very small
+// and it gives screwy results
+// this version returns a double
static double size_box2d_double(Datum box2d);
static double size_box2d_double(Datum box2d)
{
PG_RETURN_POINTER(v);
}
-Datum report_lwgeom_gist_activity(PG_FUNCTION_ARGS);
+// debug function
+Datum report_lwgeom_gist_activity(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(report_lwgeom_gist_activity);
Datum report_lwgeom_gist_activity(PG_FUNCTION_ARGS)
{
elog(NOTICE,"lwgeom gist activity - internal consistency= %i, leaf consistency = %i",counter_intern,counter_leaf);
+ counter_intern =0; //reset
+ counter_leaf = 0;
PG_RETURN_NULL();
}
#include "stringBuffer.h"
-#define DEBUG
+//#define DEBUG
#include "wktparse.h"
Datum parse_WKT_lwgeom(PG_FUNCTION_ARGS);
+
+// included here so we can be independent from postgis
// WKB structure -- exactly the same as TEXT
typedef struct Well_known_bin {
int32 size; // total size of this structure
start =semicolonLoc[1]; // one in
}
+ // this is included just for redundancy (new parser can handle wkt and wkb)
+
if (
( (start >= '0') && (start <= '9') ) ||
( (start >= 'A') && (start <= 'F') )
}
-
+// for the parser/unparser -- it needs memory management functions
void *palloc_fn2(size_t size)
{
void * result;
-
+//convert LWGEOM to wkt (in TEXT format)
PG_FUNCTION_INFO_V1(LWGEOM_asText);
Datum LWGEOM_asText(PG_FUNCTION_ARGS)
{
}
+//for the wkt parser
void elog_ERROR(const char* string)
{
return result;
}
+
+// parse WKT input
+// parse_WKT_lwgeom(TEXT) -> LWGEOM
PG_FUNCTION_INFO_V1(parse_WKT_lwgeom);
Datum parse_WKT_lwgeom(PG_FUNCTION_ARGS)
{