[GIS] How to run ST_Intersects on a geometry from text and an existing table

postgis-2.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?

Best Answer

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);
Related Question