28 #include "utils/elog.h" 29 #include "utils/geo_decls.h" 31 #include "../postgis_config.h" 32 #include "lwgeom_pg.h" 41 #define SHOW_DIGS_DOUBLE 15 42 #define MAX_DIGS_DOUBLE (SHOW_DIGS_DOUBLE + 6 + 1 + 3 +1) 74 char *str = PG_GETARG_CSTRING(0);
83 if (strstr(str,
"BOX3D(") != str )
86 elog(ERROR,
"BOX3D parser - doesn't start with BOX3D(");
90 nitems = sscanf(str,
"BOX3D(%le %le %le ,%le %le %le)",
95 nitems = sscanf(str,
"BOX3D(%le %le ,%le %le)",
100 elog(ERROR,
"BOX3D parser - couldnt parse. It should look like: BOX3D(xmin ymin zmin,xmax ymax zmax) or BOX3D(xmin ymin,xmax ymax)");
107 float tmp = box->
xmin;
113 float tmp = box->
ymin;
119 float tmp = box->
zmin;
124 PG_RETURN_POINTER(box);
144 strcat(result,
"NULL");
145 PG_RETURN_CSTRING(result);
152 result = (
char *) palloc(size);
154 sprintf(result,
"BOX3D(%.15g %.15g %.15g,%.15g %.15g %.15g)",
158 PG_RETURN_CSTRING(result);
167 PG_RETURN_POINTER(out);
175 out->low.x = box->
xmin;
176 out->low.y = box->
ymin;
178 out->high.x = box->
xmax;
179 out->high.y = box->
ymax;
186 BOX *box = palloc(
sizeof(BOX));
189 PG_RETURN_POINTER(box);
231 else if (((box->
xmin == box->
xmax ||
268 &points[0], &points[1], &points[2], &points[3]);
285 &points[0], &points[1], &points[2], &points[3]);
302 &points[0], &points[1], &points[2], &points[3]);
310 static const int ngeoms = 6;
326 &points[0], &points[1], &points[2], &points[3]));
329 &points[4], &points[7], &points[6], &points[5]));
332 &points[0], &points[4], &points[5], &points[1]));
335 &points[3], &points[2], &points[6], &points[7]));
338 &points[0], &points[3], &points[7], &points[4]));
341 &points[1], &points[5], &points[6], &points[2]));
354 PG_RETURN_POINTER(result);
386 memcpy(result, box,
sizeof(
BOX3D));
388 if (PG_NARGS() == 2) {
390 double d = PG_GETARG_FLOAT8(1);
395 double dx = PG_GETARG_FLOAT8(1);
396 double dy = PG_GETARG_FLOAT8(2);
397 double dz = PG_GETARG_FLOAT8(3);
402 PG_RETURN_POINTER(result);
428 PG_RETURN_POINTER(result);
435 PG_RETURN_FLOAT8(Min(box->
xmin, box->
xmax));
442 PG_RETURN_FLOAT8(Min(box->
ymin, box->
ymax));
449 PG_RETURN_FLOAT8(Min(box->
zmin, box->
zmax));
456 PG_RETURN_FLOAT8(Max(box->
xmin, box->
xmax));
463 PG_RETURN_FLOAT8(Max(box->
ymin, box->
ymax));
470 PG_RETURN_FLOAT8(Max(box->
zmin, box->
zmax));
484 BOX3D *result = NULL;
490 if ( (box == NULL) && (geom == NULL) )
496 result = palloc(
sizeof(
BOX3D));
497 memcpy(result, box,
sizeof(
BOX3D));
498 PG_RETURN_POINTER(result);
511 PG_FREE_IF_COPY(geom, 1);
515 result = palloc(
sizeof(
BOX3D));
516 memcpy(result, box,
sizeof(
BOX3D));
517 PG_RETURN_POINTER(result);
523 PG_FREE_IF_COPY(geom, 1);
526 PG_RETURN_POINTER(result);
529 result = palloc(
sizeof(
BOX3D));
538 PG_FREE_IF_COPY(geom, 1);
539 PG_RETURN_POINTER(result);
545 BOX3D *box0 = (
BOX3D*)(PG_ARGISNULL(0) ? NULL : PG_GETARG_POINTER(0));
546 BOX3D *box1 = (
BOX3D*)(PG_ARGISNULL(1) ? NULL : PG_GETARG_POINTER(1));
550 PG_RETURN_POINTER(box0);
553 PG_RETURN_POINTER(box1);
558 result = palloc(
sizeof(
BOX3D));
567 PG_RETURN_POINTER(result);
576 LWGEOM *minpoint, *maxpoint;
585 elog(ERROR,
"BOX3D_construct: args must be points");
594 result->
xmax = maxp.
x;
595 result->
ymax = maxp.
y;
596 result->
zmax = maxp.
z;
598 result->
xmin = minp.
x;
599 result->
ymin = minp.
y;
600 result->
zmin = minp.
z;
604 PG_RETURN_POINTER(result);
#define FLAGS_SET_SOLID(flags, value)
Datum BOX3D_ymax(PG_FUNCTION_ARGS)
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
void lwpoint_free(LWPOINT *pt)
void lwgeom_free(LWGEOM *geom)
void lwline_free(LWLINE *line)
void gserialized_set_srid(GSERIALIZED *s, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function)...
Datum BOX3D_in(PG_FUNCTION_ARGS)
#define POLYHEDRALSURFACETYPE
Datum BOX3D_combine(PG_FUNCTION_ARGS)
void error_if_srid_mismatch(int srid1, int srid2)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Datum BOX3D_out(PG_FUNCTION_ARGS)
Datum BOX3D_construct(PG_FUNCTION_ARGS)
static void expand_box3d_xyz(BOX3D *box, double dx, double dy, double dz)
Datum BOX3D_zmax(PG_FUNCTION_ARGS)
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
Datum BOX3D_to_LWGEOM(PG_FUNCTION_ARGS)
void lwpoly_free(LWPOLY *poly)
#define LW_TRUE
Return types for functions with status returns.
Datum BOX3D_xmin(PG_FUNCTION_ARGS)
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
#define SRID_UNKNOWN
Unknown SRID value.
void expand_box3d(BOX3D *box, double d)
Expand given box of 'd' units in all directions.
Datum BOX3D_to_BOX2D(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(BOX3D_in)
BOX3D_in - takes a string rep of BOX3D and returns internal rep.
Datum LWGEOM_to_BOX3D(PG_FUNCTION_ARGS)
GBOX * box3d_to_gbox(const BOX3D *b3d)
BOX3D * box3d_from_gbox(const GBOX *gbox)
Datum BOX3D_ymin(PG_FUNCTION_ARGS)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
static void box3d_to_box_p(BOX3D *box, BOX *out)
Datum BOX3D_xmax(PG_FUNCTION_ARGS)
Datum BOX3D_expand(PG_FUNCTION_ARGS)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Datum BOX3D_combine_BOX3D(PG_FUNCTION_ARGS)
Datum BOX3D_zmin(PG_FUNCTION_ARGS)
void lwcollection_free(LWCOLLECTION *col)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
void * lwalloc(size_t size)
Datum BOX3D_to_BOX(PG_FUNCTION_ARGS)
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
This library is the generic geometry handling section of PostGIS.