1053 GEOSBufferParams *bufferparams;
1054 GEOSGeometry *g1, *g3 = NULL;
1071 const double DEFAULT_MITRE_LIMIT = 5.0;
1072 const int DEFAULT_ENDCAP_STYLE = ENDCAP_ROUND;
1073 const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
1074 double mitreLimit = DEFAULT_MITRE_LIMIT;
1075 int endCapStyle = DEFAULT_ENDCAP_STYLE;
1076 int joinStyle = DEFAULT_JOIN_STYLE;
1079 double size = PG_GETARG_FLOAT8(1);
1084 params_text = PG_GETARG_TEXT_P(2);
1088 params_text = cstring_to_text(
"");
1097 PG_RETURN_POINTER(geometry_serialize(lwg));
1104 lwpgerror(
"Geometry contains invalid coordinates");
1116 if (VARSIZE_ANY_EXHDR(params_text) > 0)
1119 char *params = text_to_cstring(params_text);
1121 for (param=params; ; param=NULL)
1124 param = strtok(param,
" ");
1126 POSTGIS_DEBUGF(3,
"Param: %s", param);
1129 val = strchr(key,
'=');
1130 if (!val || *(val + 1) ==
'\0')
1132 lwpgerror(
"Missing value for buffer parameter %s", key);
1138 POSTGIS_DEBUGF(3,
"Param: %s : %s", key, val);
1140 if ( !strcmp(key,
"endcap") )
1145 if ( !strcmp(val,
"round") )
1147 endCapStyle = ENDCAP_ROUND;
1149 else if ( !strcmp(val,
"flat") ||
1150 !strcmp(val,
"butt") )
1152 endCapStyle = ENDCAP_FLAT;
1154 else if ( !strcmp(val,
"square") )
1156 endCapStyle = ENDCAP_SQUARE;
1160 lwpgerror(
"Invalid buffer end cap "
1161 "style: %s (accept: "
1162 "'round', 'flat', 'butt' "
1169 else if ( !strcmp(key,
"join") )
1171 if ( !strcmp(val,
"round") )
1173 joinStyle = JOIN_ROUND;
1175 else if ( !strcmp(val,
"mitre") ||
1176 !strcmp(val,
"miter") )
1178 joinStyle = JOIN_MITRE;
1180 else if ( !strcmp(val,
"bevel") )
1182 joinStyle = JOIN_BEVEL;
1186 lwpgerror(
"Invalid buffer end cap "
1187 "style: %s (accept: "
1188 "'round', 'mitre', 'miter' "
1194 else if ( !strcmp(key,
"mitre_limit") ||
1195 !strcmp(key,
"miter_limit") )
1198 mitreLimit = atof(val);
1200 else if ( !strcmp(key,
"quad_segs") )
1203 quadsegs = atoi(val);
1205 else if ( !strcmp(key,
"side") )
1207 if ( !strcmp(val,
"both") )
1211 else if ( !strcmp(val,
"left") )
1215 else if ( !strcmp(val,
"right") )
1222 lwpgerror(
"Invalid side parameter: %s (accept: 'right', 'left', 'both')", val);
1229 "Invalid buffer parameter: %s (accept: 'endcap', 'join', 'mitre_limit', 'miter_limit', 'quad_segs' and 'side')",
1238 POSTGIS_DEBUGF(3,
"endCap:%d joinStyle:%d mitreLimit:%g",
1239 endCapStyle, joinStyle, mitreLimit);
1241 bufferparams = GEOSBufferParams_create();
1244 if (GEOSBufferParams_setEndCapStyle(bufferparams, endCapStyle) &&
1245 GEOSBufferParams_setJoinStyle(bufferparams, joinStyle) &&
1246 GEOSBufferParams_setMitreLimit(bufferparams, mitreLimit) &&
1247 GEOSBufferParams_setQuadrantSegments(bufferparams, quadsegs) &&
1248 GEOSBufferParams_setSingleSided(bufferparams, singleside))
1250 g3 = GEOSBufferWithParams(g1, bufferparams, size);
1254 lwpgerror(
"Error setting buffer parameters.");
1256 GEOSBufferParams_destroy(bufferparams);
1260 lwpgerror(
"Error setting buffer parameters.");
1263 GEOSGeom_destroy(g1);
1267 POSTGIS_DEBUGF(3,
"result: %s", GEOSGeomToWKT(g3));
1272 GEOSGeom_destroy(g3);
1276 elog(ERROR,
"GEOS buffer() threw an error (result postgis geometry formation)!");
1280 PG_FREE_IF_COPY(geom1, 0);
1281 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)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)