I have this data:
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
DROP TABLE #temp
CREATE TABLE #temp
(
Id INT IDENTITY(1, 1) ,
X FLOAT NOT NULL ,
Y FLOAT NOT NULL
)
INSERT INTO #temp (X, Y) VALUES (0, 0)
INSERT INTO #temp (X, Y) VALUES (0, 1)
INSERT INTO #temp (X, Y) VALUES (0, 2)
INSERT INTO #temp (X, Y) VALUES (0.5, 1)
INSERT INTO #temp (X, Y) VALUES (1, 1)
INSERT INTO #temp (X, Y) VALUES (1, 2)
INSERT INTO #temp (X, Y) VALUES (1.5, 0.5)
INSERT INTO #temp (X, Y) VALUES (2, 0)
INSERT INTO #temp (X, Y) VALUES (2, 1)
I would like to remove points that are contained within other points, such as:
(0, 1)
(1, 1)
(1.5, 0.5)
to obtain the outer most points that define the outer polygon consisting of only vertical and horizontal lines without redundancies (e.g. (0, 1) is a redundant point). Can this be achieved with a set based TSQL approach in SQL Server 2014?
PS:
A scatter plot of the data is as follows:
I would like to remove the encircled points. Ultimately, I am after the outer border (drawn as red lines). Hope this makes it clearer.