PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ ST_OffsetCurve()

Datum ST_OffsetCurve ( PG_FUNCTION_ARGS  )

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

1277 {
1278  GSERIALIZED *gser_input;
1279  GSERIALIZED *gser_result;
1280  LWGEOM *lwgeom_input;
1281  LWGEOM *lwgeom_result;
1282  double size;
1283  int quadsegs = 8; /* the default */
1284  int nargs;
1285 
1286  enum
1287  {
1288  JOIN_ROUND = 1,
1289  JOIN_MITRE = 2,
1290  JOIN_BEVEL = 3
1291  };
1292 
1293  static const double DEFAULT_MITRE_LIMIT = 5.0;
1294  static const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
1295  double mitreLimit = DEFAULT_MITRE_LIMIT;
1296  int joinStyle = DEFAULT_JOIN_STYLE;
1297  char *param = NULL;
1298  char *paramstr = NULL;
1299 
1300  /* Read SQL arguments */
1301  nargs = PG_NARGS();
1302  gser_input = PG_GETARG_GSERIALIZED_P(0);
1303  size = PG_GETARG_FLOAT8(1);
1304 
1305  /* For distance == 0, just return the input. */
1306  if (size == 0) PG_RETURN_POINTER(gser_input);
1307 
1308  /* Read the lwgeom, check for errors */
1309  lwgeom_input = lwgeom_from_gserialized(gser_input);
1310  if ( ! lwgeom_input )
1311  lwpgerror("ST_OffsetCurve: lwgeom_from_gserialized returned NULL");
1312 
1313  /* For empty inputs, just echo them back */
1314  if ( lwgeom_is_empty(lwgeom_input) )
1315  PG_RETURN_POINTER(gser_input);
1316 
1317  /* Process the optional arguments */
1318  if ( nargs > 2 )
1319  {
1320  text *wkttext = PG_GETARG_TEXT_P(2);
1321  paramstr = text_to_cstring(wkttext);
1322 
1323  POSTGIS_DEBUGF(3, "paramstr: %s", paramstr);
1324 
1325  for ( param=paramstr; ; param=NULL )
1326  {
1327  char *key, *val;
1328  param = strtok(param, " ");
1329  if (!param) break;
1330  POSTGIS_DEBUGF(3, "Param: %s", param);
1331 
1332  key = param;
1333  val = strchr(key, '=');
1334  if (!val || *(val + 1) == '\0')
1335  {
1336  lwpgerror("ST_OffsetCurve: Missing value for buffer parameter %s", key);
1337  break;
1338  }
1339  *val = '\0';
1340  ++val;
1341 
1342  POSTGIS_DEBUGF(3, "Param: %s : %s", key, val);
1343 
1344  if ( !strcmp(key, "join") )
1345  {
1346  if ( !strcmp(val, "round") )
1347  {
1348  joinStyle = JOIN_ROUND;
1349  }
1350  else if ( !(strcmp(val, "mitre") && strcmp(val, "miter")) )
1351  {
1352  joinStyle = JOIN_MITRE;
1353  }
1354  else if ( ! strcmp(val, "bevel") )
1355  {
1356  joinStyle = JOIN_BEVEL;
1357  }
1358  else
1359  {
1360  lwpgerror(
1361  "Invalid buffer end cap style: %s (accept: 'round', 'mitre', 'miter' or 'bevel')",
1362  val);
1363  break;
1364  }
1365  }
1366  else if ( !strcmp(key, "mitre_limit") ||
1367  !strcmp(key, "miter_limit") )
1368  {
1369  /* mitreLimit is a float */
1370  mitreLimit = atof(val);
1371  }
1372  else if ( !strcmp(key, "quad_segs") )
1373  {
1374  /* quadrant segments is an int */
1375  quadsegs = atoi(val);
1376  }
1377  else
1378  {
1379  lwpgerror(
1380  "Invalid buffer parameter: %s (accept: 'join', 'mitre_limit', 'miter_limit and 'quad_segs')",
1381  key);
1382  break;
1383  }
1384  }
1385  POSTGIS_DEBUGF(3, "joinStyle:%d mitreLimit:%g", joinStyle, mitreLimit);
1386  pfree(paramstr); /* alloc'ed in text_to_cstring */
1387  }
1388 
1389  lwgeom_result = lwgeom_offsetcurve(lwgeom_input, size, quadsegs, joinStyle, mitreLimit);
1390 
1391  if (!lwgeom_result)
1392  lwpgerror("ST_OffsetCurve: lwgeom_offsetcurve returned NULL");
1393 
1394  gser_result = geometry_serialize(lwgeom_result);
1395  lwgeom_free(lwgeom_input);
1396  lwgeom_free(lwgeom_result);
1397  PG_RETURN_POINTER(gser_result);
1398 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
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:199

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

Here is the call graph for this function: