1

I have two columns latitude and longitude. I am trying to create boundaries such that only points within the boundary is returned. For example i have this static lat/long (40.6681, -73.9806).

There are latitude/longitude coordinates in my database which are not within that static coordinate, how do I only select those coordinates within 40.6681, -73.9806? Here is my query:

select houses from housing where borough = 'BROOKLYN' and latitude + longitude = st_within(40.6681, -73.9806);

The error message I see is:

Hint: No function matches the given name and argument types. You might need to add explicit type casts. Can someone guide me in the right direction?

  • probably just a typo - you might want to check the longitude value - this needs to be around -74 for NY – Steven Kay Dec 3 '16 at 21:41
  • Well i am trying to use park slope not the entire borough of brooklyn. – Micheal C. Dec 3 '16 at 21:49
  • 1
    What Steven Kay is telling you is that if you want to be in the western hemisphere, your longitude should be is negative. 73.9806 is 73.9806 East. 73.9806W will be -73.9806 – BradHards Dec 3 '16 at 21:53
4

You are not using the function properly. ST_WITHIN() takes two arguments both type geom.

For example:

ST_Within(geometry A, geometry B);

will return true if geometry A is completely inside geometry B.

You are going to want to try something like this:

select houses from housing where borough = 'BROOKLYN'
AND ST_WITHIN(ST_MakePoint(longitude, latitude), YOUR_BOUNDARY_GEOM);

see postgis docs

  • Hey man, thanks for the response. So basically I can't have a static latlng, i need to turn 40.6681, 73.9806 into a geom correct? – Micheal C. Dec 3 '16 at 21:45
  • Yes, you will have to convert it to a geom. Your boundary also need to be a geom. – Owen J Lamb Dec 3 '16 at 21:51
  • 2
    That last point is critical, and it can't be a point (ST_Within for two points is never true). The boundary should be describing the extent of the are (e.g. borough) you are interested in, and the border won't match. – BradHards Dec 3 '16 at 22:51

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.