# How to find out whether a lat/long position resides within a Polygon?

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:

`````` St_Within(myPointGeo,myPolygonGeo)
``````

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

• Today I also landed up in same situation ; and the description present at this link helped me and is working good postgis.refractions.net/documentation/manual-1.4/… Co-incidentally the examples there and the data type you using is same; so will be simple to replicate Commented Apr 27, 2015 at 14:13
• Also note that the docs suggest to use ST_MakePoint, in general since it's faster - postgis.net/docs/ST_MakePoint.html Commented Mar 13, 2018 at 21:06

``````SELECT ST_Intersects(myPointGeo, myPolygonGeo);
``````SELECT a.id, b.id