888 GEOSBufferParams *bufferparams;
889 GEOSGeometry *g1, *g3 = NULL;
906 const double DEFAULT_MITRE_LIMIT = 5.0;
907 const int DEFAULT_ENDCAP_STYLE = ENDCAP_ROUND;
908 const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
909 double mitreLimit = DEFAULT_MITRE_LIMIT;
910 int endCapStyle = DEFAULT_ENDCAP_STYLE;
911 int joinStyle = DEFAULT_JOIN_STYLE;
914 double size = PG_GETARG_FLOAT8(1);
919 params_text = PG_GETARG_TEXT_P(2);
923 params_text = palloc(VARHDRSZ);
924 SET_VARSIZE(params_text, 0);
940 lwpgerror(
"Geometry contains invalid coordinates");
952 if (VARSIZE_ANY_EXHDR(params_text) > 0)
957 for (param=params; ; param=NULL)
960 param = strtok(param,
" ");
962 POSTGIS_DEBUGF(3,
"Param: %s", param);
965 val = strchr(key,
'=');
966 if (!val || *(val + 1) ==
'\0')
968 lwpgerror(
"Missing value for buffer parameter %s", key);
974 POSTGIS_DEBUGF(3,
"Param: %s : %s", key, val);
976 if ( !strcmp(key,
"endcap") )
981 if ( !strcmp(val,
"round") )
983 endCapStyle = ENDCAP_ROUND;
985 else if ( !strcmp(val,
"flat") ||
986 !strcmp(val,
"butt") )
988 endCapStyle = ENDCAP_FLAT;
990 else if ( !strcmp(val,
"square") )
992 endCapStyle = ENDCAP_SQUARE;
996 lwpgerror(
"Invalid buffer end cap "
997 "style: %s (accept: "
998 "'round', 'flat', 'butt' "
1005 else if ( !strcmp(key,
"join") )
1007 if ( !strcmp(val,
"round") )
1009 joinStyle = JOIN_ROUND;
1011 else if ( !strcmp(val,
"mitre") ||
1012 !strcmp(val,
"miter") )
1014 joinStyle = JOIN_MITRE;
1016 else if ( !strcmp(val,
"bevel") )
1018 joinStyle = JOIN_BEVEL;
1022 lwpgerror(
"Invalid buffer end cap "
1023 "style: %s (accept: "
1024 "'round', 'mitre', 'miter' "
1030 else if ( !strcmp(key,
"mitre_limit") ||
1031 !strcmp(key,
"miter_limit") )
1034 mitreLimit = atof(val);
1036 else if ( !strcmp(key,
"quad_segs") )
1039 quadsegs = atoi(val);
1041 else if ( !strcmp(key,
"side") )
1043 if ( !strcmp(val,
"both") )
1047 else if ( !strcmp(val,
"left") )
1051 else if ( !strcmp(val,
"right") )
1058 lwpgerror(
"Invalid side parameter: %s (accept: 'right', 'left', 'both')", val);
1065 "Invalid buffer parameter: %s (accept: 'endcap', 'join', 'mitre_limit', 'miter_limit', 'quad_segs' and 'side')",
1074 POSTGIS_DEBUGF(3,
"endCap:%d joinStyle:%d mitreLimit:%g",
1075 endCapStyle, joinStyle, mitreLimit);
1077 bufferparams = GEOSBufferParams_create();
1080 if (GEOSBufferParams_setEndCapStyle(bufferparams, endCapStyle) &&
1081 GEOSBufferParams_setJoinStyle(bufferparams, joinStyle) &&
1082 GEOSBufferParams_setMitreLimit(bufferparams, mitreLimit) &&
1083 GEOSBufferParams_setQuadrantSegments(bufferparams, quadsegs) &&
1084 GEOSBufferParams_setSingleSided(bufferparams, singleside))
1086 g3 = GEOSBufferWithParams(g1, bufferparams, size);
1090 lwpgerror(
"Error setting buffer parameters.");
1092 GEOSBufferParams_destroy(bufferparams);
1096 lwpgerror(
"Error setting buffer parameters.");
1099 GEOSGeom_destroy(g1);
1103 POSTGIS_DEBUGF(3,
"result: %s", GEOSGeomToWKT(g3));
1108 GEOSGeom_destroy(g3);
1112 elog(ERROR,
"GEOS buffer() threw an error (result postgis geometry formation)!");
1116 PG_FREE_IF_COPY(geom1, 0);
1117 PG_RETURN_POINTER(result);
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)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
char * text_to_cstring(const text *textptr)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)