28 #include "access/gist.h"
29 #include "access/itup.h"
31 #include "utils/elog.h"
32 #include "utils/geo_decls.h"
34 #include "../postgis_config.h"
35 #include "lwgeom_pg.h"
59 char *
str = PG_GETARG_CSTRING(0);
67 for(i = 0;
str[i]; i++) {
74 elog(ERROR,
"box2d parser - couldn't parse. It should look like: BOX(xmin ymin,xmax ymax)");
97 char tmp[500] = {
'B',
'O',
'X',
'(', 0};
102 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
105 memcpy(&box_aligned, box,
sizeof(
GBOX));
119 result = palloc(size + 1);
120 memcpy(
result, tmp, size + 1);
123 PG_RETURN_CSTRING(
result);
147 PG_FREE_IF_COPY(geom, 0);
178 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
179 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
181 PG_RETURN_BOOL(FPeq(box1->
xmax, box2->
xmax) &&
193 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
194 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
219 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
220 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
222 PG_RETURN_BOOL(FPle(box1->
xmax, box2->
xmax));
231 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
232 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
234 PG_RETURN_BOOL(FPlt(box1->
xmax, box2->
xmin));
243 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
244 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
246 PG_RETURN_BOOL(FPgt(box1->
xmin, box2->
xmax));
256 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
257 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
259 PG_RETURN_BOOL(FPge(box1->
xmin, box2->
xmin));
269 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
270 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
272 PG_RETURN_BOOL(FPle(box1->
ymax, box2->
ymax));
281 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
282 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
284 PG_RETURN_BOOL(FPlt(box1->
ymax, box2->
ymin));
293 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
294 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
296 PG_RETURN_BOOL(FPgt(box1->
ymin, box2->
ymax));
306 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
307 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
309 PG_RETURN_BOOL(FPge(box1->
ymin, box2->
ymin));
318 GBOX *box1 =(
GBOX *) PG_GETARG_POINTER(0);
319 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
321 PG_RETURN_BOOL(FPle(box1->
xmax, box2->
xmax) &&
333 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
334 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
336 PG_RETURN_BOOL(FPge(box1->
xmax, box2->
xmax) &&
346 GBOX *a = (
GBOX *) PG_GETARG_POINTER(0);
347 GBOX *b = (
GBOX *) PG_GETARG_POINTER(1);
366 PG_RETURN_POINTER(n);
376 GBOX *a = (
GBOX*) PG_GETARG_POINTER(0);
377 GBOX *b = (
GBOX*) PG_GETARG_POINTER(1);
382 PG_RETURN_POINTER(n);
389 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
395 double d = PG_GETARG_FLOAT8(1);
400 double dx = PG_GETARG_FLOAT8(1);
401 double dy = PG_GETARG_FLOAT8(2);
406 PG_RETURN_POINTER(
result);
412 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
414 PG_RETURN_POINTER(
result);
420 static const uint32_t box2d_idx = 0;
421 static const uint32_t geom_idx = 1;
425 if (PG_ARGISNULL(box2d_idx) && PG_ARGISNULL(geom_idx))
432 if (PG_ARGISNULL(box2d_idx))
438 PG_RETURN_POINTER(
result);
442 if (PG_ARGISNULL(geom_idx))
444 memcpy(
result, (
char *)PG_GETARG_DATUM(box2d_idx),
sizeof(
GBOX));
445 PG_RETURN_POINTER(
result);
453 memcpy(
result, (
char *)PG_GETARG_DATUM(box2d_idx),
sizeof(
GBOX));
454 PG_RETURN_POINTER(
result);
457 a = (
GBOX *)PG_GETARG_DATUM(box2d_idx);
465 PG_RETURN_POINTER(
result);
471 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
525 &points[2], &points[3]);
530 PG_RETURN_POINTER(
result);
540 double min, max, tmp;
548 elog(ERROR,
"BOX2D_construct: arguments must be points");
553 elog(ERROR,
"BOX2D_construct: args can not be empty points");
583 PG_RETURN_POINTER(
result);
char result[OUT_DOUBLE_BUFFER_SIZE]
int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout)
Update the output GBOX to be large enough to include both inputs.
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
BOX3D * box3d_from_gbox(const GBOX *gbox)
GBOX * gbox_new(lwflags_t flags)
Create a new gbox with the dimensionality indicated by the flags.
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm)
Move the box minimums down and the maximums up by the distances provided.
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
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.
int gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox)
Given a GSERIALIZED datum, as quickly as possible (peaking into the top of the memory) return the gbo...
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
void lwpoint_free(LWPOINT *pt)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
double lwpoint_get_x(const LWPOINT *point)
#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)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
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 lwpoly_free(LWPOLY *poly)
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
#define LW_TRUE
Return types for functions with status returns.
#define FLAGS_SET_M(flags, value)
#define SRID_UNKNOWN
Unknown SRID value.
#define FLAGS_SET_Z(flags, value)
void lwline_free(LWLINE *line)
double lwpoint_get_y(const LWPOINT *point)
This library is the generic geometry handling section of PostGIS.
int lwpoint_is_empty(const LWPOINT *point)
int lwprint_double(double d, int maxdd, char *buf)
Datum BOX2D_below(PG_FUNCTION_ARGS)
Datum BOX2D_left(PG_FUNCTION_ARGS)
Datum BOX2D_overleft(PG_FUNCTION_ARGS)
Datum BOX2D_contain(PG_FUNCTION_ARGS)
Datum BOX2D_overright(PG_FUNCTION_ARGS)
Datum BOX2D_contained(PG_FUNCTION_ARGS)
Datum LWGEOM_to_BOX2DF(PG_FUNCTION_ARGS)
Datum BOX2D_overabove(PG_FUNCTION_ARGS)
Datum BOX2D_right(PG_FUNCTION_ARGS)
Datum BOX2D_intersects(PG_FUNCTION_ARGS)
Datum BOX2D_construct(PG_FUNCTION_ARGS)
Datum BOX2D_overlap(PG_FUNCTION_ARGS)
Datum BOX2D_above(PG_FUNCTION_ARGS)
Datum BOX2D_union(PG_FUNCTION_ARGS)
Datum BOX2D_in(PG_FUNCTION_ARGS)
Datum LWGEOM_to_BOX2D(PG_FUNCTION_ARGS)
Datum BOX2D_same(PG_FUNCTION_ARGS)
Datum BOX2D_to_BOX3D(PG_FUNCTION_ARGS)
Datum BOX2D_out(PG_FUNCTION_ARGS)
Datum BOX2D_expand(PG_FUNCTION_ARGS)
Datum BOX2D_to_LWGEOM(PG_FUNCTION_ARGS)
Datum BOX2D_overbelow(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(BOX2D_in)
Datum BOX2D_combine(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)