PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lwpoly_pt_outside_hack()

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

Definition at line 1441 of file lwgeodetic.c.

1442 {
1443  GEOGRAPHIC_POINT g1, g2, gSum;
1444  POINT4D p1, p2;
1445  POINT3D q1, q2, qMid, qCross, qSum;
1446  POINTARRAY *pa;
1447  if (lwgeom_is_empty((LWGEOM*)poly))
1448  return LW_FAILURE;
1449  if (poly->nrings < 1)
1450  return LW_FAILURE;
1451  pa = poly->rings[0];
1452  if (pa->npoints < 2)
1453  return LW_FAILURE;
1454 
1455  /* First two points of ring */
1456  getPoint4d_p(pa, 0, &p1);
1457  getPoint4d_p(pa, 1, &p2);
1458  /* Convert to XYZ unit vectors */
1459  geographic_point_init(p1.x, p1.y, &g1);
1460  geographic_point_init(p2.x, p2.y, &g2);
1461  geog2cart(&g1, &q1);
1462  geog2cart(&g2, &q2);
1463  /* Mid-point of first two points */
1464  vector_sum(&q1, &q2, &qMid);
1465  normalize(&qMid);
1466  /* Cross product of first two points (perpendicular) */
1467  cross_product(&q1, &q2, &qCross);
1468  normalize(&qCross);
1469  /* Invert it to put it outside, and scale down */
1470  vector_scale(&qCross, -0.2);
1471  /* Project midpoint to the right */
1472  vector_sum(&qMid, &qCross, &qSum);
1473  normalize(&qSum);
1474  /* Convert back to lon/lat */
1475  cart2geog(&qSum, &gSum);
1476  pt_outside->x = rad2deg(gSum.lon);
1477  pt_outside->y = rad2deg(gSum.lat);
1478  return LW_SUCCESS;
1479 }
#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:199
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: