PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lw_dist2d_point_curvepoly()

int lw_dist2d_point_curvepoly ( LWPOINT point,
LWCURVEPOLY poly,
DISTPTS dl 
)

Definition at line 663 of file measures.c.

664 {
665  const POINT2D *p;
666  uint32_t i;
667 
668  p = getPoint2d_cp(point->point, 0);
669 
670  if (dl->mode == DIST_MAX)
671  lwerror("lw_dist2d_point_curvepoly cannot calculate max distance");
672 
673  /* Return distance to outer ring if not inside it */
674  if ( lwgeom_contains_point(poly->rings[0], p) == LW_OUTSIDE )
675  {
676  return lw_dist2d_recursive((LWGEOM*)point, poly->rings[0], dl);
677  }
678 
679  /*
680  * Inside the outer ring.
681  * Scan though each of the inner rings looking to
682  * see if its inside. If not, distance==0.
683  * Otherwise, distance = pt to ring distance
684  */
685  for ( i = 1; i < poly->nrings; i++)
686  {
687  /* Inside a hole. Distance = pt -> ring */
688  if ( lwgeom_contains_point(poly->rings[i], p) != LW_OUTSIDE )
689  {
690  LWDEBUG(3, " inside a hole");
691  return lw_dist2d_recursive((LWGEOM*)point, poly->rings[i], dl);
692  }
693  }
694 
695  LWDEBUG(3, " inside the polygon");
696  if (dl->mode == DIST_MIN)
697  {
698  dl->distance = 0.0;
699  dl->p1.x = dl->p2.x = p->x;
700  dl->p1.y = dl->p2.y = p->y;
701  }
702 
703  return LW_TRUE; /* Is inside the polygon */
704 }
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwgeom_api.c:374
#define LW_OUTSIDE
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
Definition: lwcompound.c:129
#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
int lw_dist2d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
This is a recursive function delivering every possible combination of subgeometries.
Definition: measures.c:277
#define DIST_MIN
Definition: measures.h:44
#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
LWGEOM ** rings
Definition: liblwgeom.h:538
uint32_t nrings
Definition: liblwgeom.h:536
POINTARRAY * point
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
unsigned int uint32_t
Definition: uthash.h:78

References DIST_MAX, DIST_MIN, DISTPTS::distance, getPoint2d_cp(), lw_dist2d_recursive(), LW_OUTSIDE, LW_TRUE, LWDEBUG, lwerror(), lwgeom_contains_point(), DISTPTS::mode, LWCURVEPOLY::nrings, DISTPTS::p1, DISTPTS::p2, LWPOINT::point, LWCURVEPOLY::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: