Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a system that stores latitude/longitude information of addresses in a PostGIS table. To store Lat/Long in geometry data type I'm using ST_GeometryFromText function.

For example the following function call gets the geometric value against the specified Long/Lat position:

 myPointGeo =  ST_GeometryFromText('POINT(40.758871 -73.985114)');

Similarly, I convert a Polygon into geometric representation as follows:

myPolygonGeo =  ST_GeometryFromText('POLYGON ((40.7566484549725 -73.9878561496734, 40.7556894646734 -73.9853026866913, 40.7545841705587 -73.9860537052154, 40.7548036054111 -73.9881458282471, 40.7559820394514 -73.9887895584106, 40.7566484549725 -73.9878561496734 ))')

I want to find out whether the above lat/long position resides within this Polygon or not. For this I'm using ST_Within function. But though 'myPointGeo' actually resides within the Polygon, ST_Within is returning false. I'm using ST_Within this way:


What am I doing wrong here? Should I use some other function for this purpose?

share|improve this question
Today I also landed up in same situation ; and the description present at this link helped me and is working good… Co-incidentally the examples there and the data type you using is same; so will be simple to replicate – sidd.k Apr 27 '15 at 14:13
up vote 7 down vote accepted

I think ST_Intersects would work better, it returns a true or false on whether or not two geometries intersect. So you'd want to do something like:

SELECT ST_Intersects(myPointGeo, myPolygonGeo);

or you can do:

FROM pointTableName a, polygonTableName b 
WHERE ST_Intersects(a.myPointGeo, b.myPolygonGeo);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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