PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ ST_OffsetCurve()

Datum ST_OffsetCurve ( PG_FUNCTION_ARGS  )

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

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

Referenced by ST_GeneratePoints().

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