PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ ST_OffsetCurve()

Datum ST_OffsetCurve ( PG_FUNCTION_ARGS  )

Definition at line 1174 of file postgis/lwgeom_geos.c.

1175{
1176 GSERIALIZED *gser_input;
1177 GSERIALIZED *gser_result;
1178 LWGEOM *lwgeom_input;
1179 LWGEOM *lwgeom_result;
1180 double size;
1181 int quadsegs = 8; /* the default */
1182 int nargs;
1183
1184 enum
1185 {
1186 JOIN_ROUND = 1,
1187 JOIN_MITRE = 2,
1188 JOIN_BEVEL = 3
1189 };
1190
1191 static const double DEFAULT_MITRE_LIMIT = 5.0;
1192 static const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
1193 double mitreLimit = DEFAULT_MITRE_LIMIT;
1194 int joinStyle = DEFAULT_JOIN_STYLE;
1195 char *param = NULL;
1196 char *paramstr = NULL;
1197
1198 /* Read SQL arguments */
1199 nargs = PG_NARGS();
1200 gser_input = PG_GETARG_GSERIALIZED_P(0);
1201 size = PG_GETARG_FLOAT8(1);
1202
1203 /* For distance == 0, just return the input. */
1204 if (size == 0) PG_RETURN_POINTER(gser_input);
1205
1206 /* Read the lwgeom, check for errors */
1207 lwgeom_input = lwgeom_from_gserialized(gser_input);
1208 if ( ! lwgeom_input )
1209 lwpgerror("ST_OffsetCurve: lwgeom_from_gserialized returned NULL");
1210
1211 /* For empty inputs, just echo them back */
1212 if ( lwgeom_is_empty(lwgeom_input) )
1213 PG_RETURN_POINTER(gser_input);
1214
1215 /* Process the optional arguments */
1216 if ( nargs > 2 )
1217 {
1218 text *wkttext = PG_GETARG_TEXT_P(2);
1219 paramstr = text_to_cstring(wkttext);
1220
1221 POSTGIS_DEBUGF(3, "paramstr: %s", paramstr);
1222
1223 for ( param=paramstr; ; param=NULL )
1224 {
1225 char *key, *val;
1226 param = strtok(param, " ");
1227 if (!param) break;
1228 POSTGIS_DEBUGF(3, "Param: %s", param);
1229
1230 key = param;
1231 val = strchr(key, '=');
1232 if (!val || *(val + 1) == '\0')
1233 {
1234 lwpgerror("ST_OffsetCurve: Missing value for buffer parameter %s", key);
1235 break;
1236 }
1237 *val = '\0';
1238 ++val;
1239
1240 POSTGIS_DEBUGF(3, "Param: %s : %s", key, val);
1241
1242 if ( !strcmp(key, "join") )
1243 {
1244 if ( !strcmp(val, "round") )
1245 {
1246 joinStyle = JOIN_ROUND;
1247 }
1248 else if ( !(strcmp(val, "mitre") && strcmp(val, "miter")) )
1249 {
1250 joinStyle = JOIN_MITRE;
1251 }
1252 else if ( ! strcmp(val, "bevel") )
1253 {
1254 joinStyle = JOIN_BEVEL;
1255 }
1256 else
1257 {
1258 lwpgerror(
1259 "Invalid buffer end cap style: %s (accept: 'round', 'mitre', 'miter' or 'bevel')",
1260 val);
1261 break;
1262 }
1263 }
1264 else if ( !strcmp(key, "mitre_limit") ||
1265 !strcmp(key, "miter_limit") )
1266 {
1267 /* mitreLimit is a float */
1268 mitreLimit = atof(val);
1269 }
1270 else if ( !strcmp(key, "quad_segs") )
1271 {
1272 /* quadrant segments is an int */
1273 quadsegs = atoi(val);
1274 }
1275 else
1276 {
1277 lwpgerror(
1278 "Invalid buffer parameter: %s (accept: 'join', 'mitre_limit', 'miter_limit and 'quad_segs')",
1279 key);
1280 break;
1281 }
1282 }
1283 POSTGIS_DEBUGF(3, "joinStyle:%d mitreLimit:%g", joinStyle, mitreLimit);
1284 pfree(paramstr); /* alloc'ed in text_to_cstring */
1285 }
1286
1287 lwgeom_result = lwgeom_offsetcurve(lwgeom_input, size, quadsegs, joinStyle, mitreLimit);
1288
1289 if (!lwgeom_result)
1290 lwpgerror("ST_OffsetCurve: lwgeom_offsetcurve returned NULL");
1291
1292 gser_result = geometry_serialize(lwgeom_result);
1293 lwgeom_free(lwgeom_input);
1294 lwgeom_free(lwgeom_result);
1295 PG_RETURN_POINTER(gser_result);
1296}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:193
char * text_to_cstring(const text *textptr)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)

References geometry_serialize(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), lwgeom_offsetcurve(), and text_to_cstring().

Here is the call graph for this function: