-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_PPident.py
More file actions
61 lines (50 loc) · 2.23 KB
/
plot_PPident.py
File metadata and controls
61 lines (50 loc) · 2.23 KB
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
# Plot pilot point identifiabilities in arc map;
# from shapefile generated by identpar.py
# requires arcpy
__author__ = 'aleaf'
import os
import arcpy
import shutil
# path to identpar shapefile (also where output will be written)
path = os.path.join('D:\\', 'ATLData', 'BadRiver', 'Calibration_runs', 'Opt2b', 'GIS')
base_mxd = "BadRiver_calibration.mxd" # Base ArcMap MXD file to add the points to
ident_shp = 'Pilot_point_idents.shp' # shapefile generated by identpar.py
symbology = 'Pilot_point_idents.lyr' # pre-made symbology layer for plotting the points
def add_feature(df, filename, symbology, TOCposition):
# make a layer
newlayer = arcpy.mapping.Layer(filename)
print 'adding {0}'.format(filename)
# apply the symbology
arcpy.ApplySymbologyFromLayer_management(newlayer, os.path.join(os.getcwd(), symbology))
# add new layer to current dataframe, at the top of the table of contents
arcpy.mapping.AddLayer(df, newlayer, "TOP")
print 'set the workspace location...'
symbology = os.path.join(os.getcwd(), symbology)
shutil.copyfile(base_mxd, os.path.join(path, base_mxd))
os.chdir(path)
arcpy.env.workspace = os.getcwd()
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")
print 'open {0}'.format(base_mxd)
mxd = arcpy.mapping.MapDocument(base_mxd)
df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
arcpy.MakeFeatureLayer_management(ident_shp, "All_layers")
#newlayer = arcpy.mapping.Layer(ident_shp)
for dir in ['kz','kh']:
for layer in [4, 3, 1]:
# select pilot points for current layer and direction
thequery = """ "layer" = {0} AND "dir" = '{1}' """.format(layer, dir)
selection = arcpy.SelectLayerByAttribute_management("All_layers", "NEW_SELECTION", thequery)
# make another layer with this subset
layername = "Layer{0}_{1}_ident.shp".format(layer, dir)
arcpy.CopyFeatures_management(selection, layername)
# add to MXD
add_feature(df, layername, symbology, "TOP")
# turn all layers off
for lyr in arcpy.mapping.ListLayers(mxd):
lyr.visible=False
print 'saving as {0}'.format('{0}.mxd'.format(ident_shp[:-4]))
mxd.saveACopy('{0}.mxd'.format(ident_shp[:-4])) # saves new mxd using the specifed root name
del mxd
os.remove(base_mxd)
print "Done!"