PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ ST_OffsetCurve()

Datum ST_OffsetCurve ( PG_FUNCTION_ARGS  )

Definition at line 1086 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().

1087 {
1088  GSERIALIZED *gser_input;
1089  GSERIALIZED *gser_result;
1090  LWGEOM *lwgeom_input;
1091  LWGEOM *lwgeom_result;
1092  double size;
1093  int quadsegs = 8; /* the default */
1094  int nargs;
1095 
1096  enum
1097  {
1098  JOIN_ROUND = 1,
1099  JOIN_MITRE = 2,
1100  JOIN_BEVEL = 3
1101  };
1102 
1103  static const double DEFAULT_MITRE_LIMIT = 5.0;
1104  static const int DEFAULT_JOIN_STYLE = JOIN_ROUND;
1105  double mitreLimit = DEFAULT_MITRE_LIMIT;
1106  int joinStyle = DEFAULT_JOIN_STYLE;
1107  char *param = NULL;
1108  char *paramstr = NULL;
1109 
1110  /* Read SQL arguments */
1111  nargs = PG_NARGS();
1112  gser_input = PG_GETARG_GSERIALIZED_P(0);
1113  size = PG_GETARG_FLOAT8(1);
1114 
1115  /*
1116  * For distance == 0, just return the input.
1117  * Note that due to a bug, GEOS 3.3.0 would return EMPTY.
1118  * See http://trac.osgeo.org/geos/ticket/454
1119  */
1120  if ( size == 0 )
1121  PG_RETURN_POINTER(gser_input);
1122 
1123  /* Read the lwgeom, check for errors */
1124  lwgeom_input = lwgeom_from_gserialized(gser_input);
1125  if ( ! lwgeom_input )
1126  lwpgerror("ST_OffsetCurve: lwgeom_from_gserialized returned NULL");
1127 
1128  /* For empty inputs, just echo them back */
1129  if ( lwgeom_is_empty(lwgeom_input) )
1130  PG_RETURN_POINTER(gser_input);
1131 
1132  /* Process the optional arguments */
1133  if ( nargs > 2 )
1134  {
1135  text *wkttext = PG_GETARG_TEXT_P(2);
1136  paramstr = text_to_cstring(wkttext);
1137 
1138  POSTGIS_DEBUGF(3, "paramstr: %s", paramstr);
1139 
1140  for ( param=paramstr; ; param=NULL )
1141  {
1142  char *key, *val;
1143  param = strtok(param, " ");
1144  if (!param) break;
1145  POSTGIS_DEBUGF(3, "Param: %s", param);
1146 
1147  key = param;
1148  val = strchr(key, '=');
1149  if (!val || *(val + 1) == '\0')
1150  {
1151  lwpgerror("ST_OffsetCurve: Missing value for buffer parameter %s", key);
1152  break;
1153  }
1154  *val = '\0';
1155  ++val;
1156 
1157  POSTGIS_DEBUGF(3, "Param: %s : %s", key, val);
1158 
1159  if ( !strcmp(key, "join") )
1160  {
1161  if ( !strcmp(val, "round") )
1162  {
1163  joinStyle = JOIN_ROUND;
1164  }
1165  else if ( !(strcmp(val, "mitre") && strcmp(val, "miter")) )
1166  {
1167  joinStyle = JOIN_MITRE;
1168  }
1169  else if ( ! strcmp(val, "bevel") )
1170  {
1171  joinStyle = JOIN_BEVEL;
1172  }
1173  else
1174  {
1175  lwpgerror("Invalid buffer end cap style: %s (accept: "
1176  "'round', 'mitre', 'miter' or 'bevel')", val);
1177  break;
1178  }
1179  }
1180  else if ( !strcmp(key, "mitre_limit") ||
1181  !strcmp(key, "miter_limit") )
1182  {
1183  /* mitreLimit is a float */
1184  mitreLimit = atof(val);
1185  }
1186  else if ( !strcmp(key, "quad_segs") )
1187  {
1188  /* quadrant segments is an int */
1189  quadsegs = atoi(val);
1190  }
1191  else
1192  {
1193  lwpgerror("Invalid buffer parameter: %s (accept: "
1194  "'join', 'mitre_limit', 'miter_limit and "
1195  "'quad_segs')", key);
1196  break;
1197  }
1198  }
1199  POSTGIS_DEBUGF(3, "joinStyle:%d mitreLimit:%g", joinStyle, mitreLimit);
1200  pfree(paramstr); /* alloc'ed in text_to_cstring */
1201  }
1202 
1203  lwgeom_result = lwgeom_offsetcurve(lwgeom_input, size, quadsegs, joinStyle, mitreLimit);
1204 
1205  if (!lwgeom_result)
1206  lwpgerror("ST_OffsetCurve: lwgeom_offsetcurve returned NULL");
1207 
1208  gser_result = gserialized_from_lwgeom(lwgeom_result, 0);
1209  lwgeom_free(lwgeom_input);
1210  lwgeom_free(lwgeom_result);
1211  PG_RETURN_POINTER(gser_result);
1212 }
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: