936 GEOSBufferParams *bufferparams;
937 GEOSGeometry *g1, *g3 = NULL;
954 const double DEFAULT_MITRE_LIMIT = 5.0;
955 const int DEFAULT_ENDCAP_STYLE = ENDCAP_ROUND;
956 const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
957 double mitreLimit = DEFAULT_MITRE_LIMIT;
958 int endCapStyle = DEFAULT_ENDCAP_STYLE;
959 int joinStyle = DEFAULT_JOIN_STYLE;
962 double size = PG_GETARG_FLOAT8(1);
967 params_text = PG_GETARG_TEXT_P(2);
971 params_text = cstring_to_text(
"");
980 PG_RETURN_POINTER(geometry_serialize(lwg));
987 lwpgerror(
"Geometry contains invalid coordinates");
999 if (VARSIZE_ANY_EXHDR(params_text) > 0)
1002 char *params = text_to_cstring(params_text);
1004 for (param=params; ; param=NULL)
1007 param = strtok(param,
" ");
1009 POSTGIS_DEBUGF(3,
"Param: %s", param);
1012 val = strchr(key,
'=');
1013 if (!val || *(val + 1) ==
'\0')
1015 lwpgerror(
"Missing value for buffer parameter %s", key);
1021 POSTGIS_DEBUGF(3,
"Param: %s : %s", key, val);
1023 if ( !strcmp(key,
"endcap") )
1028 if ( !strcmp(val,
"round") )
1030 endCapStyle = ENDCAP_ROUND;
1032 else if ( !strcmp(val,
"flat") ||
1033 !strcmp(val,
"butt") )
1035 endCapStyle = ENDCAP_FLAT;
1037 else if ( !strcmp(val,
"square") )
1039 endCapStyle = ENDCAP_SQUARE;
1043 lwpgerror(
"Invalid buffer end cap "
1044 "style: %s (accept: "
1045 "'round', 'flat', 'butt' "
1052 else if ( !strcmp(key,
"join") )
1054 if ( !strcmp(val,
"round") )
1056 joinStyle = JOIN_ROUND;
1058 else if ( !strcmp(val,
"mitre") ||
1059 !strcmp(val,
"miter") )
1061 joinStyle = JOIN_MITRE;
1063 else if ( !strcmp(val,
"bevel") )
1065 joinStyle = JOIN_BEVEL;
1069 lwpgerror(
"Invalid buffer end cap "
1070 "style: %s (accept: "
1071 "'round', 'mitre', 'miter' "
1077 else if ( !strcmp(key,
"mitre_limit") ||
1078 !strcmp(key,
"miter_limit") )
1081 mitreLimit = atof(val);
1083 else if ( !strcmp(key,
"quad_segs") )
1086 quadsegs = atoi(val);
1088 else if ( !strcmp(key,
"side") )
1090 if ( !strcmp(val,
"both") )
1094 else if ( !strcmp(val,
"left") )
1098 else if ( !strcmp(val,
"right") )
1105 lwpgerror(
"Invalid side parameter: %s (accept: 'right', 'left', 'both')", val);
1112 "Invalid buffer parameter: %s (accept: 'endcap', 'join', 'mitre_limit', 'miter_limit', 'quad_segs' and 'side')",
1121 POSTGIS_DEBUGF(3,
"endCap:%d joinStyle:%d mitreLimit:%g",
1122 endCapStyle, joinStyle, mitreLimit);
1124 bufferparams = GEOSBufferParams_create();
1127 if (GEOSBufferParams_setEndCapStyle(bufferparams, endCapStyle) &&
1128 GEOSBufferParams_setJoinStyle(bufferparams, joinStyle) &&
1129 GEOSBufferParams_setMitreLimit(bufferparams, mitreLimit) &&
1130 GEOSBufferParams_setQuadrantSegments(bufferparams, quadsegs) &&
1131 GEOSBufferParams_setSingleSided(bufferparams, singleside))
1133 g3 = GEOSBufferWithParams(g1, bufferparams, size);
1137 lwpgerror(
"Error setting buffer parameters.");
1139 GEOSBufferParams_destroy(bufferparams);
1143 lwpgerror(
"Error setting buffer parameters.");
1146 GEOSGeom_destroy(g1);
1150 POSTGIS_DEBUGF(3,
"result: %s", GEOSGeomToWKT(g3));
1155 GEOSGeom_destroy(g3);
1159 elog(ERROR,
"GEOS buffer() threw an error (result postgis geometry formation)!");
1163 PG_FREE_IF_COPY(geom1, 0);
1164 PG_RETURN_POINTER(
result);
char result[OUT_DOUBLE_BUFFER_SIZE]
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
void lwgeom_geos_error(const char *fmt,...)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
#define HANDLE_GEOS_ERROR(label)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)