Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there a way to do reverse geocoding with PostGIS? There's a lot of information on the Web but I found it very confusing...

I have imported osm data into my own Postgres with PostGIS database. Now I want to make geocoding and reverse geocoding with my database. I don't know if there are some Stored Procedures, or a project somewhere that takes care of my issue.

The next step that I want to do is make a webservice that can handle this kind of requests, but that is another question.

Thanks in advance.

share|improve this question
There are a few results when you search on this site for reverse geocoding. One answer that stands out is this one about services that provide it. –  dassouki Aug 11 '11 at 17:06
Your question is a bit vague. Is there a particular problem you're having? Or do you need help with the general approach to reverse geocoding? –  Sean Aug 11 '11 at 19:00
Thanks. I'll edit it now, to make it more specific. –  Joaquín M Aug 12 '11 at 15:28
I've already tried using Nominatim, but I had issues using "gazetteer" output. It throws a "Segmentation fault" each time I import the osm data. –  Joaquín M Aug 12 '11 at 19:14
add comment

2 Answers

up vote 5 down vote accepted

Finaly, I understand the way to do geocode and reverse geocode with my PostGIS database. I made an stored procedure that finds geometry types that are near a point. This stored procedure uses the distance function to get the nearest points. After that I've created a REST api that calls this stored procedure to resolve the reverse geocoding requests.

Correct me if I'm wrong, but I've understand that Nominatim project creates a webservice api for databases that have been imported from OSM. So you don't have to create any stored procedure for reverse geocoding and geocoding. Also you don't have to make any webservice to resolve the requests through the web.

Hope this helps someone.

share|improve this answer
Can we see the procedure? –  canisrufus Aug 24 '11 at 19:10
Of course: CREATE OR REPLACE FUNCTION reverse_geocode(lat double precision, lon double precision) RETURNS text AS $BODY$ declare point geometry; rec record; geocode text; begin point := geomfromtext('POINT('||lat||' '||lon||')', 4326); select name, distance(way, point) as dist into rec from mapserverdb_point order by dist asc limit 1; geocode := rec.name; return geocode; end; $BODY$ LANGUAGE plpgsql; –  Joaquín M Sep 9 '11 at 20:55
add comment

PostGIS 2.0 tiger geocoder has a reverse geocoder utilizing Tiger data. The geocoder will install fine on PostGIS 1.5 8.4+ or higher.

If you are in US, might be the easiest to use since it's all packaged as plpgsql functions.

http://www.postgis.org/documentation/manual-svn/Extras.html#Tiger_Geocoder http://www.postgis.org/documentation/manual-svn/Reverse_Geocode.html

share|improve this answer
Thanks. I didn't need US information for reverse geocode. Now I have understand the way reverse geocode works with PostGIS databases. Thanks a lot. –  Joaquín M Aug 24 '11 at 17:35
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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