PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum BOX3D_in ( PG_FUNCTION_ARGS  )

Definition at line 53 of file lwgeom_box3d.c.

References BOX3D::srid, SRID_UNKNOWN, BOX3D::xmax, BOX3D::xmin, BOX3D::ymax, BOX3D::ymin, BOX3D::zmax, and BOX3D::zmin.

54 {
55  char *str = PG_GETARG_CSTRING(0);
56  int nitems;
57  BOX3D *box = (BOX3D *) palloc(sizeof(BOX3D));
58  box->zmin = 0;
59  box->zmax = 0;
60 
61 
62  /*printf( "box3d_in gets '%s'\n",str); */
63 
64  if (strstr(str,"BOX3D(") != str )
65  {
66  pfree(box);
67  elog(ERROR,"BOX3D parser - doesnt start with BOX3D(");
68  PG_RETURN_NULL();
69  }
70 
71  nitems = sscanf(str,"BOX3D(%le %le %le ,%le %le %le)",
72  &box->xmin, &box->ymin, &box->zmin,
73  &box->xmax, &box->ymax, &box->zmax);
74  if (nitems != 6 )
75  {
76  nitems = sscanf(str,"BOX3D(%le %le ,%le %le)",
77  &box->xmin, &box->ymin, &box->xmax, &box->ymax);
78  if (nitems != 4)
79  {
80  pfree(box);
81  elog(ERROR,"BOX3D parser - couldnt parse. It should look like: BOX3D(xmin ymin zmin,xmax ymax zmax) or BOX3D(xmin ymin,xmax ymax)");
82  PG_RETURN_NULL();
83  }
84  }
85 
86  if (box->xmin > box->xmax)
87  {
88  float tmp = box->xmin;
89  box->xmin = box->xmax;
90  box->xmax = tmp;
91  }
92  if (box->ymin > box->ymax)
93  {
94  float tmp = box->ymin;
95  box->ymin = box->ymax;
96  box->ymax = tmp;
97  }
98  if (box->zmin > box->zmax)
99  {
100  float tmp = box->zmin;
101  box->zmin = box->zmax;
102  box->zmax = tmp;
103  }
104  box->srid = SRID_UNKNOWN;
105  PG_RETURN_POINTER(box);
106 }
int32_t srid
Definition: liblwgeom.h:235
double ymin
Definition: liblwgeom.h:233
double xmin
Definition: liblwgeom.h:233
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
double xmax
Definition: liblwgeom.h:234
double ymax
Definition: liblwgeom.h:234
double zmax
Definition: liblwgeom.h:234
double zmin
Definition: liblwgeom.h:233