From fb6e546c0523ef8bbd55c6ea99497e20181315cb Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Mon, 16 Nov 2009 18:28:47 +0000 Subject: [PATCH] Add ST_MakeEnvelope() constructor, terse function for making bbox polygons. (#199) git-svn-id: http://svn.osgeo.org/postgis/trunk@4831 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/lwgeom_functions_basic.c | 51 ++++++++++++++++++++++++++++++++ postgis/postgis.sql.in.c | 5 ++++ 2 files changed, 56 insertions(+) diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index eb645eece..9adbdd929 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -77,6 +77,7 @@ Datum LWGEOM_affine(PG_FUNCTION_ARGS); Datum LWGEOM_longitude_shift(PG_FUNCTION_ARGS); Datum optimistic_overlap(PG_FUNCTION_ARGS); Datum ST_GeoHash(PG_FUNCTION_ARGS); +Datum ST_MakeEnvelope(PG_FUNCTION_ARGS); void lwgeom_affine_ptarray(POINTARRAY *pa, double afac, double bfac, double cfac, double dfac, double efac, double ffac, double gfac, double hfac, double ifac, double xoff, double yoff, double zoff); @@ -2766,6 +2767,56 @@ Datum LWGEOM_same(PG_FUNCTION_ARGS) PG_RETURN_BOOL(result); } +PG_FUNCTION_INFO_V1(ST_MakeEnvelope); +Datum ST_MakeEnvelope(PG_FUNCTION_ARGS) +{ + LWPOLY *poly; + PG_LWGEOM *result; + POINTARRAY **pa; + double *pts; + double x1, y1, x2, y2; + int srid; + + POSTGIS_DEBUG(2, "ST_MakeEnvelope called"); + + x1 = PG_GETARG_FLOAT8(0); + y1 = PG_GETARG_FLOAT8(1); + x2 = PG_GETARG_FLOAT8(2); + y2 = PG_GETARG_FLOAT8(3); + srid = PG_GETARG_INT32(4); + + pa = (POINTARRAY**)palloc(sizeof(POINTARRAY*)); + pa[0] = ptarray_construct(0, 0, 5); + pts = (double*)(pa[0]->serialized_pointlist); + + /* 1st point */ + pts[0] = x1; + pts[1] = y1; + + /* 2nd point */ + pts[2] = x1; + pts[3] = y2; + + /* 3rd point */ + pts[4] = x2; + pts[5] = y2; + + /* 4th point */ + pts[6] = x2; + pts[7] = y1; + + /* 5th point */ + pts[8] = x1; + pts[9] = y1; + + poly = lwpoly_construct(srid, ptarray_compute_box2d(pa[0]), 1, pa); + + result = pglwgeom_serialize((LWGEOM*)poly); + lwpoly_free(poly); + + PG_RETURN_POINTER(result); +} + PG_FUNCTION_INFO_V1(LWGEOM_makepoint); Datum LWGEOM_makepoint(PG_FUNCTION_ARGS) { diff --git a/postgis/postgis.sql.in.c b/postgis/postgis.sql.in.c index d4e5a0ed5..8ec0daa01 100644 --- a/postgis/postgis.sql.in.c +++ b/postgis/postgis.sql.in.c @@ -1815,6 +1815,11 @@ CREATE OR REPLACE FUNCTION ST_SetPoint(geometry, integer, geometry) AS 'MODULE_PATHNAME', 'LWGEOM_setpoint_linestring' LANGUAGE 'C' IMMUTABLE STRICT; +-- Availability: 1.5.0 +CREATE OR REPLACE FUNCTION ST_MakeEnvelope(float8, float8, float8, float8, integer) + RETURNS geometry + AS 'MODULE_PATHNAME', 'ST_MakeEnvelope' + LANGUAGE 'C' IMMUTABLE STRICT; -- Deprecation in 1.2.3 CREATE OR REPLACE FUNCTION MakePolygon(geometry, geometry[]) -- 2.50.1