PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwpoly_pt_outside_hack()

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

Definition at line 1483 of file lwgeodetic.c.

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, rad2deg, vector_scale(), vector_sum(), POINT2D::x, POINT4D::x, POINT2D::y, and POINT4D::y.

Referenced by lwpoly_pt_outside().

1484 {
1485  GEOGRAPHIC_POINT g1, g2, gSum;
1486  POINT4D p1, p2;
1487  POINT3D q1, q2, qMid, qCross, qSum;
1488  POINTARRAY *pa;
1489  if (lwgeom_is_empty((LWGEOM*)poly))
1490  return LW_FAILURE;
1491  if (poly->nrings < 1)
1492  return LW_FAILURE;
1493  pa = poly->rings[0];
1494  if (pa->npoints < 2)
1495  return LW_FAILURE;
1496 
1497  /* First two points of ring */
1498  getPoint4d_p(pa, 0, &p1);
1499  getPoint4d_p(pa, 1, &p2);
1500  /* Convert to XYZ unit vectors */
1501  geographic_point_init(p1.x, p1.y, &g1);
1502  geographic_point_init(p2.x, p2.y, &g2);
1503  geog2cart(&g1, &q1);
1504  geog2cart(&g2, &q2);
1505  /* Mid-point of first two points */
1506  vector_sum(&q1, &q2, &qMid);
1507  normalize(&qMid);
1508  /* Cross product of first two points (perpendicular) */
1509  cross_product(&q1, &q2, &qCross);
1510  normalize(&qCross);
1511  /* Invert it to put it outside, and scale down */
1512  vector_scale(&qCross, -0.2);
1513  /* Project midpoint to the right */
1514  vector_sum(&qMid, &qCross, &qSum);
1515  normalize(&qSum);
1516  /* Convert back to lon/lat */
1517  cart2geog(&qSum, &gSum);
1518  pt_outside->x = rad2deg(gSum.lon);
1519  pt_outside->y = rad2deg(gSum.lat);
1520  return LW_SUCCESS;
1521 }
double x
Definition: liblwgeom.h:352
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:611
int npoints
Definition: liblwgeom.h:371
#define LW_SUCCESS
Definition: liblwgeom.h:80
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:410
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:52
#define LW_FAILURE
Definition: liblwgeom.h:79
double x
Definition: liblwgeom.h:328
#define rad2deg(r)
Definition: lwgeodetic.h:80
double y
Definition: liblwgeom.h:328
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:400
void vector_sum(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the sum of two vectors.
Definition: lwgeodetic.c:461
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:180
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:1346
double y
Definition: liblwgeom.h:352
static void cross_product(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the cross product of two vectors.
Definition: lwgeodetic.c:450
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
void vector_scale(POINT3D *n, double scale)
Scale a vector out by a factor.
Definition: lwgeodetic.c:483
Here is the call graph for this function:
Here is the caller graph for this function: