PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lw_dist2d_distanceline()

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

Function initializing shortestline and longestline calculations.

Definition at line 70 of file measures.c.

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().

71 {
72  double x1,x2,y1,y2;
73 
74  double initdistance = ( mode == DIST_MIN ? FLT_MAX : -1.0);
75  DISTPTS thedl;
76  LWPOINT *lwpoints[2];
77  LWGEOM *result;
78 
79  thedl.mode = mode;
80  thedl.distance = initdistance;
81  thedl.tolerance = 0.0;
82 
83  LWDEBUG(2, "lw_dist2d_distanceline is called");
84 
85  if (!lw_dist2d_comp( lw1,lw2,&thedl))
86  {
87  /*should never get here. all cases ought to be error handled earlier*/
88  lwerror("Some unspecified error.");
89  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
90  }
91 
92  /*if thedl.distance is unchanged there where only empty geometries input*/
93  if (thedl.distance == initdistance)
94  {
95  LWDEBUG(3, "didn't find geometries to measure between, returning null");
96  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
97  }
98  else
99  {
100  x1=thedl.p1.x;
101  y1=thedl.p1.y;
102  x2=thedl.p2.x;
103  y2=thedl.p2.y;
104 
105  lwpoints[0] = lwpoint_make2d(srid, x1, y1);
106  lwpoints[1] = lwpoint_make2d(srid, x2, y2);
107 
108  result = (LWGEOM *)lwline_from_ptarray(srid, 2, lwpoints);
109  }
110  return result;
111 }
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:231
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:132
int mode
Definition: measures.h:27
LWLINE * lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:214
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
POINT2D p1
Definition: measures.h:25
double tolerance
Definition: measures.h:29
double x
Definition: liblwgeom.h:312
#define DIST_MIN
Definition: measures.h:17
POINT2D p2
Definition: measures.h:26
double y
Definition: liblwgeom.h:312
double distance
Definition: measures.h:24
Structure used in distance-calculations.
Definition: measures.h:22
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
Here is the call graph for this function:
Here is the caller graph for this function: