PostGIS  2.3.7dev-r@@SVN_REVISION@@
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 wich one is inside.

Definition at line 843 of file measures.c.

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().

844 {
845 
846  const POINT2D *pt;
847  int i;
848 
849  LWDEBUG(2, "lw_dist2d_poly_poly called");
850 
851  /*1 if we are looking for maxdistance, just check the outer rings.*/
852  if (dl->mode == DIST_MAX)
853  {
854  return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[0], dl);
855  }
856 
857 
858  /* 2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings
859  here it would be possible to handle the information about wich one is inside wich one and only search for the smaller ones in the bigger ones holes.*/
860  pt = getPoint2d_cp(poly1->rings[0], 0);
861  if ( ptarray_contains_point(poly2->rings[0], pt) == LW_OUTSIDE )
862  {
863  pt = getPoint2d_cp(poly2->rings[0], 0);
864  if ( ptarray_contains_point(poly1->rings[0], pt) == LW_OUTSIDE )
865  {
866  return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[0], dl);
867  }
868  }
869 
870  /*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*/
871  pt = getPoint2d_cp(poly2->rings[0], 0);
872  for (i=1; i<poly1->nrings; i++)
873  {
874  /* Inside a hole */
875  if ( ptarray_contains_point(poly1->rings[i], pt) != LW_OUTSIDE )
876  {
877  return lw_dist2d_ptarray_ptarray(poly1->rings[i], poly2->rings[0], dl);
878  }
879  }
880 
881  /*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*/
882  pt = getPoint2d_cp(poly1->rings[0], 0);
883  for (i=1; i<poly2->nrings; i++)
884  {
885  /* Inside a hole */
886  if ( ptarray_contains_point(poly2->rings[i], pt) != LW_OUTSIDE )
887  {
888  return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[i], dl);
889  }
890  }
891 
892 
893  /*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 wich one is inside.*/
894  pt = getPoint2d_cp(poly1->rings[0], 0);
895  if ( ptarray_contains_point(poly2->rings[0], pt) != LW_OUTSIDE )
896  {
897  dl->distance = 0.0;
898  dl->p1.x = dl->p2.x = pt->x;
899  dl->p1.y = dl->p2.y = pt->y;
900  return LW_TRUE;
901  }
902 
903  pt = getPoint2d_cp(poly2->rings[0], 0);
904  if ( ptarray_contains_point(poly1->rings[0], pt) != LW_OUTSIDE )
905  {
906  dl->distance = 0.0;
907  dl->p1.x = dl->p2.x = pt->x;
908  dl->p1.y = dl->p2.y = pt->y;
909  return LW_TRUE;
910  }
911 
912 
913  lwerror("Unspecified error in function lw_dist2d_poly_poly");
914  return LW_FALSE;
915 }
int mode
Definition: measures.h:51
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
POINT2D p1
Definition: measures.h:49
double x
Definition: liblwgeom.h:327
#define LW_FALSE
Definition: liblwgeom.h:76
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:485
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
POINTARRAY ** rings
Definition: liblwgeom.h:456
POINT2D p2
Definition: measures.h:50
int nrings
Definition: liblwgeom.h:454
double y
Definition: liblwgeom.h:327
double distance
Definition: measures.h:48
#define DIST_MAX
Definition: measures.h:40
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:733
#define LW_OUTSIDE
int lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2, DISTPTS *dl)
test each segment of l1 against each segment of l2.
Definition: measures.c:1131
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102

Here is the call graph for this function:

Here is the caller graph for this function: