PostGIS  2.1.10dev-r@@SVN_REVISION@@
LWGEOM* lw_dist2d_distanceline ( LWGEOM lw1,
LWGEOM lw2,
int  srid,
int  mode 
)

Function initializing shortestline and longestline calculations.

Definition at line 44 of file measures.c.

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

Referenced by LWGEOM_longestline2d(), and LWGEOM_shortestline2d().

45 {
46  double x1,x2,y1,y2;
47 
48  double initdistance = ( mode == DIST_MIN ? MAXFLOAT : -1.0);
49  DISTPTS thedl;
50  LWPOINT *lwpoints[2];
51  LWGEOM *result;
52 
53  thedl.mode = mode;
54  thedl.distance = initdistance;
55  thedl.tolerance = 0.0;
56 
57  LWDEBUG(2, "lw_dist2d_distanceline is called");
58 
59  if (!lw_dist2d_comp( lw1,lw2,&thedl))
60  {
61  /*should never get here. all cases ought to be error handled earlier*/
62  lwerror("Some unspecified error.");
63  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
64  }
65 
66  /*if thedl.distance is unchanged there where only empty geometries input*/
67  if (thedl.distance == initdistance)
68  {
69  LWDEBUG(3, "didn't find geometries to measure between, returning null");
70  result = (LWGEOM *)lwcollection_construct_empty(COLLECTIONTYPE, srid, 0, 0);
71  }
72  else
73  {
74  x1=thedl.p1.x;
75  y1=thedl.p1.y;
76  x2=thedl.p2.x;
77  y2=thedl.p2.y;
78 
79  lwpoints[0] = lwpoint_make2d(srid, x1, y1);
80  lwpoints[1] = lwpoint_make2d(srid, x2, y2);
81 
82  result = (LWGEOM *)lwline_from_ptarray(srid, 2, lwpoints);
83  }
84  return result;
85 }
int lw_dist2d_comp(LWGEOM *lw1, LWGEOM *lw2, DISTPTS *dl)
This function just deserializes geometries Bboxes is not checked here since it is the subgeometries b...
Definition: measures.c:205
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:130
int mode
Definition: measures.h:26
#define DIST_MIN
LWLINE * lwline_from_ptarray(int srid, uint32_t npoints, LWPOINT **points)
Definition: lwline.c:213
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
char ** result
Definition: liblwgeom.h:218
POINT2D p1
Definition: measures.h:24
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
double tolerance
Definition: measures.h:28
double x
Definition: liblwgeom.h:284
POINT2D p2
Definition: measures.h:25
double y
Definition: liblwgeom.h:284
double distance
Definition: measures.h:23
#define MAXFLOAT
Largest float value.
Structure used in distance-calculations.
Definition: measures.h:21
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
#define COLLECTIONTYPE
Definition: liblwgeom.h:66

Here is the call graph for this function:

Here is the caller graph for this function: