PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ 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 96 of file measures.c.

97 {
98  double x1, x2, y1, y2;
99 
100  double initdistance = (mode == DIST_MIN ? FLT_MAX : -1.0);
101  DISTPTS thedl;
102  LWPOINT *lwpoints[2];
103  LWGEOM *result;
104 
105  thedl.mode = mode;
106  thedl.distance = initdistance;
107  thedl.tolerance = 0.0;
108 
109  LWDEBUG(2, "lw_dist2d_distanceline is called");
110 
111  if (!lw_dist2d_comp(lw1, lw2, &thedl))
112  {
113  /*should never get here. all cases ought to be error handled earlier*/
114  lwerror("Some unspecified error.");
116  }
117 
118  /*if thedl.distance is unchanged there where only empty geometries input*/
119  if (thedl.distance == initdistance)
120  {
121  LWDEBUG(3, "didn't find geometries to measure between, returning null");
123  }
124  else
125  {
126  x1 = thedl.p1.x;
127  y1 = thedl.p1.y;
128  x2 = thedl.p2.x;
129  y2 = thedl.p2.y;
130 
131  lwpoints[0] = lwpoint_make2d(srid, x1, y1);
132  lwpoints[1] = lwpoint_make2d(srid, x2, y2);
133 
134  result = (LWGEOM *)lwline_from_ptarray(srid, 2, lwpoints);
135  }
136  return result;
137 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition: lwpoint.c:163
LWLINE * lwline_from_ptarray(int32_t srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:228
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwcollection.c:92
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:101
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
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:251
#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:390
double x
Definition: liblwgeom.h:390

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, result, 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: