Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 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:

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

Your Answer

 
discard

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.