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

Function initializing 3dshortestline and 3dlongestline calculations.

Definition at line 86 of file measures3d.c.

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

Referenced by lwgeom_closest_line_3d(), and lwgeom_furthest_line_3d().

87 {
88  LWDEBUG(2, "lw_dist3d_distanceline is called");
89  double x1,x2,y1,y2, z1, z2, x, y;
90  double initdistance = ( mode == DIST_MIN ? FLT_MAX : -1.0);
91  DISTPTS3D thedl;
92  LWPOINT *lwpoints[2];
93  LWGEOM *result;
94 
95  thedl.mode = mode;
96  thedl.distance = initdistance;
97  thedl.tolerance = 0.0;
98 
99  /*Check if we really have 3D geoemtries*/
100  /*If not, send it to 2D-calculations which will give the same result*/
101  /*as an infinite z-value at one or two of the geometries*/
102  if(!lwgeom_has_z(lw1) || !lwgeom_has_z(lw2))
103  {
104 
105  lwnotice("One or both of the geometries is missing z-value. The unknown z-value will be regarded as \"any value\"");
106 
107  if(!lwgeom_has_z(lw1) && !lwgeom_has_z(lw2))
108  return lw_dist2d_distanceline(lw1, lw2, srid, mode);
109 
110  DISTPTS thedl2d;
111  thedl2d.mode = mode;
112  thedl2d.distance = initdistance;
113  thedl2d.tolerance = 0.0;
114  if (!lw_dist2d_comp( lw1,lw2,&thedl2d))
115  {
116  /*should never get here. all cases ought to be error handled earlier*/
117  lwerror("Some unspecified error.");
118  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
119  }
120  LWGEOM *vertical_line;
121  if(!lwgeom_has_z(lw1))
122  {
123  x=thedl2d.p1.x;
124  y=thedl2d.p1.y;
125 
126  vertical_line = create_v_line(lw2,x,y,srid);
127  if (!lw_dist3d_recursive(vertical_line, lw2, &thedl))
128  {
129  /*should never get here. all cases ought to be error handled earlier*/
130  lwfree(vertical_line);
131  lwerror("Some unspecified error.");
132  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
133  }
134  lwfree(vertical_line);
135  }
136  if(!lwgeom_has_z(lw2))
137  {
138  x=thedl2d.p2.x;
139  y=thedl2d.p2.y;
140 
141  vertical_line = create_v_line(lw1,x,y,srid);
142  if (!lw_dist3d_recursive(lw1, vertical_line, &thedl))
143  {
144  /*should never get here. all cases ought to be error handled earlier*/
145  lwfree(vertical_line);
146  lwerror("Some unspecified error.");
147  return (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
148  }
149  lwfree(vertical_line);
150  }
151 
152  }
153  else
154  {
155  if (!lw_dist3d_recursive(lw1, lw2, &thedl))
156  {
157  /*should never get here. all cases ought to be error handled earlier*/
158  lwerror("Some unspecified error.");
159  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
160  }
161  }
162  /*if thedl.distance is unchanged there where only empty geometries input*/
163  if (thedl.distance == initdistance)
164  {
165  LWDEBUG(3, "didn't find geometries to measure between, returning null");
166  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
167  }
168  else
169  {
170  x1=thedl.p1.x;
171  y1=thedl.p1.y;
172  z1=thedl.p1.z;
173  x2=thedl.p2.x;
174  y2=thedl.p2.y;
175  z2=thedl.p2.z;
176 
177  lwpoints[0] = lwpoint_make3dz(srid, x1, y1, z1);
178  lwpoints[1] = lwpoint_make3dz(srid, x2, y2, z2);
179 
180  result = (LWGEOM *)lwline_from_ptarray(srid, 2, lwpoints);
181  }
182 
183  return result;
184 }
double z
Definition: liblwgeom.h:318
double y
Definition: liblwgeom.h:318
double distance
Definition: measures3d.h:27
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
POINT3DZ p2
Definition: measures3d.h:29
int mode
Definition: measures.h:27
LWLINE * lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:214
#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
LWGEOM * lw_dist2d_distanceline(const LWGEOM *lw1, const LWGEOM *lw2, int srid, int mode)
Function initializing shortestline and longestline calculations.
Definition: measures.c:70
POINT2D p1
Definition: measures.h:25
double tolerance
Definition: measures.h:29
double x
Definition: liblwgeom.h:312
#define DIST_MIN
Definition: measures.h:17
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: