PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ ST_OffsetCurve()

Datum ST_OffsetCurve ( PG_FUNCTION_ARGS  )

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

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