0

I am developing a location based application that stores longitude and latitude coordinates in a string. I then (using PostGIS 2.0) need to use these coordinates and run ST_Intersects on it with the 'geom' column of another table called 'regions' so I can find the name of the region which the lat/long coord is part of. I am trying to use ST_PointFromText, but the ST_intersects query returns 0 rows, which is wrong.

Query:

SELECT regions.name 
FROM regions
WHERE ST_Intersects(ST_PointFromText('POINT(38.53872 -121.7532461)', 4269),  regions.geom);

-(38.53872 -121.7532461) is the long/lat coord. I want to find the name of the region this coord is in. -4269 is the SRID -'regions' is a table containing a geometry column and a name column.

Any tips on why ST_Intersects is not returning the right region name? Or an alternative way to perform the query?

4

Try flipping you axis order, since "-121.7532461" is not a valid latitude. It should be in the range -90 to 90.

If your string is already hard-coded, use ST_FlipCoordinates to reverse the axis order.

SELECT regions.name 
FROM regions
WHERE ST_Intersects(ST_FlipCoordinates(ST_PointFromText('POINT(38.53872 -121.7532461)', 4269)),
                    regions.geom);
  • Thank you so much for your help. This solved the problem. – Dulakshi Oct 27 '13 at 7:17
  • Then please mark the question as answered. – Vince Oct 28 '13 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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