-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnect_Unconnected_Regions.sql
59 lines (56 loc) · 1.74 KB
/
Connect_Unconnected_Regions.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Declare @Input dbo.Region,@Output dbo.Region
Begin Transaction
Insert Into @Input
Select FIPS,0,Border From GerryMatter..[State]
Insert Into @Output
select * From dbo.ConnectRegions(@Input)
Delete From @Input
Update GerryMatter..[State]
Set Border=[Output].Border
From @Output Output
Where [Output].Key1=[State].FIPS
And [State].Border.STGeometryType()<>'Polygon'
Delete From @Output
Commit
Begin Transaction
Insert Into @Input
Select State_FIPS,Congressional_District,Border From GerryMatter..Congressional_District
Insert Into @Output
select * From dbo.ConnectRegions(@Input)
Delete From @Input
Update GerryMatter..Congressional_District
Set Border=[Output].Border
From @Output Output
Where [Output].Key1=Congressional_District.State_FIPS
And [Output].Key2=Congressional_District.Congressional_District
And Congressional_District.Border.STGeometryType()<>'Polygon'
Delete From @Output
Commit
Begin Transaction
Insert Into @Input
Select State_FIPS,County_FIPS,Border From GerryMatter..County
Insert Into @Output
select * From dbo.ConnectRegions(@Input)
Delete From @Input
Update GerryMatter..County
Set Border=[Output].Border
From @Output Output
Where [Output].Key1=County.State_FIPS
And [Output].Key2=County.County_FIPS
And County.Border.STGeometryType()<>'Polygon'
Delete From @Output
Commit
Begin Transaction
Insert Into @Input
Select State_FIPS,State_Precinct_Id,Border From GerryMatter..Voting_District
Insert Into @Output
select * From dbo.ConnectRegions(@Input)
Delete From @Input
Update GerryMatter..Voting_District
Set Border=[Output].Border
From @Output Output
Where [Output].Key1=Voting_District.State_FIPS
And [Output].Key2=Voting_District.State_Precinct_Id
And Voting_District.Border.STGeometryType()<>'Polygon'
Delete From @Output
Commit