PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwpoly_pt_outside_hack()

static int lwpoly_pt_outside_hack ( const LWPOLY poly,
POINT2D pt_outside 
)
static

Definition at line 1487 of file lwgeodetic.c.

1488 {
1489  GEOGRAPHIC_POINT g1, g2, gSum;
1490  POINT4D p1, p2;
1491  POINT3D q1, q2, qMid, qCross, qSum;
1492  POINTARRAY *pa;
1493  if (lwgeom_is_empty((LWGEOM*)poly))
1494  return LW_FAILURE;
1495  if (poly->nrings < 1)
1496  return LW_FAILURE;
1497  pa = poly->rings[0];
1498  if (pa->npoints < 2)
1499  return LW_FAILURE;
1500 
1501  /* First two points of ring */
1502  getPoint4d_p(pa, 0, &p1);
1503  getPoint4d_p(pa, 1, &p2);
1504  /* Convert to XYZ unit vectors */
1505  geographic_point_init(p1.x, p1.y, &g1);
1506  geographic_point_init(p2.x, p2.y, &g2);
1507  geog2cart(&g1, &q1);
1508  geog2cart(&g2, &q2);
1509  /* Mid-point of first two points */
1510  vector_sum(&q1, &q2, &qMid);
1511  normalize(&qMid);
1512  /* Cross product of first two points (perpendicular) */
1513  cross_product(&q1, &q2, &qCross);
1514  normalize(&qCross);
1515  /* Invert it to put it outside, and scale down */
1516  vector_scale(&qCross, -0.2);
1517  /* Project midpoint to the right */
1518  vector_sum(&qMid, &qCross, &qSum);
1519  normalize(&qSum);
1520  /* Convert back to lon/lat */
1521  cart2geog(&qSum, &gSum);
1522  pt_outside->x = rad2deg(gSum.lon);
1523  pt_outside->y = rad2deg(gSum.lat);
1524  return LW_SUCCESS;
1525 }
#define LW_FAILURE
Definition: liblwgeom.h:79
#define LW_SUCCESS
Definition: liblwgeom.h:80
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwgeom.c:1393
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:123
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:615
void vector_scale(POINT3D *n, double scale)
Scale a vector out by a factor.
Definition: lwgeodetic.c:487
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesian coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:414
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:180
static void cross_product(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the cross product of two vectors.
Definition: lwgeodetic.c:454
void vector_sum(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the sum of two vectors.
Definition: lwgeodetic.c:465
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesian coordinates on unit sphere.
Definition: lwgeodetic.c:404
#define rad2deg(r)
Definition: lwgeodetic.h:80
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:53
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355
uint32_t npoints
Definition: liblwgeom.h:374

References cart2geog(), cross_product(), geog2cart(), geographic_point_init(), getPoint4d_p(), GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, LW_FAILURE, LW_SUCCESS, lwgeom_is_empty(), normalize(), POINTARRAY::npoints, LWPOLY::nrings, rad2deg, LWPOLY::rings, vector_scale(), vector_sum(), POINT2D::x, POINT4D::x, POINT2D::y, and POINT4D::y.

Referenced by lwpoly_pt_outside().

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