29 #include "utils/elog.h"
30 #include "utils/geo_decls.h"
33 #include "../postgis_config.h"
34 #include "lwgeom_pg.h"
57 char *
str = PG_GETARG_CSTRING(0);
63 if (strstr(
str,
"BOX3D(") !=
str)
66 elog(ERROR,
"BOX3D parser - doesn't start with BOX3D(");
71 "BOX3D(%le %le %le ,%le %le %le)",
80 nitems = sscanf(
str,
"BOX3D(%le %le ,%le %le)", &box->
xmin, &box->
ymin, &box->
xmax, &box->
ymax);
86 "BOX3D parser - couldn't parse. It should look like: BOX3D(xmin ymin zmin,xmax ymax zmax) or BOX3D(xmin ymin,xmax ymax)");
93 float tmp = box->
xmin;
99 float tmp = box->
ymin;
105 float tmp = box->
zmin;
110 PG_RETURN_POINTER(box);
132 PG_RETURN_CSTRING(
result);
135 result = (
char *)palloc(size);
156 PG_RETURN_CSTRING(
result);
164 PG_RETURN_POINTER(out);
173 out->low.x = box->
xmin;
174 out->low.y = box->
ymin;
176 out->high.x = box->
xmax;
177 out->high.y = box->
ymax;
184 BOX *box = palloc(
sizeof(BOX));
187 PG_RETURN_POINTER(box);
296 static const int ngeoms = 6;
333 result = geometry_serialize(geom);
339 PG_RETURN_POINTER(
result);
376 double d = PG_GETARG_FLOAT8(1);
381 double dx = PG_GETARG_FLOAT8(1);
382 double dy = PG_GETARG_FLOAT8(2);
383 double dz = PG_GETARG_FLOAT8(3);
388 PG_RETURN_POINTER(
result);
413 PG_RETURN_POINTER(
result);
420 PG_RETURN_FLOAT8(Min(box->
xmin, box->
xmax));
427 PG_RETURN_FLOAT8(Min(box->
ymin, box->
ymax));
434 PG_RETURN_FLOAT8(Min(box->
zmin, box->
zmax));
441 PG_RETURN_FLOAT8(Max(box->
xmin, box->
xmax));
448 PG_RETURN_FLOAT8(Max(box->
ymin, box->
ymax));
455 PG_RETURN_FLOAT8(Max(box->
zmin, box->
zmax));
484 PG_RETURN_POINTER(
result);
499 PG_FREE_IF_COPY(geom, 1);
505 PG_RETURN_POINTER(
result);
511 PG_FREE_IF_COPY(geom, 1);
514 PG_RETURN_POINTER(
result);
526 PG_FREE_IF_COPY(geom, 1);
527 PG_RETURN_POINTER(
result);
533 BOX3D *box0 = (
BOX3D *)(PG_ARGISNULL(0) ? NULL : PG_GETARG_POINTER(0));
534 BOX3D *box1 = (
BOX3D *)(PG_ARGISNULL(1) ? NULL : PG_GETARG_POINTER(1));
538 PG_RETURN_POINTER(box0);
541 PG_RETURN_POINTER(box1);
555 PG_RETURN_POINTER(
result);
564 LWGEOM *minpoint, *maxpoint;
572 elog(ERROR,
"BOX3D_construct: args must be points");
577 elog(ERROR,
"BOX3D_construct: args can not be empty points");
596 PG_RETURN_POINTER(
result);
617 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
618 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
634 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
635 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
653 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
654 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
672 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
673 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
689 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
690 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
706 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
707 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
723 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
724 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
740 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
741 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
757 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
758 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
774 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
775 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
791 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
792 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
808 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
809 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
825 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
826 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
842 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
843 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
859 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
860 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
876 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
877 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
926 return sqrt(sqrDist);
933 BOX3D *box1 = PG_GETARG_BOX3D_P(0);
934 BOX3D *box2 = PG_GETARG_BOX3D_P(1);
char result[OUT_DOUBLE_BUFFER_SIZE]
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.
#define OUT_MAX_BYTES_DOUBLE
int lwprint_double(double d, int maxdd, char *buf)
PGDLLEXPORT Datum BOX3D_below(PG_FUNCTION_ARGS)
bool BOX3D_above_internal(BOX3D *box1, BOX3D *box2)
PGDLLEXPORT Datum BOX3D_left(PG_FUNCTION_ARGS)
bool BOX3D_back_internal(BOX3D *box1, BOX3D *box2)
PGDLLEXPORT Datum BOX3D_overlaps(PG_FUNCTION_ARGS)
Datum BOX3D_to_BOX(PG_FUNCTION_ARGS)
static void box3d_to_box_p(BOX3D *box, BOX *out)
Datum BOX3D_to_LWGEOM(PG_FUNCTION_ARGS)
PGDLLEXPORT Datum BOX3D_contained(PG_FUNCTION_ARGS)
PGDLLEXPORT Datum BOX3D_overfront(PG_FUNCTION_ARGS)
Datum BOX3D_ymax(PG_FUNCTION_ARGS)
Datum BOX3D_zmax(PG_FUNCTION_ARGS)
PGDLLEXPORT Datum BOX3D_front(PG_FUNCTION_ARGS)
Datum BOX3D_xmax(PG_FUNCTION_ARGS)
Datum BOX3D_combine(PG_FUNCTION_ARGS)
Datum BOX3D_zmin(PG_FUNCTION_ARGS)
double BOX3D_distance_internal(BOX3D *box1, BOX3D *box2)
static void expand_box3d_xyz(BOX3D *box, double dx, double dy, double dz)
bool BOX3D_overlaps_internal(BOX3D *box1, BOX3D *box2)
PG_FUNCTION_INFO_V1(BOX3D_in)
BOX3D_in - takes a string rep of BOX3D and returns internal rep.
PGDLLEXPORT Datum BOX3D_overright(PG_FUNCTION_ARGS)
Datum BOX3D_construct(PG_FUNCTION_ARGS)
bool BOX3D_contains_internal(BOX3D *box1, BOX3D *box2)
needed for sp-gist support PostgreSQL 11+
Datum BOX3D_to_BOX2D(PG_FUNCTION_ARGS)
bool BOX3D_overabove_internal(BOX3D *box1, BOX3D *box2)
PGDLLEXPORT Datum BOX3D_overleft(PG_FUNCTION_ARGS)
Datum BOX3D_out(PG_FUNCTION_ARGS)
bool BOX3D_right_internal(BOX3D *box1, BOX3D *box2)
Datum BOX3D_in(PG_FUNCTION_ARGS)
bool BOX3D_overback_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overleft_internal(BOX3D *box1, BOX3D *box2)
PGDLLEXPORT Datum BOX3D_contains(PG_FUNCTION_ARGS)
needed for sp-gist support PostgreSQL 11+
bool BOX3D_below_internal(BOX3D *box1, BOX3D *box2)
PGDLLEXPORT Datum BOX3D_back(PG_FUNCTION_ARGS)
PGDLLEXPORT Datum BOX3D_overback(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.
PGDLLEXPORT Datum BOX3D_above(PG_FUNCTION_ARGS)
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)
Datum LWGEOM_to_BOX3D(PG_FUNCTION_ARGS)
Datum BOX3D_xmin(PG_FUNCTION_ARGS)
bool BOX3D_front_internal(BOX3D *box1, BOX3D *box2)
bool BOX3D_overfront_internal(BOX3D *box1, BOX3D *box2)
PGDLLEXPORT Datum BOX3D_right(PG_FUNCTION_ARGS)
PGDLLEXPORT Datum BOX3D_overabove(PG_FUNCTION_ARGS)
PGDLLEXPORT Datum BOX3D_overbelow(PG_FUNCTION_ARGS)
PGDLLEXPORT Datum BOX3D_same(PG_FUNCTION_ARGS)
bool BOX3D_overbelow_internal(BOX3D *box1, BOX3D *box2)
Datum BOX3D_combine_BOX3D(PG_FUNCTION_ARGS)
Datum BOX3D_ymin(PG_FUNCTION_ARGS)
PGDLLEXPORT Datum BOX3D_distance(PG_FUNCTION_ARGS)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)