PostGIS  3.2.2dev-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 963 of file measures.c.

964 {
965  const POINT2D *pt;
966 
967  LWDEBUG(2, "lw_dist2d_poly_poly called");
968 
969  /*1 if we are looking for maxdistance, just check the outer rings.*/
970  if (dl->mode == DIST_MAX)
971  return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[0], dl);
972 
973  /* 2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings
974  here it would be possible to handle the information about which one is inside which one and only search for the
975  smaller ones in the bigger ones holes.*/
976  pt = getPoint2d_cp(poly1->rings[0], 0);
977  if (ptarray_contains_point(poly2->rings[0], pt) == LW_OUTSIDE)
978  {
979  pt = getPoint2d_cp(poly2->rings[0], 0);
980  if (ptarray_contains_point(poly1->rings[0], pt) == LW_OUTSIDE)
981  return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[0], dl);
982  }
983 
984  /*3 check if first point of poly2 is in a hole of poly1. If so check outer ring of poly2 against that hole
985  * of poly1*/
986  pt = getPoint2d_cp(poly2->rings[0], 0);
987  for (uint32_t i = 1; i < poly1->nrings; i++)
988  if (ptarray_contains_point(poly1->rings[i], pt) != LW_OUTSIDE)
989  return lw_dist2d_ptarray_ptarray(poly1->rings[i], poly2->rings[0], dl);
990 
991  /*4 check if first point of poly1 is in a hole of poly2. If so check outer ring of poly1 against that hole
992  * of poly2*/
993  pt = getPoint2d_cp(poly1->rings[0], 0);
994  for (uint32_t i = 1; i < poly2->nrings; i++)
995  if (ptarray_contains_point(poly2->rings[i], pt) != LW_OUTSIDE)
996  return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[i], dl);
997 
998  /*5 If we have come all the way here we know that the first point of one of them is inside the other ones
999  * outer ring and not in holes so we check wich one is inside.*/
1000  pt = getPoint2d_cp(poly1->rings[0], 0);
1001  if (ptarray_contains_point(poly2->rings[0], pt) != LW_OUTSIDE)
1002  {
1003  lw_dist2d_distpts_set(dl, 0.0, pt, pt);
1004  return LW_TRUE;
1005  }
1006 
1007  pt = getPoint2d_cp(poly2->rings[0], 0);
1008  if (ptarray_contains_point(poly1->rings[0], pt) != LW_OUTSIDE)
1009  {
1010  lw_dist2d_distpts_set(dl, 0.0, pt, pt);
1011  return LW_TRUE;
1012  }
1013 
1014  lwerror("Unspecified error in function lw_dist2d_poly_poly");
1015  return LW_FALSE;
1016 }
#define LW_FALSE
Definition: liblwgeom.h:108
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
The following is based on the "Fast Winding Number Inclusion of a Point in a Polygon" algorithm by Da...
Definition: ptarray.c:746
#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
static void lw_dist2d_distpts_set(DISTPTS *dl, double distance, const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:78
int lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2, DISTPTS *dl)
test each segment of l1 against each segment of l2.
Definition: measures.c:1186
#define DIST_MAX
Definition: measures.h:43
int mode
Definition: measures.h:54
POINTARRAY ** rings
Definition: liblwgeom.h:533
uint32_t nrings
Definition: liblwgeom.h:538

References DIST_MAX, getPoint2d_cp(), lw_dist2d_distpts_set(), lw_dist2d_ptarray_ptarray(), LW_FALSE, LW_OUTSIDE, LW_TRUE, LWDEBUG, lwerror(), DISTPTS::mode, LWPOLY::nrings, ptarray_contains_point(), and LWPOLY::rings.

Referenced by lw_dist2d_distribute_bruteforce().

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