-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_AOI.py
178 lines (144 loc) · 7.11 KB
/
create_AOI.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#-------------------------------------------------------------------------------
# Name: Create AOI in Arcgis Pro 3D Map
# Purpose: While Running in ArcGIS Pro, takes the laterals selected and
# filters the layers in scene by passing in a definition query
#
# Author: bkennady
#
# Created: 05/04/2016
#-------------------------------------------------------------------------------
import arcpy
import sys
arcpy.env.overwriteOutput
# Get Current map and maps
aprx = arcpy.mp.ArcGISProject("CURRENT")
ThreeDMap = aprx.listMaps("3D Map")[0]
UTLMap = aprx.listMaps("UT Lands Map")[0]
# layers from UT Lands Map
UTMLayerLatActive = UTLMap.listLayers("Oil & Gas Lateral")[0]
UTMLayerLatInac = UTLMap.listLayers("Oil & Gas Lateral (Inactive)")[0]
# 3D layers from 3DMap
Lateral3DLyr = ThreeDMap.listLayers("Oil & Gas Lateral (3D)")[0]
LateralTwoDLyr = ThreeDMap.listLayers("Oil & Gas Lateral")[0]
WellPerfsLyr = ThreeDMap.listLayers("Well Perfs (3D)")[0]
LeaseAllDepLyr = ThreeDMap.listLayers("Oil & Gas Lease (All Depths)")[0]
LeaseShallowLyr = ThreeDMap.listLayers("Oil & Gas Lease (Shallow)")[0]
LeaseIntLyr = ThreeDMap.listLayers("Oil & Gas Lease (Intermediate)")[0]
LeaseDeepLyr = ThreeDMap.listLayers("Oil & Gas Lease (Deep)")[0]
# 2D layers from 3D Map
BHLLyr = ThreeDMap.listLayers("Bottom Hole Location")[0]
WellLyr = ThreeDMap.listLayers("Oil & Gas Well")[0]
LateralLyr = ThreeDMap.listLayers("Oil & Gas Lateral")[0]
# Add multipatch Featureclass - Make Feature Layer
Multipatch_fc = r"foo\bar.sde\ULGISv.DBO.MN_LeaseParcel3D"
Multipatch_fl = "MultipatchFL"
arcpy.MakeFeatureLayer_management(Multipatch_fc, Multipatch_fl)
# Unselect any 3D laterals (If there are any, this causes errors when
# selecting in the 3D Map
arcpy.SelectLayerByAttribute_management(Lateral3DLyr, "CLEAR_SELECTION")
# Set up Lateral Query String
LatQueryString = ""
# Get lateral selection set variables
SelecLatCount = 0
SelSetLatAct = UTMLayerLatActive.getSelectionSet()
SelSetLatInac = UTMLayerLatInac.getSelectionSet()
SelSetLatTwoD = LateralTwoDLyr.getSelectionSet()
if str(SelSetLatAct) != "None" or str(SelSetLatInac) != "None":
LatQueryString = "BHLID IN ("
try:
if len(SelSetLatAct):
rowsLatActive = arcpy.SearchCursor(UTMLayerLatActive)
for row in rowsLatActive:
SelecLatCount += 1
LatQueryString = LatQueryString + str(row.getValue("ULGISv.DBO.MN_Lateral.BHLID")) + ", "
del rowsLatActive
except:
arcpy.AddMessage(arcpy.GetMessages())
try:
if len(SelSetLatInac):
rowsLatInac = arcpy.SearchCursor(UTMLayerLatInac)
for row in rowsLatInac:
SelecLatCount += 1
LatQueryString = LatQueryString + str(row.getValue("ULGISv.DBO.MN_Lateral.BHLID")) + ", "
del rowsLatInac
except:
arcpy.AddMessage(arcpy.GetMessages())
LatQueryString = LatQueryString[:-2] + ")"
arcpy.AddMessage("Lat Query string is: " + str(LatQueryString))
elif str(SelSetLatTwoD) != "None":
LatQueryString = "BHLID IN ("
rowsLat = arcpy.SearchCursor(LateralTwoDLyr)
for row in rowsLat:
SelecLatCount += 1
LatQueryString = LatQueryString + str(row.getValue("ULGISv.DBO.MN_Lateral.BHLID")) + ", "
del rowsLat
LatQueryString = LatQueryString[:-2] + ")"
arcpy.AddMessage("Lat Query string is: " + str(LatQueryString))
# Set Layer Definition Query and BHL Definition Query
Lateral3DLyr.definitionQuery = LatQueryString
WellPerfsLyr.definitionQuery = LatQueryString
# ---Handle situations of no 3D laterals selected or more than 50 selected------
arcpy.SelectLayerByAttribute_management(Lateral3DLyr, "NEW_SELECTION", LatQueryString )
SelLatCount = arcpy.GetCount_management(Lateral3DLyr)
LatCountNum = int(SelLatCount.getOutput(0))
arcpy.AddMessage("Number of laterals selected" + str(SelLatCount.getOutput(0)))
ThreeDMap.clearSelection()
# Handle if to many laterals are selected
if LatCountNum > 50:
arcpy.AddMessage("there are to many laterals selected")
ThreeDMap.clearSelection()
UTLMap.clearSelection()
sys.exit
# Handle if no laterals are selected
elif SelecLatCount == 0:
arcpy.AddMessage("No laterals were selected")
ThreeDMap.clearSelection()
UTLMap.clearSelection()
sys.exit
else:
# -- Filter feature classes based on selection------------------------------
# Get Legal Key Set for leases intersecting selected laterals
# Set up query string variables
LeaseAllQS = "ULDB.GIS.ActiveOGLeaseParcel_View.TopDepth = 0 And ULDB.GIS.ActiveOGLeaseParcel_View.BottomDepth = 99999"
LeaseShallowQS = "ULDB.GIS.ActiveOGLeaseParcel_View.TopDepth = 0 And ULDB.GIS.ActiveOGLeaseParcel_View.BottomDepth <> 99999"
LeaseIntQS = "ULDB.GIS.ActiveOGLeaseParcel_View.TopDepth <> 0 And ULDB.GIS.ActiveOGLeaseParcel_View.BottomDepth <> 99999"
LeaseDeepQS = "ULDB.GIS.ActiveOGLeaseParcel_View.TopDepth <> 0 And ULDB.GIS.ActiveOGLeaseParcel_View.BottomDepth = 99999"
# Select laterals then select 3D leases based on selected laterals
arcpy.SelectLayerByAttribute_management(Lateral3DLyr, "NEW_SELECTION", LatQueryString)
arcpy.SelectLayerByLocation_management(Multipatch_fl,"INTERSECT_3D", Lateral3DLyr)
# Get selected leases Legal Keys, create definition query from list
LegalKeyList = []
MultipatchCursor = arcpy.SearchCursor(Multipatch_fl)
for row in MultipatchCursor:
LegalKeyList.append(str(row.getValue("LegalKey")))
if len(LegalKeyList):
LegalKeyQueryString = "ulgisv.SDEDBA.Legal_Layer.LEGAL_KEY IN ("
for x in LegalKeyList:
LegalKeyQueryString = LegalKeyQueryString + str(x) + ", "
LegalKeyQueryString = LegalKeyQueryString[:-2] + ")"
# Set definition queries to each Lease Layer
LeaseAllDepLyr.definitionQuery = LegalKeyQueryString + " And " + LeaseAllQS
LeaseShallowLyr.definitionQuery = LegalKeyQueryString + " And " + LeaseShallowQS
LeaseIntLyr.definitionQuery = LegalKeyQueryString + " And " + LeaseIntQS
LeaseDeepLyr.definitionQuery = LegalKeyQueryString + " And " + LeaseDeepQS
else:
arcpy.AddMessage("Major Error: No Legal keys found")
# -- Filter 2D leases on 3D map based on selection---------------------
# Get API's from selected laterals
APIList = []
Lateral3DCursor = arcpy.SearchCursor(Lateral3DLyr, LatQueryString)
for row in Lateral3DCursor:
APIList.append(row.getValue("API"))
# Set up definition query string for 2D layers in 3D map
APIQueryString = "ULDB.GIS.Wellbore_View.API IN ("
for API in APIList:
APIQueryString += str(API) + ", "
APIQueryString = APIQueryString[:-2] + ")" # + " And " + TwoDQueryString
# Apply definition queries to 2D layers in 3D Map
WellLyr.definitionQuery = APIQueryString
LateralLyr.definitionQuery = LatQueryString
BHLLyr.definitionQuery = LatQueryString
# Clear Selections
ThreeDMap.clearSelection()
UTLMap.clearSelection()
del aprx