1

I'm trying to make a spatial query, but I think something is wrong with it:

I have two tables, places (point) and cities (polygon)

When I try to get the points within 500m to one point, there is no problem with st_dwithin:

select * from places 
where st_dwithin(geo, (select geo from places where id=2), 500)

But what If I want to get the polygons within 500m of one polygon, and then, all the points inside this selection?

I'm trying to do the first part: Polygons within 500m of my given polygon:

select * from munisp 
where st_dwithin(geo, (select geo from munisp where id=275), 100)

And I get the error:

BOOM! Could not generate outside point!

The 'geo' column are Geography data types, in both tables, Polygon, 4326 in one, and Point, 4326 in the other.

Am I missing something? Any idea about how could I get the points inside this, and neighbour polygons?

The point table was geography since the beginning, but the polygons one was cast from geometry (created geography column 4326, and filled with update polytable set geo=the_geom::geography)

Could that be the problem?

Having tried the query:

SELECT p.* FROM munisp m, munisp p WHERE m.id=275 AND ST_DWithin(m.geo, p.geo, 100);

I get the same error.

BOOM! Could not generate outside point!

And when I try:

SELECT p.* FROM munisp m, munisp p WHERE m.id=275 AND st_touches(m.geom, p.geom);

*Note the 'geom' column, not 'geo'. I get 0 rows. What means that no polygon is touching #275, so what is false, and it should return multiple polygons.

Could it be due to an error in the data?

closed as off-topic by Midavalo May 22 '17 at 21:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – Midavalo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Are you sure they are not geometry types? – Russell at ISC Apr 21 '15 at 12:55
  • That is what I was thinking. The point table was geography since the beginning, but the polygon one have been casted from geometry (created geography column 4326, and filled with update polytable set geo=the_geom::geography) could that be the problem? – Pablo Pardo Apr 21 '15 at 14:09
  • Ideally, questions should stand on their own, without comment. Please edit the extra information, provided in comments, into the body of the question. – Martin F Apr 21 '15 at 15:18
  • Does it work if you flatten the query? SELECT p.* FROM munisp m, munisp p WHERE m.id=275 AND ST_DWithin(m.geo, p.geo, 100); – Mike T Apr 22 '15 at 3:33
  • It seems that there was a problem with the data. I've loaded another dataset, and the spatial functions runs ok both in geography and geometry types. – Pablo Pardo Apr 22 '15 at 17:17

Browse other questions tagged or ask your own question.