PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ ST_OffsetCurve()

Datum ST_OffsetCurve ( PG_FUNCTION_ARGS  )

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

1314 {
1315  GSERIALIZED *gser_input;
1316  GSERIALIZED *gser_result;
1317  LWGEOM *lwgeom_input;
1318  LWGEOM *lwgeom_result;
1319  double size;
1320  int quadsegs = 8; /* the default */
1321  int nargs;
1322 
1323  enum
1324  {
1325  JOIN_ROUND = 1,
1326  JOIN_MITRE = 2,
1327  JOIN_BEVEL = 3
1328  };
1329 
1330  static const double DEFAULT_MITRE_LIMIT = 5.0;
1331  static const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
1332  double mitreLimit = DEFAULT_MITRE_LIMIT;
1333  int joinStyle = DEFAULT_JOIN_STYLE;
1334  char *param = NULL;
1335  char *paramstr = NULL;
1336 
1337  /* Read SQL arguments */
1338  nargs = PG_NARGS();
1339  gser_input = PG_GETARG_GSERIALIZED_P(0);
1340  size = PG_GETARG_FLOAT8(1);
1341 
1342  /* For distance == 0, just return the input. */
1343  if (size == 0) PG_RETURN_POINTER(gser_input);
1344 
1345  /* Read the lwgeom, check for errors */
1346  lwgeom_input = lwgeom_from_gserialized(gser_input);
1347  if ( ! lwgeom_input )
1348  lwpgerror("ST_OffsetCurve: lwgeom_from_gserialized returned NULL");
1349 
1350  /* For empty inputs, just echo them back */
1351  if ( lwgeom_is_empty(lwgeom_input) )
1352  PG_RETURN_POINTER(gser_input);
1353 
1354  /* Process the optional arguments */
1355  if ( nargs > 2 )
1356  {
1357  text *wkttext = PG_GETARG_TEXT_P(2);
1358  paramstr = text_to_cstring(wkttext);
1359 
1360  POSTGIS_DEBUGF(3, "paramstr: %s", paramstr);
1361 
1362  for ( param=paramstr; ; param=NULL )
1363  {
1364  char *key, *val;
1365  param = strtok(param, " ");
1366  if (!param) break;
1367  POSTGIS_DEBUGF(3, "Param: %s", param);
1368 
1369  key = param;
1370  val = strchr(key, '=');
1371  if (!val || *(val + 1) == '\0')
1372  {
1373  lwpgerror("ST_OffsetCurve: Missing value for buffer parameter %s", key);
1374  break;
1375  }
1376  *val = '\0';
1377  ++val;
1378 
1379  POSTGIS_DEBUGF(3, "Param: %s : %s", key, val);
1380 
1381  if ( !strcmp(key, "join") )
1382  {
1383  if ( !strcmp(val, "round") )
1384  {
1385  joinStyle = JOIN_ROUND;
1386  }
1387  else if ( !(strcmp(val, "mitre") && strcmp(val, "miter")) )
1388  {
1389  joinStyle = JOIN_MITRE;
1390  }
1391  else if ( ! strcmp(val, "bevel") )
1392  {
1393  joinStyle = JOIN_BEVEL;
1394  }
1395  else
1396  {
1397  lwpgerror(
1398  "Invalid buffer end cap style: %s (accept: 'round', 'mitre', 'miter' or 'bevel')",
1399  val);
1400  break;
1401  }
1402  }
1403  else if ( !strcmp(key, "mitre_limit") ||
1404  !strcmp(key, "miter_limit") )
1405  {
1406  /* mitreLimit is a float */
1407  mitreLimit = atof(val);
1408  }
1409  else if ( !strcmp(key, "quad_segs") )
1410  {
1411  /* quadrant segments is an int */
1412  quadsegs = atoi(val);
1413  }
1414  else
1415  {
1416  lwpgerror(
1417  "Invalid buffer parameter: %s (accept: 'join', 'mitre_limit', 'miter_limit and 'quad_segs')",
1418  key);
1419  break;
1420  }
1421  }
1422  POSTGIS_DEBUGF(3, "joinStyle:%d mitreLimit:%g", joinStyle, mitreLimit);
1423  pfree(paramstr); /* alloc'ed in text_to_cstring */
1424  }
1425 
1426  lwgeom_result = lwgeom_offsetcurve(lwgeom_input, size, quadsegs, joinStyle, mitreLimit);
1427 
1428  if (!lwgeom_result)
1429  lwpgerror("ST_OffsetCurve: lwgeom_offsetcurve returned NULL");
1430 
1431  gser_result = geometry_serialize(lwgeom_result);
1432  lwgeom_free(lwgeom_input);
1433  lwgeom_free(lwgeom_result);
1434  PG_RETURN_POINTER(gser_result);
1435 }
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: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:203

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

Here is the call graph for this function: