PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ geography_line_substring()

Datum geography_line_substring ( PG_FUNCTION_ARGS  )

Definition at line 1211 of file geography_measurement.c.

1212 {
1213  GSERIALIZED *gs = PG_GETARG_GSERIALIZED_P(0);
1214  double from_fraction = PG_GETARG_FLOAT8(1);
1215  double to_fraction = PG_GETARG_FLOAT8(2);
1216  LWLINE *lwline;
1217  LWGEOM *lwresult;
1218  SPHEROID s;
1220  bool use_spheroid = true;
1221 
1222  if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
1223  use_spheroid = PG_GETARG_BOOL(3);
1224 
1225  /* Return NULL on empty argument. */
1226  if ( gserialized_is_empty(gs) )
1227  {
1228  PG_FREE_IF_COPY(gs, 0);
1229  PG_RETURN_NULL();
1230  }
1231 
1232  if ( from_fraction < 0 || from_fraction > 1 )
1233  {
1234  elog(ERROR,"%s: second argument is not within [0,1]", __func__);
1235  PG_FREE_IF_COPY(gs, 0);
1236  PG_RETURN_NULL();
1237  }
1238  if ( to_fraction < 0 || to_fraction > 1 )
1239  {
1240  elog(ERROR,"%s: argument arg is not within [0,1]", __func__);
1241  PG_FREE_IF_COPY(gs, 0);
1242  PG_RETURN_NULL();
1243  }
1244  if ( from_fraction > to_fraction )
1245  {
1246  elog(ERROR, "%s: second argument must be smaller than third argument", __func__);
1247  PG_RETURN_NULL();
1248  }
1249 
1251  if ( !lwline )
1252  {
1253  elog(ERROR,"%s: first argument is not a line", __func__);
1254  PG_FREE_IF_COPY(gs, 0);
1255  PG_RETURN_NULL();
1256  }
1257 
1258  /* Initialize spheroid */
1259  spheroid_init_from_srid(gserialized_get_srid(gs), &s);
1260  /* Set to sphere if requested */
1261  if ( ! use_spheroid )
1262  s.a = s.b = s.radius;
1263 
1264  lwresult = geography_substring(lwline, &s,
1265  from_fraction, to_fraction, FP_TOLERANCE);
1266 
1267  lwline_free(lwline);
1268  PG_FREE_IF_COPY(gs, 0);
1269  lwgeom_set_geodetic(lwresult, true);
1270  result = geography_serialize(lwresult);
1271  lwgeom_free(lwresult);
1272 
1273  PG_RETURN_POINTER(result);
1274 }
char * s
Definition: cu_in_wkt.c:23
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
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:155
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:181
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:1218
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: