PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lwpoly_pt_outside_hack()

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

Definition at line 1493 of file lwgeodetic.c.

1494 {
1495  GEOGRAPHIC_POINT g1, g2, gSum;
1496  POINT4D p1, p2;
1497  POINT3D q1, q2, qMid, qCross, qSum;
1498  POINTARRAY *pa;
1499  if (lwgeom_is_empty((LWGEOM*)poly))
1500  return LW_FAILURE;
1501  if (poly->nrings < 1)
1502  return LW_FAILURE;
1503  pa = poly->rings[0];
1504  if (pa->npoints < 2)
1505  return LW_FAILURE;
1506 
1507  /* First two points of ring */
1508  getPoint4d_p(pa, 0, &p1);
1509  getPoint4d_p(pa, 1, &p2);
1510  /* Convert to XYZ unit vectors */
1511  geographic_point_init(p1.x, p1.y, &g1);
1512  geographic_point_init(p2.x, p2.y, &g2);
1513  geog2cart(&g1, &q1);
1514  geog2cart(&g2, &q2);
1515  /* Mid-point of first two points */
1516  vector_sum(&q1, &q2, &qMid);
1517  normalize(&qMid);
1518  /* Cross product of first two points (perpendicular) */
1519  cross_product(&q1, &q2, &qCross);
1520  normalize(&qCross);
1521  /* Invert it to put it outside, and scale down */
1522  vector_scale(&qCross, -0.2);
1523  /* Project midpoint to the right */
1524  vector_sum(&qMid, &qCross, &qSum);
1525  normalize(&qSum);
1526  /* Convert back to lon/lat */
1527  cart2geog(&qSum, &gSum);
1528  pt_outside->x = rad2deg(gSum.lon);
1529  pt_outside->y = rad2deg(gSum.lat);
1530  return LW_SUCCESS;
1531 }
#define LW_FAILURE
Definition: liblwgeom.h:96
#define LW_SUCCESS
Definition: liblwgeom.h:97
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:125
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:81
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:203
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:54
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414
uint32_t npoints
Definition: liblwgeom.h:427

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: