Пример #1
0
def exportDataset(xmlDoc, sourceLayer, workspace, targetName, rowLimit):
    result = True
    xmlFields = xmlDoc.getElementsByTagName("Field")
    dla.addMessage("Exporting Layer from " + sourceLayer)
    whereClause = ""
    if rowLimit != None:
        # try:
        whereClause = getObjectIdWhereClause(sourceLayer, rowLimit)
        # except:
        #    dla.addMessage("Unable to obtain where clause to Preview " + sourceLayer + ", continuing with all records")

    if whereClause != "" and whereClause != " ":
        # dla.addMessage("rowLimit " + str(rowLimit))
        dla.addMessage("Where " + str(whereClause))
    sourceName = dla.getSourceName(xmlDoc)
    viewName = sourceName + "_View"
    dla.addMessage(viewName)

    targetRef = getSpatialReference(xmlDoc, "Target")
    # sourceRef = getSpatialReference(xmlDoc,"Source")

    if targetRef != "":

        arcpy.env.workspace = workspace
        view = dla.makeFeatureView(dla.workspace, sourceLayer, viewName, whereClause, xmlFields)
        dla.addMessage("View Created")
        srcCount = arcpy.GetCount_management(view).getOutput(0)
        dla.addMessage(str(srcCount) + " source rows")
        if srcCount == 0:
            result = False
            dla.addError("Failed to extract " + sourceName + ", Nothing to export")
        else:
            arcpy.env.preserveGlobalIds = False  # need to run this way until support added for GlobalIDs
            # dla.addMessage("names: " + sourceName + "|" + targetName)
            arcpy.env.overwriteOutput = True
            try:
                arcpy.CreateFeatureclass_management(
                    workspace, targetName, template=sourceLayer, spatial_reference=targetRef
                )
            except:
                arcpy.AddError(
                    "Unable to create intermediate feature class, exiting: " + workspace + os.sep + targetName
                )
                return False
            fc = workspace + os.sep + targetName
            arcpy.Append_management(view, fc, schema_type="NO_TEST")
            dla.addMessage(arcpy.GetMessages(2))  # only serious errors
            count = arcpy.GetCount_management(fc).getOutput(0)
            dla.addMessage(str(count) + " source rows exported to " + targetName)
            if str(count) == "0":
                result = False
                dla.addError(
                    "Failed to load to "
                    + targetName
                    + ", it is likely that your data falls outside of the target Spatial Reference Extent"
                )
                dla.addMessage("To verify please use the Append tool to load some data to the target dataset")
    return result
def exportDataset(xmlDoc, sourceLayer, workspace, targetName, rowLimit):
    result = True
    xmlFields = xmlDoc.getElementsByTagName("Field")
    dla.addMessage("Exporting Layer from " + sourceLayer)
    whereClause = ""
    if rowLimit != None:
        try:
            whereClause = getObjectIdWhereClause(sourceLayer, rowLimit)
        except:
            dla.addMessage("Unable to obtain where clause to Preview " +
                           sourceLayer + ", continuing with all records")

    if whereClause != '' and whereClause != ' ':
        dla.addMessage("Where " + str(whereClause))
    sourceName = dla.getSourceName(xmlDoc)
    viewName = sourceName + "_View"
    dla.addMessage(viewName)

    targetRef = getSpatialReference(xmlDoc, "Target")
    #sourceRef = getSpatialReference(xmlDoc,"Source")

    if targetRef != '':

        arcpy.env.workspace = workspace
        view = dla.makeFeatureView(dla.workspace, sourceLayer, viewName,
                                   whereClause, xmlFields)
        dla.addMessage("View Created")
        count = arcpy.GetCount_management(view).getOutput(0)
        dla.addMessage(str(count) + " source rows")

        arcpy.env.overwriteOutput = True
        arcpy.CreateFeatureclass_management(workspace,
                                            targetName,
                                            template=sourceLayer,
                                            spatial_reference=targetRef)
        fc = workspace + os.sep + targetName
        arcpy.Append_management(view, fc, schema_type="NO_TEST")
        dla.addMessage(arcpy.GetMessages(2))  # only serious errors
        count = arcpy.GetCount_management(fc).getOutput(0)
        dla.addMessage(str(count) + " source rows exported to " + targetName)
        if str(count) == '0':
            result = False
            dla.addError(
                "Failed to load to " + targetName +
                ", it is likely that your data falls outside of the target Spatial Reference Extent"
            )
            dla.addMessage(
                "To verify please use the Append tool to load some data to the target dataset"
            )
    return result
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 exportDataset(xmlDoc,sourceLayer,workspace,targetName,rowLimit):
    result = True
    xmlFields = xmlDoc.getElementsByTagName("Field")
    dla.addMessage("Exporting Layer from " + sourceLayer)
    whereClause = ""
    if rowLimit != None:
        try:
            whereClause = getObjectIdWhereClause(sourceLayer,rowLimit)
        except:
            dla.addMessage("Unable to obtain where clause to Preview " + sourceLayer + ", continuing with all records")
            
    if whereClause != '' and whereClause != ' ':
        dla.addMessage("Where " + str(whereClause))
    sourceName = dla.getSourceName(xmlDoc)
    viewName = sourceName + "_View"
    dla.addMessage(viewName)
    
    targetRef = getSpatialReference(xmlDoc,"Target")
    #sourceRef = getSpatialReference(xmlDoc,"Source")
    
    if targetRef != '':
            
        arcpy.env.workspace = workspace
        view = dla.makeFeatureView(dla.workspace,sourceLayer,viewName,whereClause,xmlFields)
        dla.addMessage("View Created")            
        count = arcpy.GetCount_management(view).getOutput(0)
        dla.addMessage(str(count) + " source rows")

        arcpy.env.overwriteOutput = True
        arcpy.CreateFeatureclass_management(workspace,targetName,template=sourceLayer,spatial_reference=targetRef)
        fc = workspace + os.sep + targetName
        arcpy.Append_management(view,fc,schema_type="NO_TEST")
        dla.addMessage(arcpy.GetMessages(2)) # only serious errors
        count = arcpy.GetCount_management(fc).getOutput(0)
        dla.addMessage(str(count) + " source rows exported to " + targetName)
        if str(count) == '0':
            result = False
            dla.addError("Failed to load to " + targetName + ", it is likely that your data falls outside of the target Spatial Reference Extent")
            dla.addMessage("To verify please use the Append tool to load some data to the target dataset")
    return result