sql server - set based approach to remove contained points -


i have data:

if object_id('tempdb..#temp') not null     drop table #temp create table #temp     (       id int identity(1, 1) ,       x float not null ,       y float not null     )  insert #temp (x, y) values (0, 0) insert #temp (x, y) values (0, 1) insert #temp (x, y) values (0, 2) insert #temp (x, y) values (0.5, 1) insert #temp (x, y) values (1, 1) insert #temp (x, y) values (1, 2) insert #temp (x, y) values (1.5, 0.5) insert #temp (x, y) values (2, 0) insert #temp (x, y) values (2, 1) 

i remove points contained within other points, such as:

(0, 1) (1, 1) (1.5, 0.5) 

to obtain outer points define outer polygon consisting of vertical , horizontal lines without redundancies (e.g. (0, 1) redundant point). can achieved set based tsql approach in sql server 2014?

ps:

a scatter plot of data follows:

enter image description here

i remove encircled points. ultimately, after outer border (drawn red lines). hope makes clearer.

i believe might work. seems deliver on test data. bit rough. of select min , select max perhaps calculated in advance if real data large.

select *  -- uncomment delete desired points -- delete #temp #temp t  (     -- internal points     (             ( x > (select min(x) #temp) , x < (select max(x) #temp) )         , ( y > (select min(y) #temp) , y < (select max(y) #temp) )     )     -- exceptions (points nothing strictly outside them) [don't want lose (1,1)]     , exists (select * #temp x > t.x , y > t.y) ) or     -- redundant edge points [(0,1) included "exception"] (     ( (t.x = (select min(x) #temp) or t.x = (select max(x) #temp))          , exists (select * #temp x = t.x , y > t.y)          , exists (select * #temp x = t.x , y < t.y)  )     or     ( (t.y = (select min(y) #temp) or t.y = (select max(y) #temp))          , exists (select * #temp y = t.y , x > t.x)          , exists (select * #temp y = t.y , x < t.x)  ) ) 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -