PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lw_dist2d_distanceline()

LWGEOM * lw_dist2d_distanceline ( const LWGEOM lw1,
const LWGEOM lw2,
int32_t  srid,
int  mode 
)

Function initializing shortestline and longestline calculations.

Definition at line 81 of file measures.c.

82{
83 double x1, x2, y1, y2;
84
85 double initdistance = (mode == DIST_MIN ? FLT_MAX : -1.0);
86 DISTPTS thedl;
87 LWPOINT *lwpoints[2];
88 LWGEOM *result;
89
90 thedl.mode = mode;
91 thedl.distance = initdistance;
92 thedl.tolerance = 0.0;
93
94 LWDEBUG(2, "lw_dist2d_distanceline is called");
95
96 if (!lw_dist2d_comp(lw1, lw2, &thedl))
97 {
98 /*should never get here. all cases ought to be error handled earlier*/
99 lwerror("Some unspecified error.");
100 result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
101 }
102
103 /*if thedl.distance is unchanged there where only empty geometries input*/
104 if (thedl.distance == initdistance)
105 {
106 LWDEBUG(3, "didn't find geometries to measure between, returning null");
107 result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
108 }
109 else
110 {
111 x1 = thedl.p1.x;
112 y1 = thedl.p1.y;
113 x2 = thedl.p2.x;
114 y2 = thedl.p2.y;
115
116 lwpoints[0] = lwpoint_make2d(srid, x1, y1);
117 lwpoints[1] = lwpoint_make2d(srid, x2, y2);
118
119 result = (LWGEOM *)lwline_from_ptarray(srid, 2, lwpoints);
120 }
121 return result;
122}
#define COLLECTIONTYPE
Definition liblwgeom.h:122
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition lwpoint.c:163
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
LWLINE * lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points)
Definition lwline.c:228
#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_comp(const LWGEOM *lw1, const LWGEOM *lw2, DISTPTS *dl)
This function just deserializes geometries Bboxes is not checked here since it is the subgeometries b...
Definition measures.c:236
#define DIST_MIN
Definition measures.h:44
POINT2D p1
Definition measures.h:52
POINT2D p2
Definition measures.h:53
double tolerance
Definition measures.h:56
int mode
Definition measures.h:54
double distance
Definition measures.h:51
Structure used in distance-calculations.
Definition measures.h:50
double y
Definition liblwgeom.h:376
double x
Definition liblwgeom.h:376

References COLLECTIONTYPE, DIST_MIN, DISTPTS::distance, lw_dist2d_comp(), lwcollection_construct_empty(), LWDEBUG, lwerror(), lwline_from_ptarray(), lwpoint_make2d(), DISTPTS::mode, DISTPTS::p1, DISTPTS::p2, DISTPTS::tolerance, POINT2D::x, and POINT2D::y.

Referenced by lw_dist3d_distanceline(), lwgeom_closest_line(), and lwgeom_furthest_line().

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