def main(argv=None): xmlDoc = dla.getXmlDoc(xmlFileName) targetName = dla.getTargetName(xmlDoc) success = calculate(xmlFileName, dla.workspace, targetName, False) if success == False: dla.addError("Errors occurred during field calculation") arcpy.SetParameter(SUCCESS, success)
def preview(xmlFileName): global sourceLayer,targetLayer,rowLimit dla.setWorkspace() dla._errCount = 0 xmlDoc = dla.getXmlDoc(xmlFileName) #arcpy.AddMessage("rowLimit = " + str(rowLimit) ) if rowLimit == "" or rowLimit == None: rowLimit = 100 if sourceLayer == "" or sourceLayer == None: sourceLayer = dla.getNodeValue(xmlDoc,"Source") if targetLayer == "" or targetLayer == None: targetLayer = dla.getNodeValue(xmlDoc,"Target") dte = datetime.datetime.now().strftime("%Y%m%d%H%M") targetName = dla.getTargetName(xmlDoc) + dte targetFC = os.path.join(dla.workspace,targetName) res = dlaExtractLayerToGDB.extract(xmlFileName,rowLimit,dla.workspace,sourceLayer,targetFC) if res == True: res = dlaFieldCalculator.calculate(xmlFileName,dla.workspace,targetName,False) if res == True: arcpy.env.addOutputsToMap = True layer = targetName layertmp = targetName + "tmp" if arcpy.Exists(layertmp): arcpy.Delete_management(layertmp) arcpy.MakeFeatureLayer_management(targetFC,layertmp) fieldInfo = dla.getLayerVisibility(layertmp,xmlFileName) arcpy.MakeFeatureLayer_management(targetFC,layer,None,dla.workspace,fieldInfo) # should make only the target fields visible arcpy.SetParameter(_success,layer) else: dla.addError("Failed to Extract data") print("Failed to Extract data") dla.writeFinalMessage("Data Assistant - Preview")
def main(argv = None): xmlDoc = dla.getXmlDoc(xmlFileName) targetName = dla.getTargetName(xmlDoc) success = calculate(xmlFileName,dla.workspace,targetName,False) if success == False: dla.addError("Errors occurred during field calculation") arcpy.SetParameter(SUCCESS, success)
def extract(xmlFileName, rowLimit, workspace, sourceLayer, targetFC): xmlDoc = dla.getXmlDoc(xmlFileName) if workspace == "" or workspace == "#" or workspace == None: dla.workspace = arcpy.env.scratchGDB else: dla.workspace = workspace fields = dla.getFields(xmlFileName) success = True name = '' try: if not arcpy.Exists(dla.workspace): dla.addMessage(dla.workspace + " does not exist, attempting to create") dla.createGeodatabase() if len(fields) > 0: arcpy.SetProgressor("step", "Importing Layer...", 0, 1, 1) if sourceLayer == '' or sourceLayer == '#': source = dla.getNodeValue(xmlDoc, "Datasets/Source") else: source = sourceLayer if targetFC == '' or targetFC == '#': targetName = dla.getTargetName(xmlDoc) else: targetName = targetFC[targetFC.rfind(os.sep) + 1:] sourceName = dla.getSourceName(xmlDoc) arcpy.SetProgressorLabel("Loading " + sourceName + " to " + targetName + "...") #if not arcpy.Exists(sourceLayer): # dla.addError("Layer " + sourceLayer + " does not exist, exiting") # return retVal = exportDataset(xmlDoc, sourceLayer, dla.workspace, targetName, rowLimit) if retVal == False: success = False arcpy.SetProgressorPosition() except: dla.addError("A Fatal Error occurred") dla.showTraceback() success = False finally: arcpy.ResetProgressor() #arcpy.RefreshCatalog(dla.workspace) arcpy.ClearWorkspaceCache_management(dla.workspace) return success
def extract(xmlFileName,rowLimit,workspace,sourceLayer,targetFC): xmlDoc = dla.getXmlDoc(xmlFileName) if workspace == "" or workspace == "#" or workspace == None: dla.workspace = arcpy.env.scratchGDB else: dla.workspace = workspace fields = dla.getFields(xmlFileName) success = True name = '' try: if not arcpy.Exists(dla.workspace): dla.addMessage(dla.workspace + " does not exist, attempting to create") dla.createGeodatabase() if len(fields) > 0: arcpy.SetProgressor("step", "Importing Layer...",0,1,1) if sourceLayer == '' or sourceLayer == '#': source = dla.getNodeValue(xmlDoc,"Datasets/Source") else: source = sourceLayer if targetFC == '' or targetFC == '#': targetName = dla.getTargetName(xmlDoc) else: targetName = targetFC[targetFC.rfind(os.sep)+1:] sourceName = dla.getSourceName(xmlDoc) arcpy.SetProgressorLabel("Loading " + sourceName + " to " + targetName +"...") #if not arcpy.Exists(sourceLayer): # dla.addError("Layer " + sourceLayer + " does not exist, exiting") # return retVal = exportDataset(xmlDoc,sourceLayer,dla.workspace,targetName,rowLimit) if retVal == False: success = False arcpy.SetProgressorPosition() except: dla.addError("A Fatal Error occurred") dla.showTraceback() success = False finally: arcpy.ResetProgressor() #arcpy.RefreshCatalog(dla.workspace) arcpy.ClearWorkspaceCache_management(dla.workspace) return success
def preview(xmlFileName): global sourceLayer, targetLayer, rowLimit dla.setWorkspace() dla._errorCount = 0 xmlDoc = dla.getXmlDoc(xmlFileName) if rowLimit == "" or rowLimit == None: rowLimit = 100 if sourceLayer == "" or sourceLayer == None: sourceLayer = dla.getNodeValue(xmlDoc, "Source") if targetLayer == "" or targetLayer == None: targetLayer = dla.getNodeValue(xmlDoc, "Target") dte = datetime.datetime.now().strftime("%Y%m%d%H%M") targetName = dla.getTargetName(xmlDoc) + dte targetFC = os.path.join(dla.workspace, targetName) res = dlaExtractLayerToGDB.extract(xmlFileName, rowLimit, dla.workspace, sourceLayer, targetFC) if res == True: res = dlaFieldCalculator.calculate(xmlFileName, dla.workspace, targetName, False) if res == True: arcpy.env.addOutputsToMap = True layer = targetName layertmp = targetName + "tmp" if arcpy.Exists(layertmp): arcpy.Delete_management(layertmp) arcpy.MakeFeatureLayer_management(targetFC, layertmp) fieldInfo = dla.getLayerVisibility(layertmp, xmlFileName) arcpy.MakeFeatureLayer_management(targetFC, layer, None, dla.workspace, fieldInfo) # should make only the target fields visible arcpy.SetParameter(_success, layer) else: dla.addError("Failed to Extract data") print("Failed to Extract data") dla.writeFinalMessage("Data Assistant - Preview")
def publish(xmlFileNames): # function called from main or from another script, performs the data update processing global sourceLayer, targetLayer, _success dla._errorCount = 0 arcpy.SetProgressor("default", "Data Assistant") arcpy.SetProgressorLabel("Data Assistant") xmlFiles = xmlFileNames.split(";") for xmlFile in xmlFiles: # multi value parameter, loop for each file dla.addMessage("Configuration file: " + xmlFile) xmlDoc = dla.getXmlDoc(xmlFile) # parse the xml document if xmlDoc == None: return svceS = False svceT = False if sourceLayer == "" or sourceLayer == None: sourceLayer = dla.getNodeValue(xmlDoc, "Source") svceS = dla.checkLayerIsService(sourceLayer) if targetLayer == "" or targetLayer == None: targetLayer = dla.getNodeValue(xmlDoc, "Target") svceT = dla.checkLayerIsService(targetLayer) dla.addMessage(targetLayer) ## Added May2016. warn user if capabilities are not correct, exit if not a valid layer if not dla.checkServiceCapabilities(sourceLayer, True): return False if not dla.checkServiceCapabilities(targetLayer, True): return False if svceS == True or svceT == True: token = dla.getSigninToken( ) # when signed in get the token and use this. Will be requested many times during the publish if token == None: dla.addError( "User must be signed in for this tool to work with services" ) return expr = getWhereClause(xmlDoc) if useReplaceSettings == True and (expr == '' or expr == None): dla.addError( "There must be an expression for replacing by field value, current value = " + str(expr)) return False dla.setWorkspace() targetName = dla.getTargetName(xmlDoc) res = dlaExtractLayerToGDB.extract(xmlFile, None, dla.workspace, sourceLayer, targetName) if res != True: table = dla.getTempTable(targetName) msg = "Unable to export data, there is a lock on existing datasets or another unknown error" if arcpy.TestSchemaLock(table) != True: msg = "Unable to export data, there is a lock on the intermediate feature class: " + table dla.addError(msg) print(msg) return else: res = dlaFieldCalculator.calculate(xmlFile, dla.workspace, targetName, False) if res == True: dlaTable = dla.getTempTable(targetName) res = doPublish(xmlDoc, dlaTable, targetLayer) arcpy.ResetProgressor() sourceLayer = None # set source and target back to None for multiple file processing targetLayer = None if res == False: err = "Data Assistant Update Failed, see messages for details" dla.addError(err) print(err)
def publish(xmlFileNames): # function called from main or from another script, performs the data update processing global sourceLayer,targetLayer,_success dla._errorCount = 0 arcpy.SetProgressor("default","Data Assistant") arcpy.SetProgressorLabel("Data Assistant") xmlFiles = xmlFileNames.split(";") for xmlFile in xmlFiles: # multi value parameter, loop for each file dla.addMessage("Configuration file: " + xmlFile) xmlDoc = dla.getXmlDoc(xmlFile) # parse the xml document if xmlDoc == None: return svceS = False svceT = False if sourceLayer == "" or sourceLayer == None: sourceLayer = dla.getNodeValue(xmlDoc,"Source") svceS = dla.checkLayerIsService(sourceLayer) if targetLayer == "" or targetLayer == None: targetLayer = dla.getNodeValue(xmlDoc,"Target") svceT = dla.checkLayerIsService(targetLayer) dla.addMessage(targetLayer) ## Added May2016. warn user if capabilities are not correct, exit if not a valid layer if not dla.checkServiceCapabilities(sourceLayer,True): return False if not dla.checkServiceCapabilities(targetLayer,True): return False if svceS == True or svceT == True: token = dla.getSigninToken() # when signed in get the token and use this. Will be requested many times during the publish if token == None: dla.addError("User must be signed in for this tool to work with services") return expr = getWhereClause(xmlDoc) if useReplaceSettings == True and (expr == '' or expr == None): dla.addError("There must be an expression for replacing by field value, current value = " + str(expr)) return False dla.setWorkspace() targetName = dla.getTargetName(xmlDoc) res = dlaExtractLayerToGDB.extract(xmlFile,None,dla.workspace,sourceLayer,targetName) if res != True: table = dla.getTempTable(targetName) msg = "Unable to export data, there is a lock on existing datasets or another unknown error" if arcpy.TestSchemaLock(table) != True: msg = "Unable to export data, there is a lock on the intermediate feature class: " + table dla.addError(msg) print(msg) return else: res = dlaFieldCalculator.calculate(xmlFile,dla.workspace,targetName,False) if res == True: dlaTable = dla.getTempTable(targetName) res = doPublish(xmlDoc,dlaTable,targetLayer) arcpy.ResetProgressor() sourceLayer = None # set source and target back to None for multiple file processing targetLayer = None if res == False: err = "Data Assistant Update Failed, see messages for details" dla.addError(err) print(err)