PostGIS  2.4.9dev-r@@SVN_REVISION@@

## ◆ lw_dist3d_distancepoint()

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

Function initializing 3dclosestpoint calculations.

Definition at line 214 of file measures3d.c.

Referenced by lwgeom_closest_point_3d().

215 {
216
217  double x,y,z;
218  DISTPTS3D thedl;
219  double initdistance = FLT_MAX;
220  LWGEOM *result;
221
222  thedl.mode = mode;
223  thedl.distance= initdistance;
224  thedl.tolerance = 0;
225
226  LWDEBUG(2, "lw_dist3d_distancepoint is called");
227
228  /*Check if we really have 3D geoemtries*/
229  /*If not, send it to 2D-calculations which will give the same result*/
230  /*as an infinite z-value at one or two of the geometries*/
231  if(!lwgeom_has_z(lw1) || !lwgeom_has_z(lw2))
232  {
233  lwnotice("One or both of the geometries is missing z-value. The unknown z-value will be regarded as \"any value\"");
234
235  if(!lwgeom_has_z(lw1) && !lwgeom_has_z(lw2))
236  return lw_dist2d_distancepoint(lw1, lw2, srid, mode);
237
238
239  DISTPTS thedl2d;
240  thedl2d.mode = mode;
241  thedl2d.distance = initdistance;
242  thedl2d.tolerance = 0.0;
243  if (!lw_dist2d_comp( lw1,lw2,&thedl2d))
244  {
245  /*should never get here. all cases ought to be error handled earlier*/
246  lwerror("Some unspecified error.");
247  return (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
248  }
249
250  LWGEOM *vertical_line;
251  if(!lwgeom_has_z(lw1))
252  {
253  x=thedl2d.p1.x;
254  y=thedl2d.p1.y;
255
256  vertical_line = create_v_line(lw2,x,y,srid);
257  if (!lw_dist3d_recursive(vertical_line, lw2, &thedl))
258  {
259  /*should never get here. all cases ought to be error handled earlier*/
260  lwfree(vertical_line);
261  lwerror("Some unspecified error.");
262  return (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
263  }
264  lwfree(vertical_line);
265  }
266
267  if(!lwgeom_has_z(lw2))
268  {
269  x=thedl2d.p2.x;
270  y=thedl2d.p2.y;
271
272  vertical_line = create_v_line(lw1,x,y,srid);
273  if (!lw_dist3d_recursive(lw1, vertical_line, &thedl))
274  {
275  /*should never get here. all cases ought to be error handled earlier*/
276  lwfree(vertical_line);
277  lwerror("Some unspecified error.");
278  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
279  }
280  lwfree(vertical_line);
281  }
282
283  }
284  else
285  {
286  if (!lw_dist3d_recursive(lw1, lw2, &thedl))
287  {
288  /*should never get here. all cases ought to be error handled earlier*/
289  lwerror("Some unspecified error.");
290  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
291  }
292  }
293  if (thedl.distance == initdistance)
294  {
295  LWDEBUG(3, "didn't find geometries to measure between, returning null");
296  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
297  }
298  else
299  {
300  x=thedl.p1.x;
301  y=thedl.p1.y;
302  z=thedl.p1.z;
303  result = (LWGEOM *)lwpoint_make3dz(srid, x, y, z);
304  }
305
306  return result;
307 }
double z
Definition: liblwgeom.h:334
double y
Definition: liblwgeom.h:334
double distance
Definition: measures3d.h:41
LWGEOM * lw_dist2d_distancepoint(const LWGEOM *lw1, const LWGEOM *lw2, int srid, int mode)
Function initializing closestpoint calculations.
Definition: measures.c:131
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:245
double x
Definition: liblwgeom.h:334
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
void lwfree(void *mem)
Definition: lwutil.c:244
int mode
Definition: measures.h:54
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
Structure used in distance-calculations.
Definition: measures3d.h:39
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:885
POINT3DZ p1
Definition: measures3d.h:42
POINT2D p1
Definition: measures.h:52
double tolerance
Definition: measures.h:56
double x
Definition: liblwgeom.h:328
LWPOINT * lwpoint_make3dz(int srid, double x, double y, double z)
Definition: lwpoint.c:173
POINT2D p2
Definition: measures.h:53
int mode
Definition: measures3d.h:44
double y
Definition: liblwgeom.h:328
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:399
double tolerance
Definition: measures3d.h:46
double distance
Definition: measures.h:51
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:71
Structure used in distance-calculations.
Definition: measures.h:49
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
Here is the call graph for this function: Here is the caller graph for this function:
{"ft_lang_label":"__label__en","ft_lang_prob":0.5520505,"math_prob":0.97115844,"size":1675,"snap":"2023-40-2023-50","text_gpt3_token_len":447,"char_repetition_ratio":0.13943747,"word_repetition_ratio":0.06167401,"special_character_ratio":0.25014925,"punctuation_ratio":0.19031142,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9685489,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,1,null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-08T19:42:07Z\",\"WARC-Record-ID\":\"<urn:uuid:bc97e9cb-26e7-45aa-8807-d869b2004c1c>\",\"Content-Length\":\"43806\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2a04b95a-63c7-4e53-b2d8-19b8f51f37a8>\",\"WARC-Concurrent-To\":\"<urn:uuid:43e8b9fa-6ccc-4213-9ec4-b518c8dd3e2b>\",\"WARC-IP-Address\":\"209.208.97.173\",\"WARC-Target-URI\":\"http://postgis.net/docs/doxygen/2.4/df/d38/measures3d_8h_af06b5a6d7147a64e8af6f2821eec00a9.html\",\"WARC-Payload-Digest\":\"sha1:UQUB26VUZVT2NF3QZZYNYL2VA3DOBXOH\",\"WARC-Block-Digest\":\"sha1:WGEDSLU6GVKNVU6RFB77Z7CGYGLDRWUF\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100769.54_warc_CC-MAIN-20231208180539-20231208210539-00743.warc.gz\"}"}