I'm using postgis 9.1 and rgeo to develop an map application.
One of the features implies that I find all points that are XXX kms from the current point, and are also on the right of the Point.
I tried with the following query:
Environment.where{ st_dwithin(location, factory.point(170.0, 0), 300000 ) }.where('ST_X(location::geometry) > 170')
The corresponding SQL for the query:
[EDITED]
SELECT "environments".* FROM "environments" WHERE (st_dwithin("environments"."location", ST_PointFromText('POINT(170 0)', 4326), 300000)) AND (ST_X(location::geometry) > 170 );
Here I hardcoded the point to be in the 170 longitude.
The problem with this is that I can't match points in the [-170,-180] longitudes.
Is there a way to solve this using only postgis functions?
[EDIT] This is a around the world problem with postgis. In this application I'm allowed only to find points to the right and in a certain range.. I can't find a solution with pure SQL...
Thanks!