From: Paul Ramsey Date: Thu, 13 Sep 2012 02:08:45 +0000 (+0000) Subject: #1780 ST_GeoHash should support geography type without cast X-Git-Tag: 2.1.0beta2~655 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6ad2e47e51d1f26a5fd73d6d7456ad1a34f8d77;p=postgis #1780 ST_GeoHash should support geography type without cast git-svn-id: http://svn.osgeo.org/postgis/trunk@10278 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 35bb146dc..86b3f0419 100644 --- a/NEWS +++ b/NEWS @@ -35,6 +35,7 @@ PostGIS 2.1.0 - #1856, tiger geocoder: reverse geocoder rating setting for prefer numbered highway name - #1938, Refactor basic ST_AddBand to add multiple new bands in one call - #1978, wrong answer when calculating length of a closed circular arc (circle) + - #1780, support ST_GeoHash for geography * Fixes * diff --git a/liblwgeom/lwalgorithm.c b/liblwgeom/lwalgorithm.c index a63e972e5..01f043cae 100644 --- a/liblwgeom/lwalgorithm.c +++ b/liblwgeom/lwalgorithm.c @@ -496,7 +496,7 @@ char *lwgeom_geohash(const LWGEOM *lwgeom, int precision) gbox_init(&gbox); gbox_init(&gbox_bounds); - result = lwgeom_calculate_gbox(lwgeom, &gbox); + result = lwgeom_calculate_gbox_cartesian(lwgeom, &gbox); if ( result == LW_FAILURE ) return NULL; /* Return error if we are being fed something outside our working bounds */ diff --git a/postgis/geography.sql.in.c b/postgis/geography.sql.in.c index 2efdcf53b..811ca3ed9 100644 --- a/postgis/geography.sql.in.c +++ b/postgis/geography.sql.in.c @@ -774,6 +774,12 @@ CREATE OR REPLACE FUNCTION ST_Summary(geography) AS 'MODULE_PATHNAME', 'LWGEOM_summary' LANGUAGE 'c' IMMUTABLE STRICT; +-- Availability: 2.1.0 +CREATE OR REPLACE FUNCTION ST_GeoHash(geog geography, maxchars int4 DEFAULT 0) + RETURNS TEXT + AS 'MODULE_PATHNAME', 'ST_GeoHash' + LANGUAGE 'c' IMMUTABLE STRICT; + ----------------------------------------------------------------------------- diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 2e31c57da..c6106fd9f 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -2504,9 +2504,8 @@ Datum ST_GeoHash(PG_FUNCTION_ARGS) GSERIALIZED *geom = NULL; int precision = 0; - int len = 0; char *geohash = NULL; - char *result = NULL; + text *result = NULL; if ( PG_ARGISNULL(0) ) { @@ -2525,13 +2524,10 @@ Datum ST_GeoHash(PG_FUNCTION_ARGS) if ( ! geohash ) PG_RETURN_NULL(); - len = strlen(geohash) + VARHDRSZ; - result = palloc(len); - SET_VARSIZE(result, len); - memcpy(VARDATA(result), geohash, len-VARHDRSZ); + result = cstring2text(geohash); pfree(geohash); - PG_RETURN_POINTER(result); - + + PG_RETURN_TEXT_P(result); } PG_FUNCTION_INFO_V1(ST_CollectionExtract);