PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ point_from_geohash()

Datum point_from_geohash ( PG_FUNCTION_ARGS  )

Definition at line 103 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.

Referenced by box2d_from_geohash().

104 {
105  GBOX *box = NULL;
106  LWPOINT *point = NULL;
107  GSERIALIZED *result = NULL;
108  text *geohash_input = NULL;
109  char *geohash = NULL;
110  double lon, lat;
111  int precision = -1;
112 
113  if (PG_ARGISNULL(0))
114  {
115  PG_RETURN_NULL();
116  }
117 
118  if (!PG_ARGISNULL(1))
119  {
120  precision = PG_GETARG_INT32(1);
121  }
122 
123  geohash_input = PG_GETARG_TEXT_P(0);
124  geohash = text2cstring(geohash_input);
125 
126  box = parse_geohash(geohash, precision);
127 
128  lon = box->xmin + (box->xmax - box->xmin) / 2;
129  lat = box->ymin + (box->ymax - box->ymin) / 2;
130 
131  point = lwpoint_make2d(SRID_UNKNOWN, lon, lat);
132  result = geometry_serialize((LWGEOM *) point);
133 
134  lwfree(box);
135 
136  PG_RETURN_POINTER(result);
137 }
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:293
double ymin
Definition: liblwgeom.h:294
double xmin
Definition: liblwgeom.h:292
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
char * text2cstring(const text *textptr)
uint8_t precision
Definition: cu_in_twkb.c:25
double ymax
Definition: liblwgeom.h:295
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: