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 - couldnt 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);
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 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.
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Datum BOX2D_union(PG_FUNCTION_ARGS)
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
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.
Datum BOX2D_overright(PG_FUNCTION_ARGS)
Datum BOX2D_same(PG_FUNCTION_ARGS)
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
Datum BOX2D_contain(PG_FUNCTION_ARGS)
Datum BOX2D_below(PG_FUNCTION_ARGS)
Datum BOX2D_overlap(PG_FUNCTION_ARGS)
LWPOINT * lwpoint_make2d(int srid, double x, double y)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
void lwpoint_free(LWPOINT *pt)
void lwline_free(LWLINE *line)
Datum BOX2D_combine(PG_FUNCTION_ARGS)
void error_if_srid_mismatch(int srid1, int srid2)
Datum BOX2D_intersects(PG_FUNCTION_ARGS)
Datum BOX2D_in(PG_FUNCTION_ARGS)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Datum BOX2D_out(PG_FUNCTION_ARGS)
Datum BOX2D_overleft(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(BOX2D_in)
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...
#define FLAGS_SET_Z(flags, value)
double lwpoint_get_x(const LWPOINT *point)
Datum BOX2D_to_BOX3D(PG_FUNCTION_ARGS)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
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, then a duplicate point will not be added.
Datum LWGEOM_to_BOX2D(PG_FUNCTION_ARGS)
void lwpoly_free(LWPOLY *poly)
#define LW_TRUE
Return types for functions with status returns.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
#define SRID_UNKNOWN
Unknown SRID value.
Datum BOX2D_overabove(PG_FUNCTION_ARGS)
Datum BOX2D_overbelow(PG_FUNCTION_ARGS)
Datum BOX2D_construct(PG_FUNCTION_ARGS)
Datum BOX2D_above(PG_FUNCTION_ARGS)
int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout)
Update the output GBOX to be large enough to include both inputs.
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Datum BOX2D_left(PG_FUNCTION_ARGS)
BOX3D * box3d_from_gbox(const GBOX *gbox)
Datum BOX2D_right(PG_FUNCTION_ARGS)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Datum BOX2D_to_LWGEOM(PG_FUNCTION_ARGS)
Datum BOX2D_contained(PG_FUNCTION_ARGS)
double lwpoint_get_y(const LWPOINT *point)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Datum BOX2D_expand(PG_FUNCTION_ARGS)
void * lwalloc(size_t size)
Datum LWGEOM_to_BOX2DF(PG_FUNCTION_ARGS)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
This library is the generic geometry handling section of PostGIS.
#define FLAGS_SET_M(flags, value)