PostGIS  3.1.6dev-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 93 of file measures.c.

94 {
95  double x1, x2, y1, y2;
96 
97  double initdistance = (mode == DIST_MIN ? FLT_MAX : -1.0);
98  DISTPTS thedl;
99  LWPOINT *lwpoints[2];
100  LWGEOM *result;
101 
102  thedl.mode = mode;
103  thedl.distance = initdistance;
104  thedl.tolerance = 0.0;
105 
106  LWDEBUG(2, "lw_dist2d_distanceline is called");
107 
108  if (!lw_dist2d_comp(lw1, lw2, &thedl))
109  {
110  /*should never get here. all cases ought to be error handled earlier*/
111  lwerror("Some unspecified error.");
113  }
114 
115  /*if thedl.distance is unchanged there where only empty geometries input*/
116  if (thedl.distance == initdistance)
117  {
118  LWDEBUG(3, "didn't find geometries to measure between, returning null");
120  }
121  else
122  {
123  x1 = thedl.p1.x;
124  y1 = thedl.p1.y;
125  x2 = thedl.p2.x;
126  y2 = thedl.p2.y;
127 
128  lwpoints[0] = lwpoint_make2d(srid, x1, y1);
129  lwpoints[1] = lwpoint_make2d(srid, x2, y2);
130 
131  result = (LWGEOM *)lwline_from_ptarray(srid, 2, lwpoints);
132  }
133  return result;
134 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#define COLLECTIONTYPE
Definition: liblwgeom.h:122
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: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:248
#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:404
double x
Definition: liblwgeom.h:404

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: