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"
58 char *
str = PG_GETARG_CSTRING(0);
66 for(i = 0;
str[i]; i++) {
73 elog(ERROR,
"box2d parser - couldn't parse. It should look like: BOX(xmin ymin,xmax ymax)");
100 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
103 memcpy(&box_aligned, box,
sizeof(
GBOX));
106 "BOX(%.15g %.15g,%.15g %.15g)",
112 result= palloc(size+1);
113 memcpy(result,tmp,size+1);
116 PG_RETURN_CSTRING(result);
140 PG_FREE_IF_COPY(geom, 0);
159 PG_FREE_IF_COPY(geom, 0);
175 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
176 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
178 PG_RETURN_BOOL(FPeq(box1->
xmax, box2->
xmax) &&
190 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
191 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
195 result = ((FPge(box1->
xmax, box2->
xmax) &&
205 PG_RETURN_BOOL(result);
216 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
217 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
219 PG_RETURN_BOOL(FPle(box1->
xmax, box2->
xmax));
228 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
229 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
231 PG_RETURN_BOOL(FPlt(box1->
xmax, box2->
xmin));
240 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
241 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
243 PG_RETURN_BOOL(FPgt(box1->
xmin, box2->
xmax));
253 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
254 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
256 PG_RETURN_BOOL(FPge(box1->
xmin, box2->
xmin));
266 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
267 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
269 PG_RETURN_BOOL(FPle(box1->
ymax, box2->
ymax));
278 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
279 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
281 PG_RETURN_BOOL(FPlt(box1->
ymax, box2->
ymin));
290 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
291 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
293 PG_RETURN_BOOL(FPgt(box1->
ymin, box2->
ymax));
303 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
304 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
306 PG_RETURN_BOOL(FPge(box1->
ymin, box2->
ymin));
315 GBOX *box1 =(
GBOX *) PG_GETARG_POINTER(0);
316 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
318 PG_RETURN_BOOL(FPle(box1->
xmax, box2->
xmax) &&
330 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
331 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
333 PG_RETURN_BOOL(FPge(box1->
xmax, box2->
xmax) &&
343 GBOX *a = (
GBOX *) PG_GETARG_POINTER(0);
344 GBOX *b = (
GBOX *) PG_GETARG_POINTER(1);
363 PG_RETURN_POINTER(n);
373 GBOX *a = (
GBOX*) PG_GETARG_POINTER(0);
374 GBOX *b = (
GBOX*) PG_GETARG_POINTER(1);
379 PG_RETURN_POINTER(n);
386 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
388 memcpy(result, box,
sizeof(
GBOX));
392 double d = PG_GETARG_FLOAT8(1);
397 double dx = PG_GETARG_FLOAT8(1);
398 double dy = PG_GETARG_FLOAT8(2);
403 PG_RETURN_POINTER(result);
409 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
411 PG_RETURN_POINTER(result);
417 Pointer box2d_ptr = PG_GETARG_POINTER(0);
418 Pointer geom_ptr = PG_GETARG_POINTER(1);
423 if ( (box2d_ptr == NULL) && (geom_ptr == NULL) )
428 result = (
GBOX *)palloc(
sizeof(
GBOX));
430 if (box2d_ptr == NULL)
432 lwgeom = PG_GETARG_GSERIALIZED_P(1);
435 memcpy(result, &box,
sizeof(
GBOX));
436 PG_RETURN_POINTER(result);
440 if (geom_ptr == NULL)
442 memcpy(result, (
char *)PG_GETARG_DATUM(0),
sizeof(
GBOX));
443 PG_RETURN_POINTER(result);
448 lwgeom = PG_GETARG_GSERIALIZED_P(1);
452 memcpy(result, (
char *)PG_GETARG_DATUM(0),
sizeof(
GBOX));
453 PG_RETURN_POINTER(result);
456 a = (
GBOX *)PG_GETARG_DATUM(0);
464 PG_RETURN_POINTER(result);
470 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
524 &points[2], &points[3]);
529 PG_RETURN_POINTER(result);
539 double min, max, tmp;
547 elog(ERROR,
"BOX2D_construct: arguments must be points");
552 elog(ERROR,
"BOX2D_construct: args can not be empty points");
582 PG_RETURN_POINTER(result);
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)
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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)
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)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)