Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have routes (linestrings) recorded in the database. I want to create a query which returns the routes that have some commonality with a circle whose center and radius are passed as parameter.

I tried this way:

FROM   routes
WHERE  ST_Touches(geom, (ST_Buffer(ST_GeomFromText('POINT(-12.988542214345332 -38.44563066959381)'), 100, 8))) 

Is it correct?

share|improve this question

No, probably not. I'm going to assume from the coordinates of your point that you are working in longitude/latitude coordinates, but that you want to express your distances in meters. Rather than building a real "circle", recognize that for the purpose of a true/false test you can express the query as a distance calculation.

SELECT routes.*
FROM routes
                 'POINT(-12.988542214345332 -38.44563066959381)'::geography,

Also note that if you don't think you're working well below the equator (-38.4S) you should reverse your coordinates, as the coordinate order in PostGIS is X/Y or lon/lat not Y/X.

share|improve this answer

Your Answer


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.