Last active
July 14, 2017 13:43
-
-
Save seguelador/a9c0da75d93ddd4a9320bfb3f3bc83b9 to your computer and use it in GitHub Desktop.
All points inside a circle POSTGIS Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Crea un circulo en base a un punto de 2km | |
ActiveRecord::Base.connection.execute("SELECT ST_Buffer(ST_GeomFromText('POINT(100 90)'), 2000, 'quad_segs=3')") | |
########################### | |
Trae todos los customers ordenados segun distancias, tomando la distancia mas cercana primero respecto al punto | |
ActiveRecord::Base.connection.execute("SELECT * FROM customers ORDER BY customers.location <-> 'POINT(-70 -33)'") | |
########################### | |
Obtiene todos los customers que se encuentren dentro de un rango determinado (2000) | |
ActiveRecord::Base.connection.execute("SELECT * FROM customers WHERE ST_DistanceSphere(customers.location, ST_MakePoint(-70.70833273338121, -33.429525177615815)) <= 2000") | |
Customer.where("ST_DistanceSphere(customers.location, ST_MakePoint(-70.70833273338121, -33.429525177615815)) <= 2000"). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment