Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. (WITH closest_candidates AS (
  2. SELECT
  3. ent.id,
  4. ent.name,
  5. ent.geom
  6. FROM
  7. geo_data.etablissements ent
  8. WHERE ent.activite_principale = '1071C'
  9. ORDER BY
  10. ent.geom <->
  11. 'SRID=4326;POINT (5.4153978921979125 43.271437384501965)'::geometry
  12. LIMIT 10
  13. )
  14. SELECT id
  15. FROM closest_candidates
  16. ORDER BY
  17. ST_Distance(
  18. geom,
  19. 'SRID=4326;POINT (5.4153978921979125 43.271437384501965)'::geometry
  20. )
  21. LIMIT 1)
  22. UNION ALL
  23. (WITH closest_candidates AS (
  24. SELECT
  25. ent.id,
  26. ent.name,
  27. ent.geom
  28. FROM
  29. geo_data.etablissements ent
  30. WHERE ent.activite_principale = '4711D'
  31. ORDER BY
  32. ent.geom <->
  33. 'SRID=4326;POINT (5.4153978921979125 43.271437384501965)'::geometry
  34. LIMIT 10
  35. )
  36. SELECT id
  37. FROM closest_candidates
  38. ORDER BY
  39. ST_Distance(
  40. geom,
  41. 'SRID=4326;POINT (5.4153978921979125 43.271437384501965)'::geometry
  42. )
  43. LIMIT 1)
  44.  
  45. -- UNION ALL
  46. -- [...] And so on...
  47.  
  48. SELECT DISTINCT ON (a.activite_principale)
  49. a.activite_principale,
  50. a.id
  51. FROM geo_data.etablissements AS a
  52. WHERE a.activite_principale IN ('1071C', '4711D', <3rd>, <4th>, <5th>)
  53. ORDER BY a.activite_principale,
  54. a.geom <-> 'SRID=32632;POINT(363982.8087 5623158.5124)'::geometry
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement