For me, the most efficient use of Python scripts in my day to day GIS work is in the management and manipulation of files. Python is very efficient at this sort of task. If you still have to deal with ArcIMS HTML viewer sites that are based on the ESRI template like I occasionally do, you might find this script useful. Many of the configuration options in the viewer rely upon the draw order index of the layers instead of layer ids. If you only have 4 or 5 layers that will not change draw order and you do not anticipate any additional layers, it’s no big deal to count out the layers and modify the configuration file. However, if your 30 layer service is ever-changing with new layers being inserted periodically, the manual approach fast becomes cumbersome. This simple script outputs to the screen a list of all the layers in a .axl document and their corresponding index as well as a complete listing of the layers for use with the noListLayer array. The array can be copied from the output window and pasted into the ArcIMSparam.js file under "var noListLayer = new Array();" and the layers you want listed set to "true." The script can, of course, be modified to output many other order-dependent arrays such as fieldAliasList or hyperLinkLayers, etc. I’m sure the viewer can be re-written to better handle these configuration options and there may be more complete programs to handle this sort of thing, but I’ve found this script to be adequate for the occasional .axl change. ################################################################################ ###getLayerOrder written 8/9/07 by Barry Biediger State of Utah AGRC ### ###This script reads in a .axl file and outputs to the screen: ### Option1 ### - The layer index as used by IMS ### - The name of the layer as used by IMS ### - The name of the dataset ### Option2 ### - A listing of "nolegendlayers" as needed by ArcIMSParam.js ### ###Parameters: ### <full path to .axl> <index and names (y|n)> <nolegendlayers (y|n)> ### ###Example: ### C:\TEMP\myFile.axl n y -this would run the script on myFile without the ### layer names and indices, but with the noLegendLayers array. ################################################################################
import sys
axlPath = sys.argv[1] doListNames = sys.argv[2] doNoLegendLayers = sys.argv[3]
#open .axl and read it into a variable theAXLFile = open(axlPath) AXLText = theAXLFile.read() theAXLFile.close()
#set up initial placeholders LayerIndex = AXLText.find('<LAYER') DatasetIndex = AXLText.find('<DATASET') LayerNameStart = AXLText.find('name',LayerIndex) + 3 DatasetNameStart = DatasetIndex + 8 layerCount = 0 layerNumber = 0
#get layer count while LayerIndex != -1:
LayerIndex = AXLText.find('<LAYER',LayerIndex + 1) layerCount = layerCount + 1
print 'layerCount is:' print layerCount print '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
#set layer number = count so the index of the layer can be decrimented layerNumber = layerCount
#reset LayerIndex LayerIndex = AXLText.find('<LAYER')
#initialize list for noListLayers noLegendList = []
#loop through all layers and find the name and dataset name for each #also populate noListLayer list while LayerIndex != -1: LayerNameStart = AXLText.find('name', LayerIndex) + 6 layerName = AXLText[LayerNameStart:AXLText.find('"',LayerNameStart)] LayerIndex = AXLText.find('<LAYER',LayerIndex + 1)
DatasetNameStart = AXLText.find('name',DatasetIndex) + 6 datasetName = AXLText[DatasetNameStart:AXLText.find('"',DatasetNameStart)] DatasetIndex = AXLText.find('<DATASET', DatasetIndex +1)
if doNoLegendLayers == 'y': noLegendList.append(layerName) layerNumber = layerNumber -1
if doListNames == 'y': print layerNumber print layerName print datasetName print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
#print out noListLayers array if doNoLegendLayers == 'y': noLegendList.reverse() for i in range(0,layerCount): print 'noLegendLayer[' + str(i) + '] = false;//' + noLegendList[i] |