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"
60 char *str = PG_GETARG_CSTRING(0);
68 for(i = 0; str[i]; i++) {
69 str[i] = tolower(str[i]);
72 nitems = sscanf(str,
"box(%lf %lf,%lf %lf)", &box.
xmin, &box.
ymin, &box.
xmax, &box.
ymax);
75 elog(ERROR,
"box2d parser - couldn't parse. It should look like: BOX(xmin ymin,xmax ymax)");
102 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
105 memcpy(&box_aligned, box,
sizeof(
GBOX));
108 "BOX(%.15g %.15g,%.15g %.15g)",
114 result= palloc(size+1);
115 memcpy(result,tmp,size+1);
118 PG_RETURN_CSTRING(result);
142 PG_FREE_IF_COPY(geom, 0);
161 PG_FREE_IF_COPY(geom, 0);
177 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
178 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
180 PG_RETURN_BOOL(FPeq(box1->
xmax, box2->
xmax) &&
192 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
193 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
197 result = ((FPge(box1->
xmax, box2->
xmax) &&
207 PG_RETURN_BOOL(result);
218 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
219 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
221 PG_RETURN_BOOL(FPle(box1->
xmax, box2->
xmax));
230 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
231 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
233 PG_RETURN_BOOL(FPlt(box1->
xmax, box2->
xmin));
242 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
243 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
245 PG_RETURN_BOOL(FPgt(box1->
xmin, box2->
xmax));
255 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
256 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
258 PG_RETURN_BOOL(FPge(box1->
xmin, box2->
xmin));
268 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
269 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
271 PG_RETURN_BOOL(FPle(box1->
ymax, box2->
ymax));
280 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
281 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
283 PG_RETURN_BOOL(FPlt(box1->
ymax, box2->
ymin));
292 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
293 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
295 PG_RETURN_BOOL(FPgt(box1->
ymin, box2->
ymax));
305 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
306 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
308 PG_RETURN_BOOL(FPge(box1->
ymin, box2->
ymin));
317 GBOX *box1 =(
GBOX *) PG_GETARG_POINTER(0);
318 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
320 PG_RETURN_BOOL(FPle(box1->
xmax, box2->
xmax) &&
332 GBOX *box1 = (
GBOX *) PG_GETARG_POINTER(0);
333 GBOX *box2 = (
GBOX *) PG_GETARG_POINTER(1);
335 PG_RETURN_BOOL(FPge(box1->
xmax, box2->
xmax) &&
345 GBOX *a = (
GBOX *) PG_GETARG_POINTER(0);
346 GBOX *b = (
GBOX *) PG_GETARG_POINTER(1);
365 PG_RETURN_POINTER(n);
375 GBOX *a = (
GBOX*) PG_GETARG_POINTER(0);
376 GBOX *b = (
GBOX*) PG_GETARG_POINTER(1);
381 PG_RETURN_POINTER(n);
388 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
390 memcpy(result, box,
sizeof(
GBOX));
394 double d = PG_GETARG_FLOAT8(1);
399 double dx = PG_GETARG_FLOAT8(1);
400 double dy = PG_GETARG_FLOAT8(2);
405 PG_RETURN_POINTER(result);
411 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
413 PG_RETURN_POINTER(result);
419 Pointer box2d_ptr = PG_GETARG_POINTER(0);
420 Pointer geom_ptr = PG_GETARG_POINTER(1);
425 if ( (box2d_ptr == NULL) && (geom_ptr == NULL) )
430 result = (
GBOX *)palloc(
sizeof(
GBOX));
432 if (box2d_ptr == NULL)
434 lwgeom = PG_GETARG_GSERIALIZED_P(1);
437 memcpy(result, &box,
sizeof(
GBOX));
438 PG_RETURN_POINTER(result);
442 if (geom_ptr == NULL)
444 memcpy(result, (
char *)PG_GETARG_DATUM(0),
sizeof(
GBOX));
445 PG_RETURN_POINTER(result);
450 lwgeom = PG_GETARG_GSERIALIZED_P(1);
454 memcpy(result, (
char *)PG_GETARG_DATUM(0),
sizeof(
GBOX));
455 PG_RETURN_POINTER(result);
458 a = (
GBOX *)PG_GETARG_DATUM(0);
466 PG_RETURN_POINTER(result);
472 GBOX *box = (
GBOX *)PG_GETARG_POINTER(0);
526 &points[2], &points[3]);
531 PG_RETURN_POINTER(result);
541 double min, max, tmp;
548 elog(ERROR,
"GBOX_construct: arguments must be points");
580 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.
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
BOX3D * box3d_from_gbox(const GBOX *gbox)
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.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
LWPOINT * lwpoint_make2d(int srid, double x, double y)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
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.
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_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
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 FLAGS_SET_M(flags, value)
#define SRID_UNKNOWN
Unknown SRID value.
#define FLAGS_SET_Z(flags, value)
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
void lwline_free(LWLINE *line)
double lwpoint_get_y(const LWPOINT *point)
This library is the generic geometry handling section of PostGIS.
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)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)