2

i was wondering if anyone created a ST_GeoHash36 function inside postGIS,

i know the ST_GeoHash + ST_GeomFromGeoHash functions exists,

But i need the geohash36 function inside postGIS, i need a smaller hash:

info: http://en.wikipedia.org/wiki/Geohash-36

ruby implementation: https://github.com/clothesnetwork/geohash36

online demostration: http://geo36.org/bdrdC26BqH-m

Anyone know if this exists?

Txs!


** Solution! **

i made a postgresql function that use the geohash36 script! works great!

geohash36_encode function:

CREATE OR REPLACE FUNCTION geohash36_encode(double precision, double precision)
RETURNS text AS
$BODY$
#!/bin/sh
echo `/bin/sh /opt/geohash36_coords.sh hash $1 $2`
$BODY$
LANGUAGE plsh VOLATILE
COST 100;
ALTER FUNCTION geohash36_encode(double precision, double precision)
OWNER TO postgres;

geohash36_decode function:

CREATE OR REPLACE FUNCTION geohash36_decode(character varying)
RETURNS text AS
$BODY$
#!/bin/sh
LAT=`/bin/sh /opt/geohash36_coords.sh coords $1 | cut -d':' -f 2 | cut -d' ' -f 2`;
LON=`/bin/sh /opt/geohash36_coords.sh coords $1 | cut -d':' -f 3 | cut -d' ' -f 2`;
echo $LAT,$LON
$BODY$
LANGUAGE plsh VOLATILE
COST 100;
ALTER FUNCTION geohash36_decode(character varying)
OWNER TO postgres;

example:

enter image description here

geohash36_coords.sh code:

#! /bin/bash
#echo $1 $2 $3

if [ $1 = "coords" ]; then
               echo `geohash36 coords $2`
            fi

if [ $1 = "hash" ]; then
               echo `geohash36 hash $2 $3`
            fi

IMPORTANT: YOU NEED TO HAVE THIS ALREADY INSTALLED : https://github.com/clothesnetwork/geohash36

  • Not to my knowledge. Probably good to put in a feature request. If its easy enough, it might get implemented in next version of PostGIS (PostGIS 2.2). We haven't called feature freeze yet. trac.osgeo.org/postgis – LR1234567 Nov 12 '14 at 7:49
1

Looks like you found a good solution. If in the future you don't want to, or can't, rely on an external shell script you can bring your ruby implementation into the database through PL/Ruby.

  • thats' great ill try that. Get external shell inside sql its kind of unsecure.. so pl/ruby its a safer and more compact solution. I'll try that thanks!! – vlasvlasvlas Jan 28 '15 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.