PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ point_from_geohash()

Datum point_from_geohash ( PG_FUNCTION_ARGS  )

Definition at line 104 of file lwgeom_in_geohash.c.

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 }
static uint8_t precision
Definition: cu_in_twkb.c:25
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:163
void lwfree(void *mem)
Definition: lwutil.c:244
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
static GBOX * parse_geohash(char *geohash, int precision)
char * text_to_cstring(const text *textptr)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
double ymax
Definition: liblwgeom.h:298
double xmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:295

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

Here is the call graph for this function: