PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 97 of file measures3d.c.

98{
99 LWDEBUG(2, "lw_dist3d_distanceline is called");
100 double x1, x2, y1, y2, z1, z2, x, y;
101 double initdistance = (mode == DIST_MIN ? DBL_MAX : -1.0);
102 DISTPTS3D thedl;
103 LWPOINT *lwpoints[2];
104 LWGEOM *result;
105
106 thedl.mode = mode;
107 thedl.distance = initdistance;
108 thedl.tolerance = 0.0;
109
110 /* Check if we really have 3D geometries
111 * If not, send it to 2D-calculations which will give the same result
112 * as an infinite z-value at one or two of the geometries */
113 if (!lwgeom_has_z(lw1) || !lwgeom_has_z(lw2))
114 {
115
116 lwnotice(
117 "One or both of the geometries is missing z-value. The unknown z-value will be regarded as \"any value\"");
118
119 if (!lwgeom_has_z(lw1) && !lwgeom_has_z(lw2))
120 return lw_dist2d_distanceline(lw1, lw2, srid, mode);
121
122 DISTPTS thedl2d;
123 thedl2d.mode = mode;
124 thedl2d.distance = initdistance;
125 thedl2d.tolerance = 0.0;
126 if (!lw_dist2d_comp(lw1, lw2, &thedl2d))
127 {
128 /* should never get here. all cases ought to be error handled earlier */
129 lwerror("Some unspecified error.");
130 result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
131 }
132 LWGEOM *vertical_line;
133 if (!lwgeom_has_z(lw1))
134 {
135 x = thedl2d.p1.x;
136 y = thedl2d.p1.y;
137
138 vertical_line = create_v_line(lw2, x, y, srid);
139 if (!lw_dist3d_recursive(vertical_line, lw2, &thedl))
140 {
141 /* should never get here. all cases ought to be error handled earlier */
142 lwfree(vertical_line);
143 lwerror("Some unspecified error.");
144 result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
145 }
146 lwfree(vertical_line);
147 }
148 if (!lwgeom_has_z(lw2))
149 {
150 x = thedl2d.p2.x;
151 y = thedl2d.p2.y;
152
153 vertical_line = create_v_line(lw1, x, y, srid);
154 if (!lw_dist3d_recursive(lw1, vertical_line, &thedl))
155 {
156 /* should never get here. all cases ought to be error handled earlier */
157 lwfree(vertical_line);
158 lwerror("Some unspecified error.");
160 }
161 lwfree(vertical_line);
162 }
163 }
164 else
165 {
166 if (!lw_dist3d_recursive(lw1, lw2, &thedl))
167 {
168 /* should never get here. all cases ought to be error handled earlier */
169 lwerror("Some unspecified error.");
170 result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
171 }
172 }
173 /*if thedl.distance is unchanged there where only empty geometries input*/
174 if (thedl.distance == initdistance)
175 {
176 LWDEBUG(3, "didn't find geometries to measure between, returning null");
177 result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
178 }
179 else
180 {
181 x1 = thedl.p1.x;
182 y1 = thedl.p1.y;
183 z1 = thedl.p1.z;
184 x2 = thedl.p2.x;
185 y2 = thedl.p2.y;
186 z2 = thedl.p2.z;
187
188 lwpoints[0] = lwpoint_make3dz(srid, x1, y1, z1);
189 lwpoints[1] = lwpoint_make3dz(srid, x2, y2, z2);
190
191 result = (LWGEOM *)lwline_from_ptarray(srid, 2, lwpoints);
192 }
193
194 return result;
195}
#define COLLECTIONTYPE
Definition liblwgeom.h:122
LWPOINT * lwpoint_make3dz(int32_t srid, double x, double y, double z)
Definition lwpoint.c:173
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition lwgeom.c:916
void lwfree(void *mem)
Definition lwutil.c:242
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
LWLINE * lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points)
Definition lwline.c:228
#define LWDEBUG(level, msg)
Definition lwgeom_log.h:83
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition lwutil.c:190
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition lwutil.c:177
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:59
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:485
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:236
LWGEOM * lw_dist2d_distanceline(const LWGEOM *lw1, const LWGEOM *lw2, int32_t srid, int mode)
Function initializing shortestline and longestline calculations.
Definition measures.c:81
#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
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:376
double x
Definition liblwgeom.h:376
double z
Definition liblwgeom.h:382
double x
Definition liblwgeom.h:382
double y
Definition liblwgeom.h:382

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, POINT2D::x, POINT3DZ::x, POINT2D::y, POINT3DZ::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: