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?

  • 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.