PostGIS  2.2.7dev-r@@SVN_REVISION@@
LWGEOM* lw_dist3d_distancepoint ( const LWGEOM lw1,
const LWGEOM lw2,
int  srid,
int  mode 
)

Function initializing 3dclosestpoint calculations.

Definition at line 190 of file measures3d.c.

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, DISTPTS::tolerance, DISTPTS3D::tolerance, pixval::x, POINT2D::x, POINT3DZ::x, pixval::y, POINT2D::y, POINT3DZ::y, and POINT3DZ::z.

Referenced by lwgeom_closest_point_3d().

191 {
192 
193  double x,y,z;
194  DISTPTS3D thedl;
195  double initdistance = FLT_MAX;
196  LWGEOM *result;
197 
198  thedl.mode = mode;
199  thedl.distance= initdistance;
200  thedl.tolerance = 0;
201 
202  LWDEBUG(2, "lw_dist3d_distancepoint is called");
203 
204  /*Check if we really have 3D geoemtries*/
205  /*If not, send it to 2D-calculations which will give the same result*/
206  /*as an infinite z-value at one or two of the geometries*/
207  if(!lwgeom_has_z(lw1) || !lwgeom_has_z(lw2))
208  {
209  lwnotice("One or both of the geometries is missing z-value. The unknown z-value will be regarded as \"any value\"");
210 
211  if(!lwgeom_has_z(lw1) && !lwgeom_has_z(lw2))
212  return lw_dist2d_distancepoint(lw1, lw2, srid, mode);
213 
214 
215  DISTPTS thedl2d;
216  thedl2d.mode = mode;
217  thedl2d.distance = initdistance;
218  thedl2d.tolerance = 0.0;
219  if (!lw_dist2d_comp( lw1,lw2,&thedl2d))
220  {
221  /*should never get here. all cases ought to be error handled earlier*/
222  lwerror("Some unspecified error.");
223  return (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
224  }
225 
226  LWGEOM *vertical_line;
227  if(!lwgeom_has_z(lw1))
228  {
229  x=thedl2d.p1.x;
230  y=thedl2d.p1.y;
231 
232  vertical_line = create_v_line(lw2,x,y,srid);
233  if (!lw_dist3d_recursive(vertical_line, lw2, &thedl))
234  {
235  /*should never get here. all cases ought to be error handled earlier*/
236  lwfree(vertical_line);
237  lwerror("Some unspecified error.");
238  return (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
239  }
240  lwfree(vertical_line);
241  }
242 
243  if(!lwgeom_has_z(lw2))
244  {
245  x=thedl2d.p2.x;
246  y=thedl2d.p2.y;
247 
248  vertical_line = create_v_line(lw1,x,y,srid);
249  if (!lw_dist3d_recursive(lw1, vertical_line, &thedl))
250  {
251  /*should never get here. all cases ought to be error handled earlier*/
252  lwfree(vertical_line);
253  lwerror("Some unspecified error.");
254  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
255  }
256  lwfree(vertical_line);
257  }
258 
259  }
260  else
261  {
262  if (!lw_dist3d_recursive(lw1, lw2, &thedl))
263  {
264  /*should never get here. all cases ought to be error handled earlier*/
265  lwerror("Some unspecified error.");
266  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
267  }
268  }
269  if (thedl.distance == initdistance)
270  {
271  LWDEBUG(3, "didn't find geometries to measure between, returning null");
272  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
273  }
274  else
275  {
276  x=thedl.p1.x;
277  y=thedl.p1.y;
278  z=thedl.p1.z;
279  result = (LWGEOM *)lwpoint_make3dz(srid, x, y, z);
280  }
281 
282  return result;
283 }
double z
Definition: liblwgeom.h:318
double y
Definition: liblwgeom.h:318
double distance
Definition: measures3d.h:27
LWGEOM * lw_dist2d_distancepoint(const LWGEOM *lw1, const LWGEOM *lw2, int srid, int mode)
Function initializing closestpoint calculations.
Definition: measures.c:117
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:231
double x
Definition: liblwgeom.h:318
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:61
void lwfree(void *mem)
Definition: lwutil.c:214
int mode
Definition: measures.h:27
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
Structure used in distance-calculations.
Definition: measures3d.h:25
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:836
POINT3DZ p1
Definition: measures3d.h:28
POINT2D p1
Definition: measures.h:25
double tolerance
Definition: measures.h:29
double x
Definition: liblwgeom.h:312
LWPOINT * lwpoint_make3dz(int srid, double x, double y, double z)
Definition: lwpoint.c:142
POINT2D p2
Definition: measures.h:26
int mode
Definition: measures3d.h:30
double y
Definition: liblwgeom.h:312
tuple x
Definition: pixval.py:53
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:375
double tolerance
Definition: measures3d.h:32
double distance
Definition: measures.h:24
static LWGEOM * create_v_line(const LWGEOM *lwgeom, double x, double y, int srid)
This function is used to create a vertical line used for cases where one if the geometries lacks z-va...
Definition: measures3d.c:47
Structure used in distance-calculations.
Definition: measures.h:22
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
tuple y
Definition: pixval.py:54
#define COLLECTIONTYPE
Definition: liblwgeom.h:76

Here is the call graph for this function:

Here is the caller graph for this function: