[postgis-tickets] r15266 - Refactor logic for ST_MakeEnvelope to be reusable in liblwgeom
Sandro Santilli
strk at kbt.io
Fri Dec 2 00:06:10 PST 2016
Author: strk
Date: 2016-12-02 00:06:09 -0800 (Fri, 02 Dec 2016)
New Revision: 15266
Modified:
trunk/liblwgeom/liblwgeom.h.in
trunk/liblwgeom/lwpoly.c
trunk/postgis/lwgeom_functions_basic.c
Log:
Refactor logic for ST_MakeEnvelope to be reusable in liblwgeom
Patch by Bj?\195?\182rn Harrtell via
https://git.osgeo.org/gogs/postgis/postgis/pulls/8
Modified: trunk/liblwgeom/liblwgeom.h.in
===================================================================
--- trunk/liblwgeom/liblwgeom.h.in 2016-11-28 15:10:35 UTC (rev 15265)
+++ trunk/liblwgeom/liblwgeom.h.in 2016-12-02 08:06:09 UTC (rev 15266)
@@ -1356,8 +1356,9 @@
extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
extern void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint);
extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes);
-extern LWPOLY* lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
-extern LWPOLY* lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
+extern LWPOLY *lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
+extern LWPOLY *lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2);
+extern LWPOLY *lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
extern LWTRIANGLE *lwtriangle_from_lwline(const LWLINE *shell);
extern LWMPOINT *lwmpoint_from_lwgeom(const LWGEOM *g); /* Extract the coordinates of an LWGEOM into an LWMPOINT */
Modified: trunk/liblwgeom/lwpoly.c
===================================================================
--- trunk/liblwgeom/lwpoly.c 2016-11-28 15:10:35 UTC (rev 15265)
+++ trunk/liblwgeom/lwpoly.c 2016-12-02 08:06:09 UTC (rev 15266)
@@ -94,6 +94,28 @@
return lwpoly;
}
+LWPOLY *
+lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2)
+{
+ POINT4D p1, p2, p3, p4;
+ LWPOLY *poly;
+
+ p1.x = x1;
+ p1.y = y1;
+ p2.x = x1;
+ p2.y = y2;
+ p3.x = x2;
+ p3.y = y2;
+ p4.x = x2;
+ p4.y = y1;
+
+ poly = lwpoly_construct_rectangle(0, 0, &p1, &p2, &p3, &p4);
+ lwgeom_set_srid(lwpoly_as_lwgeom(poly), srid);
+ lwgeom_add_bbox(lwpoly_as_lwgeom(poly));
+
+ return poly;
+}
+
LWPOLY*
lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
{
Modified: trunk/postgis/lwgeom_functions_basic.c
===================================================================
--- trunk/postgis/lwgeom_functions_basic.c 2016-11-28 15:10:35 UTC (rev 15265)
+++ trunk/postgis/lwgeom_functions_basic.c 2016-12-02 08:06:09 UTC (rev 15266)
@@ -2075,37 +2075,8 @@
srid = PG_GETARG_INT32(4);
}
- pa = (POINTARRAY**)palloc(sizeof(POINTARRAY**));
- pa[0] = ptarray_construct_empty(0, 0, 5);
+ poly = lwpoly_construct_envelope(srid, x1, y1, x2, y2);
- /* 1st point */
- p.x = x1;
- p.y = y1;
- ptarray_append_point(pa[0], &p, LW_TRUE);
-
- /* 2nd point */
- p.x = x1;
- p.y = y2;
- ptarray_append_point(pa[0], &p, LW_TRUE);
-
- /* 3rd point */
- p.x = x2;
- p.y = y2;
- ptarray_append_point(pa[0], &p, LW_TRUE);
-
- /* 4th point */
- p.x = x2;
- p.y = y1;
- ptarray_append_point(pa[0], &p, LW_TRUE);
-
- /* 5th point */
- p.x = x1;
- p.y = y1;
- ptarray_append_point(pa[0], &p, LW_TRUE);
-
- poly = lwpoly_construct(srid, NULL, 1, pa);
- lwgeom_add_bbox(lwpoly_as_lwgeom(poly));
-
result = geometry_serialize(lwpoly_as_lwgeom(poly));
lwpoly_free(poly);
More information about the postgis-tickets
mailing list