]> granicus.if.org Git - postgis/commitdiff
Added makepolygon(geometry, geometry[])
authorSandro Santilli <strk@keybit.net>
Thu, 6 Jan 2005 13:46:41 +0000 (13:46 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 6 Jan 2005 13:46:41 +0000 (13:46 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1234 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_functions_basic.c
lwgeom/lwpostgis.sql.in

index 8f7676bbae1291fa26f5792e865184d4f7a7f66b..9350f851862cc331e7b4f447cb0c041ba705be24 100644 (file)
@@ -50,6 +50,7 @@ Datum LWGEOM_makepoint(PG_FUNCTION_ARGS);
 Datum LWGEOM_makepoint3dm(PG_FUNCTION_ARGS);
 Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS);
 Datum LWGEOM_makeline(PG_FUNCTION_ARGS);
+Datum LWGEOM_makepoly(PG_FUNCTION_ARGS);
 Datum LWGEOM_line_from_mpoint(PG_FUNCTION_ARGS);
 Datum LWGEOM_addpoint(PG_FUNCTION_ARGS);
 Datum LWGEOM_asEWKT(PG_FUNCTION_ARGS);
@@ -2110,6 +2111,61 @@ Datum LWGEOM_makeline(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(result);
 }
 
+/*
+ * makepoly( GEOMETRY, GEOMETRY[] ) returns a POLYGON 
+ * formed by the given shell and holes geometries.
+ */
+PG_FUNCTION_INFO_V1(LWGEOM_makepoly);
+Datum LWGEOM_makepoly(PG_FUNCTION_ARGS)
+{
+       PG_LWGEOM *pglwg1;
+       ArrayType *array=NULL;
+       PG_LWGEOM *result=NULL;
+       const LWLINE *shell=NULL;
+       const LWLINE **holes=NULL;
+       LWPOLY *outpoly;
+       unsigned int nholes=0;
+       unsigned int i;
+       size_t offset=0;
+
+#ifdef DEBUG
+       elog(NOTICE, "LWGEOM_makepoly called");
+#endif
+
+       /* Get input shell */
+       pglwg1 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       if ( ! TYPE_GETTYPE(pglwg1->type) == LINETYPE ) {
+               lwerror("Shell is not a line");
+       }
+       shell = lwline_deserialize(SERIALIZED_FORM(pglwg1));
+
+       /* Get input holes if any */
+       if ( PG_NARGS() > 1 )
+       {
+               array = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+               nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
+               holes = lwalloc(sizeof(LWLINE *)*nholes);
+               for (i=0; i<nholes; i++)
+               {
+                       PG_LWGEOM *g = (PG_LWGEOM *)(ARR_DATA_PTR(array)+offset);
+                       LWLINE *hole;
+                       offset += INTALIGN(g->size);
+                       if ( TYPE_GETTYPE(g->type) != LINETYPE ) {
+                               lwerror("Hole %d is not a line", i);
+                       }
+                       hole = lwline_deserialize(SERIALIZED_FORM(g));
+                       holes[i] = hole;
+               }
+       }
+
+       outpoly = lwpoly_from_lwlines(shell, nholes, holes);
+       //lwnotice("%s", lwpoly_summary(outpoly));
+
+       result = pglwgeom_serialize((LWGEOM *)outpoly);
+
+       PG_RETURN_POINTER(result);
+}
+
 // makes a polygon of the expanded features bvol - 1st point = LL 3rd=UR
 // 2d only. (3d might be worth adding).
 // create new geometry of type polygon, 1 ring, 5 points
index cc17cb92cf876b3afd351c10ed5eb9199ff52d79..2ea7579c15347d2daf4022b785278854ad588c16 100644 (file)
@@ -1810,6 +1810,16 @@ CREATE AGGREGATE makeline (
        finalfunc = makeline_garray
        );
 
+CREATEFUNCTION MakePolygon(geometry, geometry[])
+       RETURNS geometry
+       AS '@MODULE_FILENAME@', 'LWGEOM_makepoly'
+       LANGUAGE 'C' WITH (iscachable,isstrict);
+
+CREATEFUNCTION MakePolygon(geometry)
+       RETURNS geometry
+       AS '@MODULE_FILENAME@', 'LWGEOM_makepoly'
+       LANGUAGE 'C' WITH (iscachable,isstrict);
+
 CREATEFUNCTION polygonize_garray (geometry[])
        RETURNS geometry
        AS '@MODULE_FILENAME@', 'GEOS_polygonize_garray'