I wrote Spatial Query https://github.com/netshade/spatial_query to do just this.
Alternatively, you could check out http://geoscript.org/index.html , which is likely better supported than Spatial Query is. If you decide to check out SQ though, I'd be flattered to hear if it worked for you.