963 GEOSBufferParams *bufferparams;
964 GEOSGeometry *g1, *g3 = NULL;
981 const double DEFAULT_MITRE_LIMIT = 5.0;
982 const int DEFAULT_ENDCAP_STYLE = ENDCAP_ROUND;
983 const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
984 double mitreLimit = DEFAULT_MITRE_LIMIT;
985 int endCapStyle = DEFAULT_ENDCAP_STYLE;
986 int joinStyle = DEFAULT_JOIN_STYLE;
989 double size = PG_GETARG_FLOAT8(1);
994 params_text = PG_GETARG_TEXT_P(2);
998 params_text = cstring_to_text(
"");
1007 PG_RETURN_POINTER(geometry_serialize(lwg));
1014 lwpgerror(
"Geometry contains invalid coordinates");
1026 if (VARSIZE_ANY_EXHDR(params_text) > 0)
1029 char *params = text_to_cstring(params_text);
1031 for (param=params; ; param=NULL)
1034 param = strtok(param,
" ");
1036 POSTGIS_DEBUGF(3,
"Param: %s", param);
1039 val = strchr(key,
'=');
1040 if (!val || *(val + 1) ==
'\0')
1042 lwpgerror(
"Missing value for buffer parameter %s", key);
1048 POSTGIS_DEBUGF(3,
"Param: %s : %s", key, val);
1050 if ( !strcmp(key,
"endcap") )
1055 if ( !strcmp(val,
"round") )
1057 endCapStyle = ENDCAP_ROUND;
1059 else if ( !strcmp(val,
"flat") ||
1060 !strcmp(val,
"butt") )
1062 endCapStyle = ENDCAP_FLAT;
1064 else if ( !strcmp(val,
"square") )
1066 endCapStyle = ENDCAP_SQUARE;
1070 lwpgerror(
"Invalid buffer end cap "
1071 "style: %s (accept: "
1072 "'round', 'flat', 'butt' "
1079 else if ( !strcmp(key,
"join") )
1081 if ( !strcmp(val,
"round") )
1083 joinStyle = JOIN_ROUND;
1085 else if ( !strcmp(val,
"mitre") ||
1086 !strcmp(val,
"miter") )
1088 joinStyle = JOIN_MITRE;
1090 else if ( !strcmp(val,
"bevel") )
1092 joinStyle = JOIN_BEVEL;
1096 lwpgerror(
"Invalid buffer end cap "
1097 "style: %s (accept: "
1098 "'round', 'mitre', 'miter' "
1104 else if ( !strcmp(key,
"mitre_limit") ||
1105 !strcmp(key,
"miter_limit") )
1108 mitreLimit = atof(val);
1110 else if ( !strcmp(key,
"quad_segs") )
1113 quadsegs = atoi(val);
1115 else if ( !strcmp(key,
"side") )
1117 if ( !strcmp(val,
"both") )
1121 else if ( !strcmp(val,
"left") )
1125 else if ( !strcmp(val,
"right") )
1132 lwpgerror(
"Invalid side parameter: %s (accept: 'right', 'left', 'both')", val);
1139 "Invalid buffer parameter: %s (accept: 'endcap', 'join', 'mitre_limit', 'miter_limit', 'quad_segs' and 'side')",
1148 POSTGIS_DEBUGF(3,
"endCap:%d joinStyle:%d mitreLimit:%g",
1149 endCapStyle, joinStyle, mitreLimit);
1151 bufferparams = GEOSBufferParams_create();
1154 if (GEOSBufferParams_setEndCapStyle(bufferparams, endCapStyle) &&
1155 GEOSBufferParams_setJoinStyle(bufferparams, joinStyle) &&
1156 GEOSBufferParams_setMitreLimit(bufferparams, mitreLimit) &&
1157 GEOSBufferParams_setQuadrantSegments(bufferparams, quadsegs) &&
1158 GEOSBufferParams_setSingleSided(bufferparams, singleside))
1160 g3 = GEOSBufferWithParams(g1, bufferparams, size);
1164 lwpgerror(
"Error setting buffer parameters.");
1166 GEOSBufferParams_destroy(bufferparams);
1170 lwpgerror(
"Error setting buffer parameters.");
1173 GEOSGeom_destroy(g1);
1177 POSTGIS_DEBUGF(3,
"result: %s", GEOSGeomToWKT(g3));
1182 GEOSGeom_destroy(g3);
1186 elog(ERROR,
"GEOS buffer() threw an error (result postgis geometry formation)!");
1190 PG_FREE_IF_COPY(geom1, 0);
1191 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)