PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ point_from_geohash()

Datum point_from_geohash ( PG_FUNCTION_ARGS  )

Definition at line 103 of file lwgeom_in_geohash.c.

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 = text_to_cstring(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}
static uint8_t precision
Definition cu_in_twkb.c:25
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
void lwfree(void *mem)
Definition lwutil.c:248
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition lwpoint.c:163
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215
static GBOX * parse_geohash(char *geohash, int precision)
double ymax
Definition liblwgeom.h:357
double xmax
Definition liblwgeom.h:355
double ymin
Definition liblwgeom.h:356
double xmin
Definition liblwgeom.h:354

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

Here is the call graph for this function: