PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lw_dist3d_distancepoint()

LWGEOM* lw_dist3d_distancepoint ( const LWGEOM lw1,
const LWGEOM lw2,
int32_t  srid,
int  mode 
)

Function initializing 3dclosestpoint calculations.

Definition at line 235 of file measures3d.c.

236 {
237 
238  double x, y, z;
239  DISTPTS3D thedl;
240  double initdistance = DBL_MAX;
241  LWGEOM *result;
242 
243  thedl.mode = mode;
244  thedl.distance = initdistance;
245  thedl.tolerance = 0;
246 
247  LWDEBUG(2, "lw_dist3d_distancepoint is called");
248 
249  /* Check if we really have 3D geometries
250  * If not, send it to 2D-calculations which will give the same result
251  * as an infinite z-value at one or two of the geometries
252  */
253  if (!lwgeom_has_z(lw1) || !lwgeom_has_z(lw2))
254  {
255  lwnotice(
256  "One or both of the geometries is missing z-value. The unknown z-value will be regarded as \"any value\"");
257 
258  if (!lwgeom_has_z(lw1) && !lwgeom_has_z(lw2))
259  return lw_dist2d_distancepoint(lw1, lw2, srid, mode);
260 
261  DISTPTS thedl2d;
262  thedl2d.mode = mode;
263  thedl2d.distance = initdistance;
264  thedl2d.tolerance = 0.0;
265  if (!lw_dist2d_comp(lw1, lw2, &thedl2d))
266  {
267  /* should never get here. all cases ought to be error handled earlier */
268  lwerror("Some unspecified error.");
269  return (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
270  }
271 
272  LWGEOM *vertical_line;
273  if (!lwgeom_has_z(lw1))
274  {
275  x = thedl2d.p1.x;
276  y = thedl2d.p1.y;
277 
278  vertical_line = create_v_line(lw2, x, y, srid);
279  if (!lw_dist3d_recursive(vertical_line, lw2, &thedl))
280  {
281  /* should never get here. all cases ought to be error handled earlier */
282  lwfree(vertical_line);
283  lwerror("Some unspecified error.");
284  return (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
285  }
286  lwfree(vertical_line);
287  }
288 
289  if (!lwgeom_has_z(lw2))
290  {
291  x = thedl2d.p2.x;
292  y = thedl2d.p2.y;
293 
294  vertical_line = create_v_line(lw1, x, y, srid);
295  if (!lw_dist3d_recursive(lw1, vertical_line, &thedl))
296  {
297  /* should never get here. all cases ought to be error handled earlier */
298  lwfree(vertical_line);
299  lwerror("Some unspecified error.");
301  }
302  lwfree(vertical_line);
303  }
304  }
305  else
306  {
307  if (!lw_dist3d_recursive(lw1, lw2, &thedl))
308  {
309  /* should never get here. all cases ought to be error handled earlier */
310  lwerror("Some unspecified error.");
312  }
313  }
314  if (thedl.distance == initdistance)
315  {
316  LWDEBUG(3, "didn't find geometries to measure between, returning null");
318  }
319  else
320  {
321  x = thedl.p1.x;
322  y = thedl.p1.y;
323  z = thedl.p1.z;
324  result = (LWGEOM *)lwpoint_make3dz(srid, x, y, z);
325  }
326 
327  return result;
328 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:934
void lwfree(void *mem)
Definition: lwutil.c:248
LWPOINT * lwpoint_make3dz(int32_t srid, double x, double y, double z)
Definition: lwpoint.c:173
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwcollection.c:92
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:101
void lwnotice(const char *fmt,...) __attribute__((format(printf
Write a notice out to the notice handler.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static LWGEOM * create_v_line(const LWGEOM *lwgeom, double x, double y, int32_t srid)
This function is used to create a vertical line used for cases where one if the geometries lacks z-va...
Definition: measures3d.c:93
int lw_dist3d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS3D *dl)
This is a recursive function delivering every possible combination of subgeometries.
Definition: measures3d.c:519
int lw_dist2d_comp(const LWGEOM *lw1, const LWGEOM *lw2, DISTPTS *dl)
This function just deserializes geometries Bboxes is not checked here since it is the subgeometries b...
Definition: measures.c:239
LWGEOM * lw_dist2d_distancepoint(const LWGEOM *lw1, const LWGEOM *lw2, int32_t srid, int mode)
Function initializing closestpoint calculations.
Definition: measures.c:131
POINT3DZ p1
Definition: measures3d.h:41
double distance
Definition: measures3d.h:40
int mode
Definition: measures3d.h:43
double tolerance
Definition: measures3d.h:47
Structure used in distance-calculations.
Definition: measures3d.h:39
POINT2D p1
Definition: measures.h:52
POINT2D p2
Definition: measures.h:53
double tolerance
Definition: measures.h:56
int mode
Definition: measures.h:54
double distance
Definition: measures.h:51
Structure used in distance-calculations.
Definition: measures.h:50
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390
double z
Definition: liblwgeom.h:396
double x
Definition: liblwgeom.h:396
double y
Definition: liblwgeom.h:396

References COLLECTIONTYPE, create_v_line(), DISTPTS::distance, DISTPTS3D::distance, lw_dist2d_comp(), lw_dist2d_distancepoint(), lw_dist3d_recursive(), lwcollection_construct_empty(), LWDEBUG, lwerror(), lwfree(), lwgeom_has_z(), lwnotice(), lwpoint_make3dz(), DISTPTS::mode, DISTPTS3D::mode, DISTPTS::p1, DISTPTS3D::p1, DISTPTS::p2, result, DISTPTS::tolerance, DISTPTS3D::tolerance, POINT2D::x, POINT3DZ::x, pixval::x, POINT2D::y, POINT3DZ::y, pixval::y, and POINT3DZ::z.

Referenced by lwgeom_closest_point_3d().

Here is the call graph for this function:
Here is the caller graph for this function: