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 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:

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

Is it correct?

share|improve this question
add comment

1 Answer 1

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
WHERE ST_DWithin(
                 routes.geom::geography,
                 'POINT(-12.988542214345332 -38.44563066959381)'::geography,
                 100
                );

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
add comment

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.