PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ point_from_geohash()

Datum point_from_geohash ( PG_FUNCTION_ARGS  )

Definition at line 104 of file lwgeom_in_geohash.c.

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

Referenced by box2d_from_geohash().

105 {
106  GBOX *box = NULL;
107  LWPOINT *point = NULL;
108  GSERIALIZED *result = NULL;
109  text *geohash_input = NULL;
110  char *geohash = NULL;
111  double lon, lat;
112  int precision = -1;
113 
114  if (PG_ARGISNULL(0))
115  {
116  PG_RETURN_NULL();
117  }
118 
119  if (!PG_ARGISNULL(1))
120  {
121  precision = PG_GETARG_INT32(1);
122  }
123 
124  geohash_input = PG_GETARG_TEXT_P(0);
125  geohash = text_to_cstring(geohash_input);
126 
127  box = parse_geohash(geohash, precision);
128 
129  lon = box->xmin + (box->xmax - box->xmin) / 2;
130  lat = box->ymin + (box->ymax - box->ymin) / 2;
131 
132  point = lwpoint_make2d(SRID_UNKNOWN, lon, lat);
133  result = geometry_serialize((LWGEOM *) point);
134 
135  lwfree(box);
136 
137  PG_RETURN_POINTER(result);
138 }
char * text_to_cstring(const text *textptr)
void lwfree(void *mem)
Definition: lwutil.c:244
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:163
double xmax
Definition: liblwgeom.h:295
double ymin
Definition: liblwgeom.h:296
double xmin
Definition: liblwgeom.h:294
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
uint8_t precision
Definition: cu_in_twkb.c:25
double ymax
Definition: liblwgeom.h:297
static GBOX * parse_geohash(char *geohash, int precision)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
Here is the call graph for this function:
Here is the caller graph for this function: