PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lw_dist3d_distanceline()

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

Function initializing 3dshortestline and 3dlongestline calculations.

Definition at line 131 of file measures3d.c.

132 {
133  LWDEBUG(2, "lw_dist3d_distanceline is called");
134  double x1, x2, y1, y2, z1, z2, x, y;
135  double initdistance = (mode == DIST_MIN ? DBL_MAX : -1.0);
136  DISTPTS3D thedl;
137  LWPOINT *lwpoints[2];
138  LWGEOM *result;
139 
140  thedl.mode = mode;
141  thedl.distance = initdistance;
142  thedl.tolerance = 0.0;
143 
144  /* Check if we really have 3D geometries
145  * If not, send it to 2D-calculations which will give the same result
146  * as an infinite z-value at one or two of the geometries */
147  if (!lwgeom_has_z(lw1) || !lwgeom_has_z(lw2))
148  {
149 
150  lwnotice(
151  "One or both of the geometries is missing z-value. The unknown z-value will be regarded as \"any value\"");
152 
153  if (!lwgeom_has_z(lw1) && !lwgeom_has_z(lw2))
154  return lw_dist2d_distanceline(lw1, lw2, srid, mode);
155 
156  DISTPTS thedl2d;
157  thedl2d.mode = mode;
158  thedl2d.distance = initdistance;
159  thedl2d.tolerance = 0.0;
160  if (!lw_dist2d_comp(lw1, lw2, &thedl2d))
161  {
162  /* should never get here. all cases ought to be error handled earlier */
163  lwerror("Some unspecified error.");
165  }
166  LWGEOM *vertical_line;
167  if (!lwgeom_has_z(lw1))
168  {
169  x = thedl2d.p1.x;
170  y = thedl2d.p1.y;
171 
172  vertical_line = create_v_line(lw2, x, y, srid);
173  if (!lw_dist3d_recursive(vertical_line, lw2, &thedl))
174  {
175  /* should never get here. all cases ought to be error handled earlier */
176  lwfree(vertical_line);
177  lwerror("Some unspecified error.");
179  }
180  lwfree(vertical_line);
181  }
182  if (!lwgeom_has_z(lw2))
183  {
184  x = thedl2d.p2.x;
185  y = thedl2d.p2.y;
186 
187  vertical_line = create_v_line(lw1, x, y, srid);
188  if (!lw_dist3d_recursive(lw1, vertical_line, &thedl))
189  {
190  /* should never get here. all cases ought to be error handled earlier */
191  lwfree(vertical_line);
192  lwerror("Some unspecified error.");
193  return (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
194  }
195  lwfree(vertical_line);
196  }
197  }
198  else
199  {
200  if (!lw_dist3d_recursive(lw1, lw2, &thedl))
201  {
202  /* should never get here. all cases ought to be error handled earlier */
203  lwerror("Some unspecified error.");
205  }
206  }
207  /*if thedl.distance is unchanged there where only empty geometries input*/
208  if (thedl.distance == initdistance)
209  {
210  LWDEBUG(3, "didn't find geometries to measure between, returning null");
212  }
213  else
214  {
215  x1 = thedl.p1.x;
216  y1 = thedl.p1.y;
217  z1 = thedl.p1.z;
218  x2 = thedl.p2.x;
219  y2 = thedl.p2.y;
220  z2 = thedl.p2.z;
221 
222  lwpoints[0] = lwpoint_make3dz(srid, x1, y1, z1);
223  lwpoints[1] = lwpoint_make3dz(srid, x2, y2, z2);
224 
225  result = (LWGEOM *)lwline_from_ptarray(srid, 2, lwpoints);
226  }
227 
228  return result;
229 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
LWLINE * lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:228
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
LWGEOM * lw_dist2d_distanceline(const LWGEOM *lw1, const LWGEOM *lw2, int32_t srid, int mode)
Function initializing shortestline and longestline calculations.
Definition: measures.c:84
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
#define DIST_MIN
Definition: measures.h:44
POINT3DZ p2
Definition: measures3d.h:42
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(), DIST_MIN, DISTPTS::distance, DISTPTS3D::distance, lw_dist2d_comp(), lw_dist2d_distanceline(), lw_dist3d_recursive(), lwcollection_construct_empty(), LWDEBUG, lwerror(), lwfree(), lwgeom_has_z(), lwline_from_ptarray(), lwnotice(), lwpoint_make3dz(), DISTPTS::mode, DISTPTS3D::mode, DISTPTS::p1, DISTPTS3D::p1, DISTPTS::p2, DISTPTS3D::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_line_3d(), and lwgeom_furthest_line_3d().

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