PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ lw_dist2d_poly_poly()

int lw_dist2d_poly_poly ( LWPOLY poly1,
LWPOLY poly2,
DISTPTS dl 
)

Function handling polygon to polygon calculation 1 if we are looking for maxdistance, just check the outer rings.

2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings 3 check if first point of poly2 is in a hole of poly1. If so check outer ring of poly2 against that hole of poly1 4 check if first point of poly1 is in a hole of poly2. If so check outer ring of poly1 against that hole of poly2 5 If we have come all the way here we know that the first point of one of them is inside the other ones outer ring and not in holes so we check which one is inside.

Definition at line 982 of file measures.c.

983 {
984  const POINT2D *pt;
985 
986  LWDEBUG(2, "lw_dist2d_poly_poly called");
987 
988  /*1 if we are looking for maxdistance, just check the outer rings.*/
989  if (dl->mode == DIST_MAX)
990  return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[0], dl);
991 
992  /* 2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings
993  here it would be possible to handle the information about which one is inside which one and only search for the
994  smaller ones in the bigger ones holes.*/
995  pt = getPoint2d_cp(poly1->rings[0], 0);
996  if (ptarray_contains_point(poly2->rings[0], pt) == LW_OUTSIDE)
997  {
998  pt = getPoint2d_cp(poly2->rings[0], 0);
999  if (ptarray_contains_point(poly1->rings[0], pt) == LW_OUTSIDE)
1000  return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[0], dl);
1001  }
1002 
1003  /*3 check if first point of poly2 is in a hole of poly1. If so check outer ring of poly2 against that hole
1004  * of poly1*/
1005  pt = getPoint2d_cp(poly2->rings[0], 0);
1006  for (uint32_t i = 1; i < poly1->nrings; i++)
1007  if (ptarray_contains_point(poly1->rings[i], pt) != LW_OUTSIDE)
1008  return lw_dist2d_ptarray_ptarray(poly1->rings[i], poly2->rings[0], dl);
1009 
1010  /*4 check if first point of poly1 is in a hole of poly2. If so check outer ring of poly1 against that hole
1011  * of poly2*/
1012  pt = getPoint2d_cp(poly1->rings[0], 0);
1013  for (uint32_t i = 1; i < poly2->nrings; i++)
1014  if (ptarray_contains_point(poly2->rings[i], pt) != LW_OUTSIDE)
1015  return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[i], dl);
1016 
1017  /*5 If we have come all the way here we know that the first point of one of them is inside the other ones
1018  * outer ring and not in holes so we check wich one is inside.*/
1019  pt = getPoint2d_cp(poly1->rings[0], 0);
1020  if (ptarray_contains_point(poly2->rings[0], pt) != LW_OUTSIDE)
1021  {
1022  dl->distance = 0.0;
1023  dl->p1.x = dl->p2.x = pt->x;
1024  dl->p1.y = dl->p2.y = pt->y;
1025  return LW_TRUE;
1026  }
1027 
1028  pt = getPoint2d_cp(poly2->rings[0], 0);
1029  if (ptarray_contains_point(poly1->rings[0], pt) != LW_OUTSIDE)
1030  {
1031  dl->distance = 0.0;
1032  dl->p1.x = dl->p2.x = pt->x;
1033  dl->p1.y = dl->p2.y = pt->y;
1034  return LW_TRUE;
1035  }
1036 
1037  lwerror("Unspecified error in function lw_dist2d_poly_poly");
1038  return LW_FALSE;
1039 }
#define LW_FALSE
Definition: liblwgeom.h:109
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:108
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
Return 1 if the point is inside the POINTARRAY, -1 if it is outside, and 0 if it is on the boundary.
Definition: ptarray.c:740
#define LW_OUTSIDE
#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
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:101
int lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2, DISTPTS *dl)
test each segment of l1 against each segment of l2.
Definition: measures.c:1219
#define DIST_MAX
Definition: measures.h:43
POINT2D p1
Definition: measures.h:52
POINT2D p2
Definition: measures.h:53
int mode
Definition: measures.h:54
double distance
Definition: measures.h:51
POINTARRAY ** rings
Definition: liblwgeom.h:534
uint32_t nrings
Definition: liblwgeom.h:539
double y
Definition: liblwgeom.h:405
double x
Definition: liblwgeom.h:405

References DIST_MAX, DISTPTS::distance, getPoint2d_cp(), lw_dist2d_ptarray_ptarray(), LW_FALSE, LW_OUTSIDE, LW_TRUE, LWDEBUG, lwerror(), DISTPTS::mode, LWPOLY::nrings, DISTPTS::p1, DISTPTS::p2, ptarray_contains_point(), LWPOLY::rings, POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_distribute_bruteforce().

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