PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ST_OffsetCurve()

Datum ST_OffsetCurve ( PG_FUNCTION_ARGS  )

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

1339 {
1340  GSERIALIZED *gser_input;
1341  GSERIALIZED *gser_result;
1342  LWGEOM *lwgeom_input;
1343  LWGEOM *lwgeom_result;
1344  double size;
1345  int quadsegs = 8; /* the default */
1346  int nargs;
1347 
1348  enum
1349  {
1350  JOIN_ROUND = 1,
1351  JOIN_MITRE = 2,
1352  JOIN_BEVEL = 3
1353  };
1354 
1355  static const double DEFAULT_MITRE_LIMIT = 5.0;
1356  static const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
1357  double mitreLimit = DEFAULT_MITRE_LIMIT;
1358  int joinStyle = DEFAULT_JOIN_STYLE;
1359  char *param = NULL;
1360  char *paramstr = NULL;
1361 
1362  /* Read SQL arguments */
1363  nargs = PG_NARGS();
1364  gser_input = PG_GETARG_GSERIALIZED_P(0);
1365  size = PG_GETARG_FLOAT8(1);
1366 
1367  /* For distance == 0, just return the input. */
1368  if (size == 0) PG_RETURN_POINTER(gser_input);
1369 
1370  /* Read the lwgeom, check for errors */
1371  lwgeom_input = lwgeom_from_gserialized(gser_input);
1372  if ( ! lwgeom_input )
1373  lwpgerror("ST_OffsetCurve: lwgeom_from_gserialized returned NULL");
1374 
1375  /* For empty inputs, just echo them back */
1376  if ( lwgeom_is_empty(lwgeom_input) )
1377  PG_RETURN_POINTER(gser_input);
1378 
1379  /* Process the optional arguments */
1380  if ( nargs > 2 )
1381  {
1382  text *wkttext = PG_GETARG_TEXT_P(2);
1383  paramstr = text_to_cstring(wkttext);
1384 
1385  POSTGIS_DEBUGF(3, "paramstr: %s", paramstr);
1386 
1387  for ( param=paramstr; ; param=NULL )
1388  {
1389  char *key, *val;
1390  param = strtok(param, " ");
1391  if (!param) break;
1392  POSTGIS_DEBUGF(3, "Param: %s", param);
1393 
1394  key = param;
1395  val = strchr(key, '=');
1396  if (!val || *(val + 1) == '\0')
1397  {
1398  lwpgerror("ST_OffsetCurve: Missing value for buffer parameter %s", key);
1399  break;
1400  }
1401  *val = '\0';
1402  ++val;
1403 
1404  POSTGIS_DEBUGF(3, "Param: %s : %s", key, val);
1405 
1406  if ( !strcmp(key, "join") )
1407  {
1408  if ( !strcmp(val, "round") )
1409  {
1410  joinStyle = JOIN_ROUND;
1411  }
1412  else if ( !(strcmp(val, "mitre") && strcmp(val, "miter")) )
1413  {
1414  joinStyle = JOIN_MITRE;
1415  }
1416  else if ( ! strcmp(val, "bevel") )
1417  {
1418  joinStyle = JOIN_BEVEL;
1419  }
1420  else
1421  {
1422  lwpgerror(
1423  "Invalid buffer end cap style: %s (accept: 'round', 'mitre', 'miter' or 'bevel')",
1424  val);
1425  break;
1426  }
1427  }
1428  else if ( !strcmp(key, "mitre_limit") ||
1429  !strcmp(key, "miter_limit") )
1430  {
1431  /* mitreLimit is a float */
1432  mitreLimit = atof(val);
1433  }
1434  else if ( !strcmp(key, "quad_segs") )
1435  {
1436  /* quadrant segments is an int */
1437  quadsegs = atoi(val);
1438  }
1439  else
1440  {
1441  lwpgerror(
1442  "Invalid buffer parameter: %s (accept: 'join', 'mitre_limit', 'miter_limit and 'quad_segs')",
1443  key);
1444  break;
1445  }
1446  }
1447  POSTGIS_DEBUGF(3, "joinStyle:%d mitreLimit:%g", joinStyle, mitreLimit);
1448  pfree(paramstr); /* alloc'ed in text_to_cstring */
1449  }
1450 
1451  lwgeom_result = lwgeom_offsetcurve(lwgeom_input, size, quadsegs, joinStyle, mitreLimit);
1452 
1453  if (!lwgeom_result)
1454  lwpgerror("ST_OffsetCurve: lwgeom_offsetcurve returned NULL");
1455 
1456  gser_result = geometry_serialize(lwgeom_result);
1457  lwgeom_free(lwgeom_input);
1458  lwgeom_free(lwgeom_result);
1459  PG_RETURN_POINTER(gser_result);
1460 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
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:203

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

Here is the call graph for this function: