Created
March 11, 2022 09:29
-
-
Save Erik-H-zz/018caedd849889d3c478d4a7727af094 to your computer and use it in GitHub Desktop.
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
CREATE view [Model].[vw_GeoIntersects] | |
as | |
WITH Coordinates AS ( | |
SELECT | |
ID | |
, Latitude | |
, Longitude | |
, geometry::Point(Longitude, Latitude, 0) AS LatLon | |
FROM Ref.MarpolCoordinates | |
), Intersects AS ( | |
SELECT | |
ID | |
, c.Latitude | |
, c.Longitude | |
, CAST(c.LatLon.STIntersects(a.AreaCoordinates) AS INT) as inArea | |
FROM Coordinates c | |
CROSS JOIN Ref.MarpolAreas a | |
) | |
SELECT CAST(ID AS VARCHAR(50)) AS ID | |
, '' AS AreaCoordinates | |
, 50 AS Size -- required for Power BI visual | |
, i.Latitude | |
, i.Longitude | |
, i.inArea AS InMarpolArea | |
FROM Intersects i | |
UNION ALL | |
SELECT ma.MarpolAreaName | |
, CAST(ma.AreaCoordinates AS varchar(max)) AS AreaCoordinates | |
, 50 AS Size | |
, NULL | |
, NULL | |
, NULL | |
FROM Ref.MarpolAreas ma |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment