800 GEOSBufferParams *bufferparams;
801 GEOSGeometry *g1, *g3 = NULL;
818 static const double DEFAULT_MITRE_LIMIT = 5.0;
819 static const int DEFAULT_ENDCAP_STYLE = ENDCAP_ROUND;
820 static const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
822 double mitreLimit = DEFAULT_MITRE_LIMIT;
823 int endCapStyle = DEFAULT_ENDCAP_STYLE;
824 int joinStyle = DEFAULT_JOIN_STYLE;
829 geom1 = PG_GETARG_GSERIALIZED_P(0);
830 size = PG_GETARG_FLOAT8(1);
852 params = pstrdup(PG_GETARG_CSTRING(2));
854 POSTGIS_DEBUGF(3,
"Params: %s", params);
856 for (param=params; ; param=NULL)
859 param = strtok(param,
" ");
861 POSTGIS_DEBUGF(3,
"Param: %s", param);
864 val = strchr(key,
'=');
865 if (!val || *(val + 1) ==
'\0')
867 lwpgerror(
"Missing value for buffer parameter %s", key);
873 POSTGIS_DEBUGF(3,
"Param: %s : %s", key, val);
875 if ( !strcmp(key,
"endcap") )
880 if ( !strcmp(val,
"round") )
882 endCapStyle = ENDCAP_ROUND;
884 else if ( !strcmp(val,
"flat") ||
885 !strcmp(val,
"butt") )
887 endCapStyle = ENDCAP_FLAT;
889 else if ( !strcmp(val,
"square") )
891 endCapStyle = ENDCAP_SQUARE;
895 lwpgerror(
"Invalid buffer end cap "
896 "style: %s (accept: "
897 "'round', 'flat', 'butt' "
904 else if ( !strcmp(key,
"join") )
906 if ( !strcmp(val,
"round") )
908 joinStyle = JOIN_ROUND;
910 else if ( !strcmp(val,
"mitre") ||
911 !strcmp(val,
"miter") )
913 joinStyle = JOIN_MITRE;
915 else if ( !strcmp(val,
"bevel") )
917 joinStyle = JOIN_BEVEL;
921 lwpgerror(
"Invalid buffer end cap "
922 "style: %s (accept: "
923 "'round', 'mitre', 'miter' "
929 else if ( !strcmp(key,
"mitre_limit") ||
930 !strcmp(key,
"miter_limit") )
933 mitreLimit = atof(val);
935 else if ( !strcmp(key,
"quad_segs") )
938 quadsegs = atoi(val);
940 else if ( !strcmp(key,
"side") ||
941 !strcmp(key,
"side") )
943 if ( !strcmp(val,
"both") )
947 else if ( !strcmp(val,
"left") )
951 else if ( !strcmp(val,
"right") )
958 lwpgerror(
"Invalid side parameter: %s (accept: 'right', 'left', 'both')", val);
965 "Invalid buffer parameter: %s (accept: 'endcap', 'join', 'mitre_limit', 'miter_limit', 'quad_segs' and 'side')",
973 POSTGIS_DEBUGF(3,
"endCap:%d joinStyle:%d mitreLimit:%g",
974 endCapStyle, joinStyle, mitreLimit);
978 bufferparams = GEOSBufferParams_create();
981 if (GEOSBufferParams_setEndCapStyle(bufferparams, endCapStyle) &&
982 GEOSBufferParams_setJoinStyle(bufferparams, joinStyle) &&
983 GEOSBufferParams_setMitreLimit(bufferparams, mitreLimit) &&
984 GEOSBufferParams_setQuadrantSegments(bufferparams, quadsegs) &&
985 GEOSBufferParams_setSingleSided(bufferparams, singleside))
987 g3 = GEOSBufferWithParams(g1, bufferparams, size);
991 lwpgerror(
"Error setting buffer parameters.");
993 GEOSBufferParams_destroy(bufferparams);
997 lwpgerror(
"Error setting buffer parameters.");
1000 GEOSGeom_destroy(g1);
1004 POSTGIS_DEBUGF(3,
"result: %s", GEOSGeomToWKT(g3));
1009 GEOSGeom_destroy(g3);
1013 elog(ERROR,
"GEOS buffer() threw an error (result postgis geometry formation)!");
1017 PG_FREE_IF_COPY(geom1, 0);
1018 PG_RETURN_POINTER(result);
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
void lwgeom_geos_error(const char *fmt,...)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
#define HANDLE_GEOS_ERROR(label)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)