29 #include "utils/elog.h"
30 #include "utils/geo_decls.h"
33 #include "../postgis_config.h"
34 #include "lwgeom_pg.h"
43 #define SHOW_DIGS_DOUBLE 15
44 #define MAX_DIGS_DOUBLE (SHOW_DIGS_DOUBLE + 6 + 1 + 3 + 1)
58 char *
str = PG_GETARG_CSTRING(0);
64 if (strstr(
str,
"BOX3D(") !=
str)
67 elog(ERROR,
"BOX3D parser - doesn't start with BOX3D(");
72 "BOX3D(%le %le %le ,%le %le %le)",
81 nitems = sscanf(
str,
"BOX3D(%le %le ,%le %le)", &box->
xmin, &box->
ymin, &box->
xmax, &box->
ymax);
87 "BOX3D parser - couldn't parse. It should look like: BOX3D(xmin ymin zmin,xmax ymax zmax) or BOX3D(xmin ymin,xmax ymax)");
94 float tmp = box->
xmin;
100 float tmp = box->
ymin;
106 float tmp = box->
zmin;
111 PG_RETURN_POINTER(box);
130 strcat(result,
"NULL");
131 PG_RETURN_CSTRING(result);
137 result = (
char *)palloc(size);
140 "BOX3D(%.15g %.15g %.15g,%.15g %.15g %.15g)",
148 PG_RETURN_CSTRING(result);
156 PG_RETURN_POINTER(out);
165 out->low.x = box->
xmin;
166 out->low.y = box->
ymin;
168 out->high.x = box->
xmax;
169 out->high.y = box->
ymax;
176 BOX *box = palloc(
sizeof(BOX));
179 PG_RETURN_POINTER(box);
288 static const int ngeoms = 6;
331 PG_RETURN_POINTER(result);
363 memcpy(result, box,
sizeof(
BOX3D));
368 double d = PG_GETARG_FLOAT8(1);
373 double dx = PG_GETARG_FLOAT8(1);
374 double dy = PG_GETARG_FLOAT8(2);
375 double dz = PG_GETARG_FLOAT8(3);
380 PG_RETURN_POINTER(result);
405 PG_RETURN_POINTER(result);
412 PG_RETURN_FLOAT8(Min(box->
xmin, box->
xmax));
419 PG_RETURN_FLOAT8(Min(box->
ymin, box->
ymax));
426 PG_RETURN_FLOAT8(Min(box->
zmin, box->
zmax));
433 PG_RETURN_FLOAT8(Max(box->
xmin, box->
xmax));
440 PG_RETURN_FLOAT8(Max(box->
ymin, box->
ymax));
447 PG_RETURN_FLOAT8(Max(box->
zmin, box->
zmax));
461 BOX3D *result = NULL;
474 result = palloc(
sizeof(
BOX3D));
475 memcpy(result, box,
sizeof(
BOX3D));
476 PG_RETURN_POINTER(result);
491 PG_FREE_IF_COPY(geom, 1);
495 result = palloc(
sizeof(
BOX3D));
496 memcpy(result, box,
sizeof(
BOX3D));
497 PG_RETURN_POINTER(result);
503 PG_FREE_IF_COPY(geom, 1);
506 PG_RETURN_POINTER(result);
509 result = palloc(
sizeof(
BOX3D));
518 PG_FREE_IF_COPY(geom, 1);
519 PG_RETURN_POINTER(result);
525 BOX3D *box0 = (
BOX3D *)(PG_ARGISNULL(0) ? NULL : PG_GETARG_POINTER(0));
526 BOX3D *box1 = (
BOX3D *)(PG_ARGISNULL(1) ? NULL : PG_GETARG_POINTER(1));
530 PG_RETURN_POINTER(box0);
533 PG_RETURN_POINTER(box1);
538 result = palloc(
sizeof(
BOX3D));
547 PG_RETURN_POINTER(result);
556 LWGEOM *minpoint, *maxpoint;
564 elog(ERROR,
"BOX3D_construct: args must be points");
569 elog(ERROR,
"BOX3D_construct: args can not be empty points");
578 result->
xmax = maxp.
x;
579 result->
ymax = maxp.
y;
580 result->
zmax = maxp.
z;
582 result->
xmin = minp.
x;
583 result->
ymin = minp.
y;
584 result->
zmin = minp.
z;
588 PG_RETURN_POINTER(result);
592 #if POSTGIS_PGSQL_VERSION > 100
608 PGDLLEXPORT Datum BOX3D_contains(PG_FUNCTION_ARGS)
610 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
611 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
613 PG_RETURN_BOOL(result);
625 PGDLLEXPORT Datum BOX3D_contained(PG_FUNCTION_ARGS)
627 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
628 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
630 PG_RETURN_BOOL(result);
644 PGDLLEXPORT Datum BOX3D_overlaps(PG_FUNCTION_ARGS)
646 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
647 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
649 PG_RETURN_BOOL(result);
663 PGDLLEXPORT Datum BOX3D_same(PG_FUNCTION_ARGS)
665 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
666 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
668 PG_RETURN_BOOL(result);
680 PGDLLEXPORT Datum BOX3D_left(PG_FUNCTION_ARGS)
682 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
683 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
685 PG_RETURN_BOOL(result);
697 PGDLLEXPORT Datum BOX3D_overleft(PG_FUNCTION_ARGS)
699 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
700 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
702 PG_RETURN_BOOL(result);
714 PGDLLEXPORT Datum BOX3D_right(PG_FUNCTION_ARGS)
716 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
717 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
719 PG_RETURN_BOOL(result);
731 PGDLLEXPORT Datum BOX3D_overright(PG_FUNCTION_ARGS)
733 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
734 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
736 PG_RETURN_BOOL(result);
748 PGDLLEXPORT Datum BOX3D_below(PG_FUNCTION_ARGS)
750 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
751 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
753 PG_RETURN_BOOL(result);
765 PGDLLEXPORT Datum BOX3D_overbelow(PG_FUNCTION_ARGS)
767 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
768 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
770 PG_RETURN_BOOL(result);
782 PGDLLEXPORT Datum BOX3D_above(PG_FUNCTION_ARGS)
784 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
785 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
787 PG_RETURN_BOOL(result);
799 PGDLLEXPORT Datum BOX3D_overabove(PG_FUNCTION_ARGS)
801 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
802 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
804 PG_RETURN_BOOL(result);
816 PGDLLEXPORT Datum BOX3D_front(PG_FUNCTION_ARGS)
818 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
819 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
821 PG_RETURN_BOOL(result);
833 PGDLLEXPORT Datum BOX3D_overfront(PG_FUNCTION_ARGS)
835 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
836 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
838 PG_RETURN_BOOL(result);
850 PGDLLEXPORT Datum BOX3D_back(PG_FUNCTION_ARGS)
852 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
853 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
855 PG_RETURN_BOOL(result);
867 PGDLLEXPORT Datum BOX3D_overback(PG_FUNCTION_ARGS)
869 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
870 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
872 PG_RETURN_BOOL(result);
919 return sqrt(sqrDist);
924 PGDLLEXPORT Datum BOX3D_distance(PG_FUNCTION_ARGS)
926 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
927 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
GBOX * box3d_to_gbox(const BOX3D *b3d)
BOX3D * box3d_from_gbox(const GBOX *gbox)
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void gserialized_set_srid(GSERIALIZED *g, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function).
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
void lwpoint_free(LWPOINT *pt)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
#define POLYHEDRALSURFACETYPE
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
void lwcollection_free(LWCOLLECTION *col)
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 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,...
void * lwalloc(size_t size)
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
void lwpoly_free(LWPOLY *poly)
#define LW_TRUE
Return types for functions with status returns.
#define SRID_UNKNOWN
Unknown SRID value.
#define FLAGS_SET_SOLID(flags, value)
void lwline_free(LWLINE *line)
This library is the generic geometry handling section of PostGIS.
Datum BOX3D_to_BOX(PG_FUNCTION_ARGS)
static void box3d_to_box_p(BOX3D *box, BOX *out)
Datum BOX3D_to_LWGEOM(PG_FUNCTION_ARGS)
Datum BOX3D_ymax(PG_FUNCTION_ARGS)
Datum BOX3D_zmax(PG_FUNCTION_ARGS)
Datum BOX3D_xmax(PG_FUNCTION_ARGS)
Datum BOX3D_combine(PG_FUNCTION_ARGS)
Datum BOX3D_zmin(PG_FUNCTION_ARGS)
static void expand_box3d_xyz(BOX3D *box, double dx, double dy, double dz)
PG_FUNCTION_INFO_V1(BOX3D_in)
BOX3D_in - takes a string rep of BOX3D and returns internal rep.
Datum BOX3D_construct(PG_FUNCTION_ARGS)
Datum BOX3D_to_BOX2D(PG_FUNCTION_ARGS)
Datum BOX3D_out(PG_FUNCTION_ARGS)
Datum BOX3D_in(PG_FUNCTION_ARGS)
Datum BOX3D_expand(PG_FUNCTION_ARGS)
void expand_box3d(BOX3D *box, double d)
Expand given box of 'd' units in all directions.
Datum LWGEOM_to_BOX3D(PG_FUNCTION_ARGS)
Datum BOX3D_xmin(PG_FUNCTION_ARGS)
Datum BOX3D_combine_BOX3D(PG_FUNCTION_ARGS)
Datum BOX3D_ymin(PG_FUNCTION_ARGS)
bool BOX3D_above_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_back_internal(BOX3D *box1, BOX3D *box2)
double BOX3D_distance_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overlaps_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_contains_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overabove_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_right_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overback_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overleft_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_below_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_left_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overright_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_same_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_contained_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_front_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overfront_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overbelow_internal(BOX3D *box1, BOX3D *box2)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)