29 #include "utils/elog.h"
30 #include "utils/geo_decls.h"
32 #include "../postgis_config.h"
33 #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");
573 result->
xmax = maxp.
x;
574 result->
ymax = maxp.
y;
575 result->
zmax = maxp.
z;
577 result->
xmin = minp.
x;
578 result->
ymin = minp.
y;
579 result->
zmin = minp.
z;
583 PG_RETURN_POINTER(result);
587 #if POSTGIS_PGSQL_VERSION > 100
603 PGDLLEXPORT Datum BOX3D_contains(PG_FUNCTION_ARGS)
605 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
606 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
608 PG_RETURN_BOOL(result);
620 PGDLLEXPORT Datum BOX3D_contained(PG_FUNCTION_ARGS)
622 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
623 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
625 PG_RETURN_BOOL(result);
639 PGDLLEXPORT Datum BOX3D_overlaps(PG_FUNCTION_ARGS)
641 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
642 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
644 PG_RETURN_BOOL(result);
658 PGDLLEXPORT Datum BOX3D_same(PG_FUNCTION_ARGS)
660 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
661 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
663 PG_RETURN_BOOL(result);
675 PGDLLEXPORT Datum BOX3D_left(PG_FUNCTION_ARGS)
677 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
678 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
680 PG_RETURN_BOOL(result);
692 PGDLLEXPORT Datum BOX3D_overleft(PG_FUNCTION_ARGS)
694 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
695 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
697 PG_RETURN_BOOL(result);
709 PGDLLEXPORT Datum BOX3D_right(PG_FUNCTION_ARGS)
711 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
712 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
714 PG_RETURN_BOOL(result);
726 PGDLLEXPORT Datum BOX3D_overright(PG_FUNCTION_ARGS)
728 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
729 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
731 PG_RETURN_BOOL(result);
743 PGDLLEXPORT Datum BOX3D_below(PG_FUNCTION_ARGS)
745 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
746 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
748 PG_RETURN_BOOL(result);
760 PGDLLEXPORT Datum BOX3D_overbelow(PG_FUNCTION_ARGS)
762 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
763 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
765 PG_RETURN_BOOL(result);
777 PGDLLEXPORT Datum BOX3D_above(PG_FUNCTION_ARGS)
779 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
780 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
782 PG_RETURN_BOOL(result);
794 PGDLLEXPORT Datum BOX3D_overabove(PG_FUNCTION_ARGS)
796 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
797 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
799 PG_RETURN_BOOL(result);
811 PGDLLEXPORT Datum BOX3D_front(PG_FUNCTION_ARGS)
813 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
814 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
816 PG_RETURN_BOOL(result);
828 PGDLLEXPORT Datum BOX3D_overfront(PG_FUNCTION_ARGS)
830 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
831 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
833 PG_RETURN_BOOL(result);
845 PGDLLEXPORT Datum BOX3D_back(PG_FUNCTION_ARGS)
847 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
848 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
850 PG_RETURN_BOOL(result);
862 PGDLLEXPORT Datum BOX3D_overback(PG_FUNCTION_ARGS)
864 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
865 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
867 PG_RETURN_BOOL(result);
914 return sqrt(sqrDist);
919 PGDLLEXPORT Datum BOX3D_distance(PG_FUNCTION_ARGS)
921 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
922 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
GBOX * box3d_to_gbox(const BOX3D *b3d)
BOX3D * box3d_from_gbox(const GBOX *gbox)
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).
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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.
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(int 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)
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
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)
void error_if_srid_mismatch(int srid1, int srid2)
void lwpoly_free(LWPOLY *poly)
#define LW_TRUE
Return types for functions with status returns.
#define SRID_UNKNOWN
Unknown SRID value.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
#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)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)