Advertisement
brunohaick

sag_sql

Apr 12th, 2024 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PostgreSQL 0.56 KB | Source Code | 0 0
  1. INSERT INTO alerts_has_geo_municipios (id_alert, id_geo, area, geom)
  2. (
  3. WITH intersected AS (
  4.     SELECT
  5.         a.id AS alert_id,
  6.         b.id AS geo_mun_id,
  7.         ST_Intersection(a.geom, b.geom) AS intersection_geom
  8.     FROM
  9.         alerts a
  10.         INNER JOIN geo_municipios b ON ST_Intersects(a.geom, b.geom)
  11. )
  12. SELECT
  13.     alert_id,
  14.     geo_mun_id,
  15.     CASE
  16.         WHEN ST_Area(intersected.intersection_geom::geography) > 0
  17.         THEN ST_Area(intersected.intersection_geom::geography) / 100
  18.     ELSE 0
  19.     END AS area,
  20.     intersection_geom
  21. FROM
  22.     intersected
  23. )
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement