Last active
September 28, 2015 07:26
-
-
Save bradbrowne/74e6a01ab95519342ea3 to your computer and use it in GitHub Desktop.
Nearest Line to Polygon
This file contains hidden or 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
with distance_cte AS | |
( | |
SELECT | |
pv.PFI AS pr_view_pfi, | |
tr.PFI AS tr_pfi, | |
pv.SP_GEOMETRY.STDistance(tr.SP_GEOMETRY) AS distance, | |
RANK() OVER (PARTITION BY pv.pfi ORDER BY pv.SP_GEOMETRY.STDistance(tr.SP_GEOMETRY)) AS rank_distance | |
FROM Flux.vmprop.PROPERTY_VIEW AS pv, Flux.vmtrans.TR_ROAD AS tr | |
--WHERE pv.pfi = 173589345 | |
) | |
, unique_cte AS | |
( | |
select | |
pr_view_pfi, | |
tr_pfi, | |
distance, | |
RANK() OVER (PARTITION BY pr_view_pfi ORDER BY tr_pfi desc) AS rank_pfi | |
from distance_cte | |
where rank_distance = 1 | |
) | |
SELECT | |
pr_view_pfi, | |
tr_pfi, | |
distance | |
FROM unique_cte | |
WHERE rank_pfi = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment