0

I'm using Postgis extension in my Postgresql database in Rails app. I have a model Pipe(location: geometry), and it's a linestring. I would like to check if there are any of these pipes withing a certain radius of a given point(lat, lon)? I'm using Leaflet.

How to do this?

ivanacorovic
  • 2,669
  • 4
  • 30
  • 46

1 Answers1

0

Leaflet doesn't have a functionality for making such calculations. It only has the distanceTo method for calculating distance between two points. Since you're working with linestrings that wouldn't work. If you really want to do this on the clientside i would look at a library like GeoScript. That library has a distance method in the geom.Geometry class which works with geometries. There's also other methods like contains, touches, intersects, contains, within etc, which could come in handy at some point.

But i'm thinking you'de be best off doing something like this on the serverside using the PostGIS extension of your DB. PostGIS has ST_Distance and ST_DWithin which also calculates distance between two geometries and much more like contains, covers, crosses, overlaps, touches etc. The entire specification and examples for geometry calculations in PostGIS can be found here.

iH8
  • 27,722
  • 4
  • 67
  • 76
  • I am trying to use this ST_DWITHIN(geometry, geometry, distance). Is there any way to set distance parameter to be in meters? – ivanacorovic Nov 23 '14 at 00:10
  • That's kind of beyond the scope of your current question. It depends on the spatial reference system you're using. Already been anwered in this question: http://stackoverflow.com/questions/8444753/st-dwithin-takes-parameter-as-degree-not-meters-why – iH8 Nov 23 '14 at 08:22