[postgis-commits] svn - r2641 - in trunk/extras/tiger_geocoder: . utility

postgis-commits at postgis.refractions.net postgis-commits at postgis.refractions.net
Tue Jul 3 14:22:30 PDT 2007


Author: snowman
Date: 2007-07-03 14:22:29 -0700 (Tue, 03 Jul 2007)
New Revision: 2641

Added:
   trunk/extras/tiger_geocoder/utility/
   trunk/extras/tiger_geocoder/utility/cull_null.sql
   trunk/extras/tiger_geocoder/utility/levenshtein_ignore_case.sql
   trunk/extras/tiger_geocoder/utility/nullable_levenshtein.sql
   trunk/extras/tiger_geocoder/utility/utmzone.sql
Log:
Initial import of utility functions, seperated into individual files
for sanity.


Added: trunk/extras/tiger_geocoder/utility/cull_null.sql
===================================================================
--- trunk/extras/tiger_geocoder/utility/cull_null.sql	2007-07-03 21:19:54 UTC (rev 2640)
+++ trunk/extras/tiger_geocoder/utility/cull_null.sql	2007-07-03 21:22:29 UTC (rev 2641)
@@ -0,0 +1,8 @@
+-- Returns the value passed, or an empty string if null.
+-- This is used to concatinate values that may be null.
+CREATE OR REPLACE FUNCTION cull_null(VARCHAR) RETURNS VARCHAR
+AS $_$
+BEGIN
+    RETURN coalesce($1,'');
+END;
+$_$ LANGUAGE plpgsql;

Added: trunk/extras/tiger_geocoder/utility/levenshtein_ignore_case.sql
===================================================================
--- trunk/extras/tiger_geocoder/utility/levenshtein_ignore_case.sql	2007-07-03 21:19:54 UTC (rev 2640)
+++ trunk/extras/tiger_geocoder/utility/levenshtein_ignore_case.sql	2007-07-03 21:22:29 UTC (rev 2641)
@@ -0,0 +1,10 @@
+-- This function determines the levenshtein distance irespective of case.
+CREATE OR REPLACE FUNCTION levenshtein_ignore_case(VARCHAR, VARCHAR) RETURNS INTEGER
+AS $_$
+DECLARE
+  result INTEGER;
+BEGIN
+  result := levenshtein(upper($1), upper($2));
+  RETURN result;
+END
+$_$ LANGUAGE plpgsql;

Added: trunk/extras/tiger_geocoder/utility/nullable_levenshtein.sql
===================================================================
--- trunk/extras/tiger_geocoder/utility/nullable_levenshtein.sql	2007-07-03 21:19:54 UTC (rev 2640)
+++ trunk/extras/tiger_geocoder/utility/nullable_levenshtein.sql	2007-07-03 21:22:29 UTC (rev 2641)
@@ -0,0 +1,27 @@
+-- This function take two arguements.  The first is the "given string" and
+-- must not be null.  The second arguement is the "compare string" and may
+-- or may not be null.  If the second string is null, the value returned is
+-- 3, otherwise it is the levenshtein difference between the two.
+CREATE OR REPLACE FUNCTION nullable_levenshtein(VARCHAR, VARCHAR) RETURNS INTEGER
+AS $_$
+DECLARE
+  given_string VARCHAR;
+  result INTEGER := 3;
+  verbose BOOLEAN := FALSE;
+BEGIN
+  IF $1 IS NULL THEN
+    IF verbose THEN
+      RAISE NOTICE 'nullable_levenshtein - given string is NULL!';
+    END IF;
+    RETURN NULL;
+  ELSE
+    given_string := $1;
+  END IF;
+
+  IF $2 IS NOT NULL AND $2 != '' THEN
+    result := levenshtein_ignore_case(given_string, $2);
+  END IF;
+
+  RETURN result;
+END
+$_$ LANGUAGE plpgsql;

Added: trunk/extras/tiger_geocoder/utility/utmzone.sql
===================================================================
--- trunk/extras/tiger_geocoder/utility/utmzone.sql	2007-07-03 21:19:54 UTC (rev 2640)
+++ trunk/extras/tiger_geocoder/utility/utmzone.sql	2007-07-03 21:22:29 UTC (rev 2641)
@@ -0,0 +1,17 @@
+CREATE OR REPLACE FUNCTION utmzone(geometry) RETURNS integer AS
+$BODY$
+DECLARE
+    geomgeog geometry;
+    zone int;
+    pref int;
+BEGIN
+    geomgeog:=transform($1,4326);
+    IF (y(geomgeog))>0 THEN
+        pref:=32600;
+    ELSE
+        pref:=32700;
+    END IF;
+    zone:=floor((x(geomgeog)+180)/6)+1;
+    RETURN zone+pref;
+END;
+$BODY$ LANGUAGE 'plpgsql' immutable;



More information about the postgis-commits mailing list