PostGIS  2.3.8dev-r@@SVN_REVISION@@
lwgeom_box.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * PostGIS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PostGIS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  **********************************************************************
20  *
21  * Copyright 2001-2009 Refractions Research Inc.
22  * Copyright 2009 Mark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
23  *
24  **********************************************************************/
25 
26 
27 #include "postgres.h"
28 #include "access/gist.h"
29 #include "access/itup.h"
30 #include "fmgr.h"
31 #include "utils/elog.h"
32 #include "utils/geo_decls.h"
33 
34 #include "../postgis_config.h"
35 #include "lwgeom_pg.h"
36 #include "liblwgeom.h"
37 
38 #include <math.h>
39 #include <float.h>
40 #include <string.h>
41 #include <stdio.h>
42 #include <errno.h>
43 
44 
45 /* forward defs */
46 Datum BOX2D_in(PG_FUNCTION_ARGS);
47 Datum BOX2D_out(PG_FUNCTION_ARGS);
48 Datum LWGEOM_to_BOX2D(PG_FUNCTION_ARGS);
49 Datum LWGEOM_to_BOX2DF(PG_FUNCTION_ARGS);
50 Datum BOX2D_expand(PG_FUNCTION_ARGS);
51 Datum BOX2D_to_BOX3D(PG_FUNCTION_ARGS);
52 Datum BOX2D_combine(PG_FUNCTION_ARGS);
53 Datum BOX2D_to_LWGEOM(PG_FUNCTION_ARGS);
54 Datum BOX2D_construct(PG_FUNCTION_ARGS);
55 
56 /* parser - "BOX(xmin ymin,xmax ymax)" */
58 Datum BOX2D_in(PG_FUNCTION_ARGS)
59 {
60  char *str = PG_GETARG_CSTRING(0);
61  int nitems;
62  double tmp;
63  GBOX box;
64  int i;
65 
66  gbox_init(&box);
67 
68  for(i = 0; str[i]; i++) {
69  str[i] = tolower(str[i]);
70  }
71 
72  nitems = sscanf(str,"box(%lf %lf,%lf %lf)", &box.xmin, &box.ymin, &box.xmax, &box.ymax);
73  if (nitems != 4)
74  {
75  elog(ERROR,"box2d parser - couldnt parse. It should look like: BOX(xmin ymin,xmax ymax)");
76  PG_RETURN_NULL();
77  }
78 
79  if (box.xmin > box.xmax)
80  {
81  tmp = box.xmin;
82  box.xmin = box.xmax;
83  box.xmax = tmp;
84  }
85  if (box.ymin > box.ymax)
86  {
87  tmp = box.ymin;
88  box.ymin = box.ymax;
89  box.ymax = tmp;
90  }
91  PG_RETURN_POINTER(gbox_copy(&box));
92 }
93 
94 /*writer "BOX(xmin ymin,xmax ymax)" */
96 Datum BOX2D_out(PG_FUNCTION_ARGS)
97 {
98  GBOX *box = (GBOX *) PG_GETARG_POINTER(0);
99  char tmp[500]; /* big enough */
100  char *result;
101  int size;
102 
103  size = sprintf(tmp,"BOX(%.15g %.15g,%.15g %.15g)",
104  box->xmin, box->ymin, box->xmax, box->ymax);
105 
106  result= palloc(size+1); /* +1= null term */
107  memcpy(result,tmp,size+1);
108  result[size] = '\0';
109 
110  PG_RETURN_CSTRING(result);
111 }
112 
113 
114 /*convert a GSERIALIZED to BOX2D */
116 Datum LWGEOM_to_BOX2D(PG_FUNCTION_ARGS)
117 {
118  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
119  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
120  GBOX gbox;
121 
122  /* Cannot box empty! */
123  if ( lwgeom_is_empty(lwgeom) )
124  PG_RETURN_NULL();
125 
126  /* Cannot calculate box? */
127  if ( lwgeom_calculate_gbox(lwgeom, &gbox) == LW_FAILURE )
128  PG_RETURN_NULL();
129 
130  /* Strip out higher dimensions */
131  FLAGS_SET_Z(gbox.flags, 0);
132  FLAGS_SET_M(gbox.flags, 0);
133 
134  PG_FREE_IF_COPY(geom, 0);
135  PG_RETURN_POINTER(gbox_copy(&gbox));
136 }
137 
138 
139 /*convert a GSERIALIZED to BOX2D */
141 Datum LWGEOM_to_BOX2DF(PG_FUNCTION_ARGS)
142 {
143  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
144  GBOX gbox;
145 
146  if ( gserialized_get_gbox_p(geom, &gbox) == LW_FAILURE )
147  PG_RETURN_NULL();
148 
149  /* Strip out higher dimensions */
150  FLAGS_SET_Z(gbox.flags, 0);
151  FLAGS_SET_M(gbox.flags, 0);
152 
153  PG_FREE_IF_COPY(geom, 0);
154  PG_RETURN_POINTER(gbox_copy(&gbox));
155 }
156 
157 
158 /*----------------------------------------------------------
159  * Relational operators for BOXes.
160  * <, >, <=, >=, and == are based on box area.
161  *---------------------------------------------------------*/
162 
163 /*
164  * box_same - are two boxes identical?
165  */
167 Datum BOX2D_same(PG_FUNCTION_ARGS)
168 {
169  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
170  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
171 
172  PG_RETURN_BOOL(FPeq(box1->xmax, box2->xmax) &&
173  FPeq(box1->xmin, box2->xmin) &&
174  FPeq(box1->ymax, box2->ymax) &&
175  FPeq(box1->ymin, box2->ymin));
176 }
177 
178 /*
179  * box_overlap - does box1 overlap box2?
180  */
182 Datum BOX2D_overlap(PG_FUNCTION_ARGS)
183 {
184  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
185  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
186  bool result;
187 
188 
189  result = ((FPge(box1->xmax, box2->xmax) &&
190  FPle(box1->xmin, box2->xmax)) ||
191  (FPge(box2->xmax, box1->xmax) &&
192  FPle(box2->xmin, box1->xmax)))
193  &&
194  ((FPge(box1->ymax, box2->ymax) &&
195  FPle(box1->ymin, box2->ymax)) ||
196  (FPge(box2->ymax, box1->ymax) &&
197  FPle(box2->ymin, box1->ymax)));
198 
199  PG_RETURN_BOOL(result);
200 }
201 
202 
203 /*
204  * box_overleft - is the right edge of box1 to the left of
205  * the right edge of box2?
206  */
208 Datum BOX2D_overleft(PG_FUNCTION_ARGS)
209 {
210  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
211  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
212 
213  PG_RETURN_BOOL(FPle(box1->xmax, box2->xmax));
214 }
215 
216 /*
217  * box_left - is box1 strictly left of box2?
218  */
220 Datum BOX2D_left(PG_FUNCTION_ARGS)
221 {
222  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
223  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
224 
225  PG_RETURN_BOOL(FPlt(box1->xmax, box2->xmin));
226 }
227 
228 /*
229  * box_right - is box1 strictly right of box2?
230  */
232 Datum BOX2D_right(PG_FUNCTION_ARGS)
233 {
234  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
235  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
236 
237  PG_RETURN_BOOL(FPgt(box1->xmin, box2->xmax));
238 }
239 
240 /*
241  * box_overright - is the left edge of box1 to the right of
242  * the left edge of box2?
243  */
245 Datum BOX2D_overright(PG_FUNCTION_ARGS)
246 {
247  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
248  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
249 
250  PG_RETURN_BOOL(FPge(box1->xmin, box2->xmin));
251 }
252 
253 /*
254  * box_overbelow - is the bottom edge of box1 below
255  * the bottom edge of box2?
256  */
258 Datum BOX2D_overbelow(PG_FUNCTION_ARGS)
259 {
260  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
261  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
262 
263  PG_RETURN_BOOL(FPle(box1->ymax, box2->ymax));
264 }
265 
266 /*
267  * box_below - is box1 strictly below box2?
268  */
270 Datum BOX2D_below(PG_FUNCTION_ARGS)
271 {
272  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
273  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
274 
275  PG_RETURN_BOOL(FPlt(box1->ymax, box2->ymin));
276 }
277 
278 /*
279  * box_above - is box1 strictly above box2?
280  */
282 Datum BOX2D_above(PG_FUNCTION_ARGS)
283 {
284  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
285  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
286 
287  PG_RETURN_BOOL(FPgt(box1->ymin, box2->ymax));
288 }
289 
290 /*
291  * box_overabove - the top edge of box1 above
292  * the top edge of box2?
293  */
295 Datum BOX2D_overabove(PG_FUNCTION_ARGS)
296 {
297  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
298  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
299 
300  PG_RETURN_BOOL(FPge(box1->ymin, box2->ymin));
301 }
302 
303 /*
304  * box_contained - is box1 contained by box2?
305  */
307 Datum BOX2D_contained(PG_FUNCTION_ARGS)
308 {
309  GBOX *box1 =(GBOX *) PG_GETARG_POINTER(0);
310  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
311 
312  PG_RETURN_BOOL(FPle(box1->xmax, box2->xmax) &&
313  FPge(box1->xmin, box2->xmin) &&
314  FPle(box1->ymax, box2->ymax) &&
315  FPge(box1->ymin, box2->ymin));
316 }
317 
318 /*
319  * box_contain - does box1 contain box2?
320  */
322 Datum BOX2D_contain(PG_FUNCTION_ARGS)
323 {
324  GBOX *box1 = (GBOX *) PG_GETARG_POINTER(0);
325  GBOX *box2 = (GBOX *) PG_GETARG_POINTER(1);
326 
327  PG_RETURN_BOOL(FPge(box1->xmax, box2->xmax) &&
328  FPle(box1->xmin, box2->xmin) &&
329  FPge(box1->ymax, box2->ymax) &&
330  FPle(box1->ymin, box2->ymin));
331 
332 }
333 
335 Datum BOX2D_intersects(PG_FUNCTION_ARGS)
336 {
337  GBOX *a = (GBOX *) PG_GETARG_POINTER(0);
338  GBOX *b = (GBOX *) PG_GETARG_POINTER(1);
339  GBOX *n;
340 
341 
342  n = (GBOX *) palloc(sizeof(GBOX));
343 
344  n->xmax = Min(a->xmax, b->xmax);
345  n->ymax = Min(a->ymax, b->ymax);
346  n->xmin = Max(a->xmin, b->xmin);
347  n->ymin = Max(a->ymin, b->ymin);
348 
349 
350  if (n->xmax < n->xmin || n->ymax < n->ymin)
351  {
352  pfree(n);
353  /* Indicate "no intersection" by returning NULL pointer */
354  n = NULL;
355  }
356 
357  PG_RETURN_POINTER(n);
358 }
359 
360 
361 /*
362  * union of two BOX2Ds
363  */
365 Datum BOX2D_union(PG_FUNCTION_ARGS)
366 {
367  GBOX *a = (GBOX*) PG_GETARG_POINTER(0);
368  GBOX *b = (GBOX*) PG_GETARG_POINTER(1);
369  GBOX *n;
370 
371  n = (GBOX *) lwalloc(sizeof(GBOX));
372  if ( ! gbox_union(a,b,n) ) PG_RETURN_NULL();
373  PG_RETURN_POINTER(n);
374 }
375 
376 
378 Datum BOX2D_expand(PG_FUNCTION_ARGS)
379 {
380  GBOX *box = (GBOX *)PG_GETARG_POINTER(0);
381  GBOX *result = (GBOX *)palloc(sizeof(GBOX));
382  memcpy(result, box, sizeof(GBOX));
383 
384  if (PG_NARGS() == 2)
385  {
386  double d = PG_GETARG_FLOAT8(1);
387  gbox_expand(result, d);
388  }
389  else
390  {
391  double dx = PG_GETARG_FLOAT8(1);
392  double dy = PG_GETARG_FLOAT8(2);
393 
394  gbox_expand_xyzm(result, dx, dy, 0, 0);
395  }
396 
397  PG_RETURN_POINTER(result);
398 }
399 
401 Datum BOX2D_to_BOX3D(PG_FUNCTION_ARGS)
402 {
403  GBOX *box = (GBOX *)PG_GETARG_POINTER(0);
404  BOX3D *result = box3d_from_gbox(box);
405  PG_RETURN_POINTER(result);
406 }
407 
409 Datum BOX2D_combine(PG_FUNCTION_ARGS)
410 {
411  Pointer box2d_ptr = PG_GETARG_POINTER(0);
412  Pointer geom_ptr = PG_GETARG_POINTER(1);
413  GBOX *a,*b;
414  GSERIALIZED *lwgeom;
415  GBOX box, *result;
416 
417  if ( (box2d_ptr == NULL) && (geom_ptr == NULL) )
418  {
419  PG_RETURN_NULL(); /* combine_box2d(null,null) => null */
420  }
421 
422  result = (GBOX *)palloc(sizeof(GBOX));
423 
424  if (box2d_ptr == NULL)
425  {
426  lwgeom = PG_GETARG_GSERIALIZED_P(1);
427  /* empty geom would make getbox2d_p return NULL */
428  if ( ! gserialized_get_gbox_p(lwgeom, &box) ) PG_RETURN_NULL();
429  memcpy(result, &box, sizeof(GBOX));
430  PG_RETURN_POINTER(result);
431  }
432 
433  /* combine_bbox(BOX3D, null) => BOX3D */
434  if (geom_ptr == NULL)
435  {
436  memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(GBOX));
437  PG_RETURN_POINTER(result);
438  }
439 
440  /*combine_bbox(BOX3D, geometry) => union(BOX3D, geometry->bvol) */
441 
442  lwgeom = PG_GETARG_GSERIALIZED_P(1);
443  if ( ! gserialized_get_gbox_p(lwgeom, &box) )
444  {
445  /* must be the empty geom */
446  memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(GBOX));
447  PG_RETURN_POINTER(result);
448  }
449 
450  a = (GBOX *)PG_GETARG_DATUM(0);
451  b = &box;
452 
453  result->xmax = Max(a->xmax, b->xmax);
454  result->ymax = Max(a->ymax, b->ymax);
455  result->xmin = Min(a->xmin, b->xmin);
456  result->ymin = Min(a->ymin, b->ymin);
457 
458  PG_RETURN_POINTER(result);
459 }
460 
462 Datum BOX2D_to_LWGEOM(PG_FUNCTION_ARGS)
463 {
464  GBOX *box = (GBOX *)PG_GETARG_POINTER(0);
465  POINTARRAY *pa = ptarray_construct_empty(0, 0, 5);
466  POINT4D pt;
467  GSERIALIZED *result;
468 
469 
470  /*
471  * Alter BOX2D cast so that a valid geometry is always
472  * returned depending upon the size of the BOX2D. The
473  * code makes the following assumptions:
474  * - If the BOX2D is a single point then return a
475  * POINT geometry
476  * - If the BOX2D represents either a horizontal or
477  * vertical line, return a LINESTRING geometry
478  * - Otherwise return a POLYGON
479  */
480 
481  if ( (box->xmin == box->xmax) && (box->ymin == box->ymax) )
482  {
483  /* Construct and serialize point */
484  LWPOINT *point = lwpoint_make2d(SRID_UNKNOWN, box->xmin, box->ymin);
485  result = geometry_serialize(lwpoint_as_lwgeom(point));
486  lwpoint_free(point);
487  }
488  else if ( (box->xmin == box->xmax) || (box->ymin == box->ymax) )
489  {
490  LWLINE *line;
491 
492  /* Assign coordinates to point array */
493  pt.x = box->xmin;
494  pt.y = box->ymin;
495  ptarray_append_point(pa, &pt, LW_TRUE);
496  pt.x = box->xmax;
497  pt.y = box->ymax;
498  ptarray_append_point(pa, &pt, LW_TRUE);
499 
500  /* Construct and serialize linestring */
501  line = lwline_construct(SRID_UNKNOWN, NULL, pa);
502  result = geometry_serialize(lwline_as_lwgeom(line));
503  lwline_free(line);
504  }
505  else
506  {
507  POINT4D points[4];
508  LWPOLY *poly;
509 
510  /* Initialize the 4 vertices of the polygon */
511  points[0] = (POINT4D) { box->xmin, box->ymin };
512  points[1] = (POINT4D) { box->xmin, box->ymax };
513  points[2] = (POINT4D) { box->xmax, box->ymax };
514  points[3] = (POINT4D) { box->xmax, box->ymin };
515 
516  /* Construct polygon */
517  poly = lwpoly_construct_rectangle(LW_FALSE, LW_FALSE, &points[0], &points[1],
518  &points[2], &points[3]);
519  result = geometry_serialize(lwpoly_as_lwgeom(poly));
520  lwpoly_free(poly);
521  }
522 
523  PG_RETURN_POINTER(result);
524 }
525 
527 Datum BOX2D_construct(PG_FUNCTION_ARGS)
528 {
529  GSERIALIZED *pgmin = PG_GETARG_GSERIALIZED_P(0);
530  GSERIALIZED *pgmax = PG_GETARG_GSERIALIZED_P(1);
531  GBOX *result;
532  LWPOINT *minpoint, *maxpoint;
533  double min, max, tmp;
534 
535  minpoint = (LWPOINT*)lwgeom_from_gserialized(pgmin);
536  maxpoint = (LWPOINT*)lwgeom_from_gserialized(pgmax);
537 
538  if ( (minpoint->type != POINTTYPE) || (maxpoint->type != POINTTYPE) )
539  {
540  elog(ERROR, "GBOX_construct: arguments must be points");
541  PG_RETURN_NULL();
542  }
543 
544  error_if_srid_mismatch(minpoint->srid, maxpoint->srid);
545 
546  result = gbox_new(gflags(0, 0, 0));
547 
548  /* Process X min/max */
549  min = lwpoint_get_x(minpoint);
550  max = lwpoint_get_x(maxpoint);
551  if ( min > max )
552  {
553  tmp = min;
554  min = max;
555  max = tmp;
556  }
557  result->xmin = min;
558  result->xmax = max;
559 
560  /* Process Y min/max */
561  min = lwpoint_get_y(minpoint);
562  max = lwpoint_get_y(maxpoint);
563  if ( min > max )
564  {
565  tmp = min;
566  min = max;
567  max = tmp;
568  }
569  result->ymin = min;
570  result->ymax = max;
571 
572  PG_RETURN_POINTER(result);
573 }
574 
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.
Definition: g_serialized.c:398
double x
Definition: liblwgeom.h:351
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:438
Datum BOX2D_union(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:365
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:43
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.
Definition: g_box.c:126
Datum BOX2D_overright(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:245
Datum BOX2D_same(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:167
uint8_t type
Definition: liblwgeom.h:406
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void * Pointer
Definition: kmeans.h:59
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
Definition: g_box.c:108
Datum BOX2D_contain(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:322
Datum BOX2D_below(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:270
Datum BOX2D_overlap(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:182
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:145
double xmax
Definition: liblwgeom.h:292
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:195
void lwline_free(LWLINE *line)
Definition: lwline.c:76
Datum BOX2D_combine(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:409
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:369
Datum BOX2D_intersects(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:335
Datum BOX2D_in(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:58
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:252
Datum BOX2D_out(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:96
Datum BOX2D_overleft(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:208
PG_FUNCTION_INFO_V1(BOX2D_in)
#define LW_FAILURE
Definition: liblwgeom.h:78
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...
Definition: lwgeom.c:665
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:145
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
Datum BOX2D_to_BOX3D(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:401
double ymin
Definition: liblwgeom.h:293
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:262
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:51
double xmin
Definition: liblwgeom.h:291
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.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:76
Datum LWGEOM_to_BOX2D(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:116
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:152
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
Datum BOX2D_overabove(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:295
Datum BOX2D_overbelow(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:258
Datum BOX2D_construct(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:527
double ymax
Definition: liblwgeom.h:294
Datum BOX2D_above(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:282
int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout)
Update the output GBOX to be large enough to include both inputs.
Definition: g_box.c:146
int32_t srid
Definition: liblwgeom.h:409
uint8_t flags
Definition: liblwgeom.h:290
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
Datum BOX2D_left(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:220
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:64
Datum BOX2D_right(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:232
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
Datum BOX2D_to_LWGEOM(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:462
Datum BOX2D_contained(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:307
#define FPeq(A, B)
Definition: box2d.c:37
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:73
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:267
Datum BOX2D_expand(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:378
void * lwalloc(size_t size)
Definition: lwutil.c:227
Datum LWGEOM_to_BOX2DF(PG_FUNCTION_ARGS)
Definition: lwgeom_box.c:141
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1310
double y
Definition: liblwgeom.h:351
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
Definition: lwpoly.c:80
This library is the generic geometry handling section of PostGIS.
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:146