Percentage of a shape that exist within another shape in Sql Server 2008/2012
A simple scalar function to see how much a shape exists within another shape, as a percentage.
eg. How much does SoHo fit within Manhattan?
CREATE FUNCTION [dbo].[PercentageOfIntersection]
(
@SmallShape GEOGRAPHY,
@LargeShape GEOGRAPHY
)
RETURNS FLOAT
AS
BEGIN
RETURN (@SmallShape
.STIntersection(@LargeShape )
.STArea() /
(CASE
WHEN @SmallShape .STArea() <= 0
THEN 0.0000001
ELSE @SmallShape .STArea()
END)) * 100.00
END
Written by Pure Krome
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Sql
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#