[postgis-devel] Tiger 2010 Geocoder Divide By Zero Error

Emily Gouge egouge at refractions.net
Fri Jun 17 16:06:01 PDT 2011


I have recently been doing some geocoding testing using the Postgis 
geocoder from 2.0.0 branch.  I started getting divide by zero errors 
today and was looking through the source code at the geocode_address 
function.  After figuring out the source of the error I looked in SVN 
and saw there was a fix committed about a week ago (thanks!) but I'm 
still somewhat confused about this part of the code.

The original divide by 0 error is caused by the following partial statement:

  ((1.0 - ' || '(least_hn(' || coalesce(quote_literal(parsed.address || 
'.0'),'NULL') || ',least_hn(b.fromhn,b.tohn)::text) /' || ' 
greatest_hn(' || coalesce(quote_literal(parsed.address || '.0'),'NULL') 
|| ',greatest_hn(b.fromhn,b.tohn)::text))' || ') * 5)::integer + 5'

My question is what is the purpose of the '.0' concatenation?

I looked at the greatest_hn function and if any of it's parameters 
contain characters that are not digits then it returns 0.  So by 
concatenating the '.0' I believe you are guaranteeing the first argument 
is going to be treated as 0?  So either the '.0' should not be there or 
the statement can be simplified.  If I'm missing something please 
correct me.

Thanks,
Emily



More information about the postgis-devel mailing list