PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geography_line_substring()

Datum geography_line_substring ( PG_FUNCTION_ARGS  )

Definition at line 1214 of file geography_measurement.c.

1215 {
1216  GSERIALIZED *gs = PG_GETARG_GSERIALIZED_P(0);
1217  double from_fraction = PG_GETARG_FLOAT8(1);
1218  double to_fraction = PG_GETARG_FLOAT8(2);
1219  LWLINE *lwline;
1220  LWGEOM *lwresult;
1221  SPHEROID s;
1223  bool use_spheroid = true;
1224 
1225  if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
1226  use_spheroid = PG_GETARG_BOOL(3);
1227 
1228  /* Return NULL on empty argument. */
1229  if ( gserialized_is_empty(gs) )
1230  {
1231  PG_FREE_IF_COPY(gs, 0);
1232  PG_RETURN_NULL();
1233  }
1234 
1235  if ( from_fraction < 0 || from_fraction > 1 )
1236  {
1237  elog(ERROR,"%s: second argument is not within [0,1]", __func__);
1238  PG_FREE_IF_COPY(gs, 0);
1239  PG_RETURN_NULL();
1240  }
1241  if ( to_fraction < 0 || to_fraction > 1 )
1242  {
1243  elog(ERROR,"%s: argument arg is not within [0,1]", __func__);
1244  PG_FREE_IF_COPY(gs, 0);
1245  PG_RETURN_NULL();
1246  }
1247  if ( from_fraction > to_fraction )
1248  {
1249  elog(ERROR, "%s: second argument must be smaller than third argument", __func__);
1250  PG_RETURN_NULL();
1251  }
1252 
1254  if ( !lwline )
1255  {
1256  elog(ERROR,"%s: first argument is not a line", __func__);
1257  PG_FREE_IF_COPY(gs, 0);
1258  PG_RETURN_NULL();
1259  }
1260 
1261  /* Initialize spheroid */
1262  spheroid_init_from_srid(gserialized_get_srid(gs), &s);
1263  /* Set to sphere if requested */
1264  if ( ! use_spheroid )
1265  s.a = s.b = s.radius;
1266 
1267  lwresult = geography_substring(lwline, &s,
1268  from_fraction, to_fraction, FP_TOLERANCE);
1269 
1270  lwline_free(lwline);
1271  PG_FREE_IF_COPY(gs, 0);
1272  lwgeom_set_geodetic(lwresult, true);
1273  result = geography_serialize(lwresult);
1274  lwgeom_free(lwresult);
1275 
1276  PG_RETURN_POINTER(result);
1277 }
char * s
Definition: cu_in_wkt.c:23
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:126
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:964
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
LWGEOM * geography_substring(const LWLINE *line, const SPHEROID *s, double from, double to, double tolerance)
Return the part of a line between two fractional locations.
void lwline_free(LWLINE *line)
Definition: lwline.c:67
#define FP_TOLERANCE
Floating point comparators.

References FP_TOLERANCE, geography_substring(), gserialized_get_srid(), gserialized_is_empty(), lwgeom_as_lwline(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_set_geodetic(), lwline_free(), result, and s.

Here is the call graph for this function: