PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ST_OffsetCurve()

Datum ST_OffsetCurve ( PG_FUNCTION_ARGS  )

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

1065 {
1066  GSERIALIZED *gser_input;
1067  GSERIALIZED *gser_result;
1068  LWGEOM *lwgeom_input;
1069  LWGEOM *lwgeom_result;
1070  double size;
1071  int quadsegs = 8; /* the default */
1072  int nargs;
1073 
1074  enum
1075  {
1076  JOIN_ROUND = 1,
1077  JOIN_MITRE = 2,
1078  JOIN_BEVEL = 3
1079  };
1080 
1081  static const double DEFAULT_MITRE_LIMIT = 5.0;
1082  static const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
1083  double mitreLimit = DEFAULT_MITRE_LIMIT;
1084  int joinStyle = DEFAULT_JOIN_STYLE;
1085  char *param = NULL;
1086  char *paramstr = NULL;
1087 
1088  /* Read SQL arguments */
1089  nargs = PG_NARGS();
1090  gser_input = PG_GETARG_GSERIALIZED_P(0);
1091  size = PG_GETARG_FLOAT8(1);
1092 
1093  /* For distance == 0, just return the input. */
1094  if (size == 0) PG_RETURN_POINTER(gser_input);
1095 
1096  /* Read the lwgeom, check for errors */
1097  lwgeom_input = lwgeom_from_gserialized(gser_input);
1098  if ( ! lwgeom_input )
1099  lwpgerror("ST_OffsetCurve: lwgeom_from_gserialized returned NULL");
1100 
1101  /* For empty inputs, just echo them back */
1102  if ( lwgeom_is_empty(lwgeom_input) )
1103  PG_RETURN_POINTER(gser_input);
1104 
1105  /* Process the optional arguments */
1106  if ( nargs > 2 )
1107  {
1108  text *wkttext = PG_GETARG_TEXT_P(2);
1109  paramstr = text_to_cstring(wkttext);
1110 
1111  POSTGIS_DEBUGF(3, "paramstr: %s", paramstr);
1112 
1113  for ( param=paramstr; ; param=NULL )
1114  {
1115  char *key, *val;
1116  param = strtok(param, " ");
1117  if (!param) break;
1118  POSTGIS_DEBUGF(3, "Param: %s", param);
1119 
1120  key = param;
1121  val = strchr(key, '=');
1122  if (!val || *(val + 1) == '\0')
1123  {
1124  lwpgerror("ST_OffsetCurve: Missing value for buffer parameter %s", key);
1125  break;
1126  }
1127  *val = '\0';
1128  ++val;
1129 
1130  POSTGIS_DEBUGF(3, "Param: %s : %s", key, val);
1131 
1132  if ( !strcmp(key, "join") )
1133  {
1134  if ( !strcmp(val, "round") )
1135  {
1136  joinStyle = JOIN_ROUND;
1137  }
1138  else if ( !(strcmp(val, "mitre") && strcmp(val, "miter")) )
1139  {
1140  joinStyle = JOIN_MITRE;
1141  }
1142  else if ( ! strcmp(val, "bevel") )
1143  {
1144  joinStyle = JOIN_BEVEL;
1145  }
1146  else
1147  {
1148  lwpgerror(
1149  "Invalid buffer end cap style: %s (accept: 'round', 'mitre', 'miter' or 'bevel')",
1150  val);
1151  break;
1152  }
1153  }
1154  else if ( !strcmp(key, "mitre_limit") ||
1155  !strcmp(key, "miter_limit") )
1156  {
1157  /* mitreLimit is a float */
1158  mitreLimit = atof(val);
1159  }
1160  else if ( !strcmp(key, "quad_segs") )
1161  {
1162  /* quadrant segments is an int */
1163  quadsegs = atoi(val);
1164  }
1165  else
1166  {
1167  lwpgerror(
1168  "Invalid buffer parameter: %s (accept: 'join', 'mitre_limit', 'miter_limit and 'quad_segs')",
1169  key);
1170  break;
1171  }
1172  }
1173  POSTGIS_DEBUGF(3, "joinStyle:%d mitreLimit:%g", joinStyle, mitreLimit);
1174  pfree(paramstr); /* alloc'ed in text_to_cstring */
1175  }
1176 
1177  lwgeom_result = lwgeom_offsetcurve(lwgeom_input, size, quadsegs, joinStyle, mitreLimit);
1178 
1179  if (!lwgeom_result)
1180  lwpgerror("ST_OffsetCurve: lwgeom_offsetcurve returned NULL");
1181 
1182  gser_result = gserialized_from_lwgeom(lwgeom_result, 0);
1183  lwgeom_free(lwgeom_input);
1184  lwgeom_free(lwgeom_result);
1185  PG_RETURN_POINTER(gser_result);
1186 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwgeom.c:1393
char * text_to_cstring(const text *textptr)

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

Here is the call graph for this function: