PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ ST_OffsetCurve()

Datum ST_OffsetCurve ( PG_FUNCTION_ARGS  )

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

1249 {
1250  GSERIALIZED *gser_input;
1251  GSERIALIZED *gser_result;
1252  LWGEOM *lwgeom_input;
1253  LWGEOM *lwgeom_result;
1254  double size;
1255  int quadsegs = 8; /* the default */
1256  int nargs;
1257 
1258  enum
1259  {
1260  JOIN_ROUND = 1,
1261  JOIN_MITRE = 2,
1262  JOIN_BEVEL = 3
1263  };
1264 
1265  static const double DEFAULT_MITRE_LIMIT = 5.0;
1266  static const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
1267  double mitreLimit = DEFAULT_MITRE_LIMIT;
1268  int joinStyle = DEFAULT_JOIN_STYLE;
1269  char *param = NULL;
1270  char *paramstr = NULL;
1271 
1272  /* Read SQL arguments */
1273  nargs = PG_NARGS();
1274  gser_input = PG_GETARG_GSERIALIZED_P(0);
1275  size = PG_GETARG_FLOAT8(1);
1276 
1277  /* For distance == 0, just return the input. */
1278  if (size == 0) PG_RETURN_POINTER(gser_input);
1279 
1280  /* Read the lwgeom, check for errors */
1281  lwgeom_input = lwgeom_from_gserialized(gser_input);
1282  if ( ! lwgeom_input )
1283  lwpgerror("ST_OffsetCurve: lwgeom_from_gserialized returned NULL");
1284 
1285  /* For empty inputs, just echo them back */
1286  if ( lwgeom_is_empty(lwgeom_input) )
1287  PG_RETURN_POINTER(gser_input);
1288 
1289  /* Process the optional arguments */
1290  if ( nargs > 2 )
1291  {
1292  text *wkttext = PG_GETARG_TEXT_P(2);
1293  paramstr = text_to_cstring(wkttext);
1294 
1295  POSTGIS_DEBUGF(3, "paramstr: %s", paramstr);
1296 
1297  for ( param=paramstr; ; param=NULL )
1298  {
1299  char *key, *val;
1300  param = strtok(param, " ");
1301  if (!param) break;
1302  POSTGIS_DEBUGF(3, "Param: %s", param);
1303 
1304  key = param;
1305  val = strchr(key, '=');
1306  if (!val || *(val + 1) == '\0')
1307  {
1308  lwpgerror("ST_OffsetCurve: Missing value for buffer parameter %s", key);
1309  break;
1310  }
1311  *val = '\0';
1312  ++val;
1313 
1314  POSTGIS_DEBUGF(3, "Param: %s : %s", key, val);
1315 
1316  if ( !strcmp(key, "join") )
1317  {
1318  if ( !strcmp(val, "round") )
1319  {
1320  joinStyle = JOIN_ROUND;
1321  }
1322  else if ( !(strcmp(val, "mitre") && strcmp(val, "miter")) )
1323  {
1324  joinStyle = JOIN_MITRE;
1325  }
1326  else if ( ! strcmp(val, "bevel") )
1327  {
1328  joinStyle = JOIN_BEVEL;
1329  }
1330  else
1331  {
1332  lwpgerror(
1333  "Invalid buffer end cap style: %s (accept: 'round', 'mitre', 'miter' or 'bevel')",
1334  val);
1335  break;
1336  }
1337  }
1338  else if ( !strcmp(key, "mitre_limit") ||
1339  !strcmp(key, "miter_limit") )
1340  {
1341  /* mitreLimit is a float */
1342  mitreLimit = atof(val);
1343  }
1344  else if ( !strcmp(key, "quad_segs") )
1345  {
1346  /* quadrant segments is an int */
1347  quadsegs = atoi(val);
1348  }
1349  else
1350  {
1351  lwpgerror(
1352  "Invalid buffer parameter: %s (accept: 'join', 'mitre_limit', 'miter_limit and 'quad_segs')",
1353  key);
1354  break;
1355  }
1356  }
1357  POSTGIS_DEBUGF(3, "joinStyle:%d mitreLimit:%g", joinStyle, mitreLimit);
1358  pfree(paramstr); /* alloc'ed in text_to_cstring */
1359  }
1360 
1361  lwgeom_result = lwgeom_offsetcurve(lwgeom_input, size, quadsegs, joinStyle, mitreLimit);
1362 
1363  if (!lwgeom_result)
1364  lwpgerror("ST_OffsetCurve: lwgeom_offsetcurve returned NULL");
1365 
1366  gser_result = geometry_serialize(lwgeom_result);
1367  lwgeom_free(lwgeom_input);
1368  lwgeom_free(lwgeom_result);
1369  PG_RETURN_POINTER(gser_result);
1370 }
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: