Skip to content

Commit

Permalink
Add generic test for geo overlap #5
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianK13 committed Dec 1, 2023
1 parent e6ecfff commit 6530830
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions dbt/tests/generic/expect_point_to_lie_in_area.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% test expect_point_to_lie_in_area(
model,
model_point_column_point_geometry,
model_point_column_area_id,
model_area,
model_area_column_id,
model_area_column_area_geometry,
area_buffer_zone
)
%}
WITH areas AS (
SELECT
{{ model_area_column_id }},
ST_BUFFER({{ model_area_column_area_geometry }}, {{ area_buffer_zone }}) AS area_geometry_with_buffer
FROM {{ model_area }}
),

points AS (
SELECT *
FROM {{ model }}
WHERE {{ model_point_column_point_geometry }} IS NOT NULL
),

join_areas_on_points AS (
SELECT
*
FROM
points
JOIN areas
ON points.{{ model_point_column_area_id }} = areas.{{ model_area_column_id }}
)

SELECT
*
FROM
join_areas_on_points
WHERE
NOT ST_WITHIN({{ model_point_column_point_geometry }}, area_geometry_with_buffer)


{% endtest %}

0 comments on commit 6530830

Please sign in to comment.