[GIS] Using PostGIS with Rails

postgis

I'm new to postGIS, and am looking to use a spatial database with my Rails app (specifically, to retrieve points from the database that are within the bounding box of a Google Maps viewport). I posted a question on Stack Overflow with a few more details ( https://stackoverflow.com/questions/3555840/constucting-a-postgis-query-with-rails ), before coming across this site. I was following the tutorial at http://railsonpostgresql.com/2009/11/05/intro-to-postgis, but my implementation doesn't really seem to work – when zoomed in, the points don't appear as expected (but some appear when zoomed further out, although not those near the international date line). I'm using the spatial_adapter and GeoRuby gems at the moment – are there any good tutorials out there on how to begin integrating postGIS with Rails? From what I've read, it seems like using the geography type would be a good start for my project, but unfortunately I don't believe GeoRuby supports it. Any help/suggestions would be greatly appreciated!

Best Answer

The answer on Stackoverflow echos my thoughts: first, determine if the issue is in the google maps implementation or with the database results. I'd try installing QGIS, and point it at your PostGIS database -- if all the data shows up there fine, and zooming works as expected, the data is correct in the database.

From your example query, here's a quick map of the bounding box: bbox example

That is consistent with the parameters you're sending, so try another one that fails, check the logs and try the query directly against the database to see if its sending the results you want. Step backward from there till you've isolated the component that's failed. Hope that helps!