PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum point_from_geohash ( PG_FUNCTION_ARGS  )

Definition at line 88 of file lwgeom_in_geohash.c.

References geometry_serialize(), lwfree(), lwpoint_make2d(), parse_geohash(), precision, SRID_UNKNOWN, text2cstring(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

89 {
90  GBOX *box = NULL;
91  LWPOINT *point = NULL;
92  GSERIALIZED *result = NULL;
93  text *geohash_input = NULL;
94  char *geohash = NULL;
95  double lon, lat;
96  int precision = -1;
97 
98  if (PG_ARGISNULL(0))
99  {
100  PG_RETURN_NULL();
101  }
102 
103  if (!PG_ARGISNULL(1))
104  {
105  precision = PG_GETARG_INT32(1);
106  }
107 
108  geohash_input = PG_GETARG_TEXT_P(0);
109  geohash = text2cstring(geohash_input);
110 
111  box = parse_geohash(geohash, precision);
112 
113  lon = box->xmin + (box->xmax - box->xmin) / 2;
114  lat = box->ymin + (box->ymax - box->ymin) / 2;
115 
116  point = lwpoint_make2d(SRID_UNKNOWN, lon, lat);
117  result = geometry_serialize((LWGEOM *) point);
118 
119  lwfree(box);
120 
121  PG_RETURN_POINTER(result);
122 }
void lwfree(void *mem)
Definition: lwutil.c:214
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:132
double xmax
Definition: liblwgeom.h:277
double ymin
Definition: liblwgeom.h:278
double xmin
Definition: liblwgeom.h:276
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
char * text2cstring(const text *textptr)
uint8_t precision
Definition: cu_in_twkb.c:25
double ymax
Definition: liblwgeom.h:279
static GBOX * parse_geohash(char *geohash, int precision)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)

Here is the call graph for this function: