853 GEOSGeometry *g1, *g3;
869 static const double DEFAULT_MITRE_LIMIT = 5.0;
870 static const int DEFAULT_ENDCAP_STYLE = ENDCAP_ROUND;
871 static const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
873 double mitreLimit = DEFAULT_MITRE_LIMIT;
874 int endCapStyle = DEFAULT_ENDCAP_STYLE;
875 int joinStyle = DEFAULT_JOIN_STYLE;
880 geom1 = PG_GETARG_GSERIALIZED_P(0);
881 size = PG_GETARG_FLOAT8(1);
906 params = pstrdup(PG_GETARG_CSTRING(2));
908 POSTGIS_DEBUGF(3,
"Params: %s", params);
910 for (param=params; ; param=NULL)
913 param = strtok(param,
" ");
914 if ( param == NULL )
break;
915 POSTGIS_DEBUGF(3,
"Param: %s", param);
918 val = strchr(key,
'=');
919 if ( val == NULL || *(val+1) ==
'\0' )
921 lwpgerror(
"Missing value for buffer " 922 "parameter %s", key);
928 POSTGIS_DEBUGF(3,
"Param: %s : %s", key, val);
930 if ( !strcmp(key,
"endcap") )
935 if ( !strcmp(val,
"round") )
937 endCapStyle = ENDCAP_ROUND;
939 else if ( !strcmp(val,
"flat") ||
940 !strcmp(val,
"butt") )
942 endCapStyle = ENDCAP_FLAT;
944 else if ( !strcmp(val,
"square") )
946 endCapStyle = ENDCAP_SQUARE;
950 lwpgerror(
"Invalid buffer end cap " 951 "style: %s (accept: " 952 "'round', 'flat', 'butt' " 959 else if ( !strcmp(key,
"join") )
961 if ( !strcmp(val,
"round") )
963 joinStyle = JOIN_ROUND;
965 else if ( !strcmp(val,
"mitre") ||
966 !strcmp(val,
"miter") )
968 joinStyle = JOIN_MITRE;
970 else if ( !strcmp(val,
"bevel") )
972 joinStyle = JOIN_BEVEL;
976 lwpgerror(
"Invalid buffer end cap " 977 "style: %s (accept: " 978 "'round', 'mitre', 'miter' " 984 else if ( !strcmp(key,
"mitre_limit") ||
985 !strcmp(key,
"miter_limit") )
988 mitreLimit = atof(val);
990 else if ( !strcmp(key,
"quad_segs") )
993 quadsegs = atoi(val);
997 lwpgerror(
"Invalid buffer parameter: %s (accept: " 998 "'endcap', 'join', 'mitre_limit', " 1000 "'quad_segs')", key);
1007 POSTGIS_DEBUGF(3,
"endCap:%d joinStyle:%d mitreLimit:%g",
1008 endCapStyle, joinStyle, mitreLimit);
1012 g3 = GEOSBufferWithStyle(g1, size, quadsegs, endCapStyle, joinStyle, mitreLimit);
1013 GEOSGeom_destroy(g1);
1021 POSTGIS_DEBUGF(3,
"result: %s", GEOSGeomToWKT(g3));
1026 GEOSGeom_destroy(g3);
1030 elog(ERROR,
"GEOS buffer() threw an error (result postgis geometry formation)!");
1034 PG_FREE_IF_COPY(geom1, 0);
1035 PG_RETURN_POINTER(result);
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
void lwgeom_geos_error(const char *fmt,...)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
#define HANDLE_GEOS_ERROR(label)
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)...