コード例 #1
0
def preview(xmlFileName):
    global source, target, rowLimit

    dla.setWorkspace()
    dla._errCount = 0

    xmlFileName = dla.getXmlDocName(xmlFileName)
    xmlDoc = dla.getXmlDoc(xmlFileName)
    #arcpy.AddMessage("rowLimit = " + str(rowLimit) )
    if rowLimit == "" or rowLimit == None:
        rowLimit = 100

    prj = dla.setProject(xmlFileName, dla.getNodeValue(xmlDoc, "Project"))
    if prj == None:
        dla.addError(
            "Unable to open your project, please ensure it is in the same folder as your current project or your Config file"
        )
        return False

    if source == "" or source == None:
        source = dla.getDatasetPath(xmlDoc, "Source")
    if target == "" or target == None:
        target = dla.getDatasetPath(xmlDoc, "Target")

    if dla.isTable(source) or dla.isTable(target):
        datasetType = 'Table'
    else:
        datasetType = 'FeatureClass'
    dte = datetime.datetime.now().strftime("%Y%m%d%H%M")
    targetName = dla.getDatasetName(target) + dte
    targetDS = os.path.join(dla.workspace, targetName)
    res = dlaExtractLayerToGDB.extract(xmlFileName, rowLimit, dla.workspace,
                                       source, targetDS, datasetType)
    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)
            if dla.isTable(targetDS):
                arcpy.MakeTableView_management(targetDS, layertmp)
            else:
                arcpy.MakeFeatureLayer_management(targetDS, layertmp)
            fieldInfo = dla.getLayerVisibility(layertmp, xmlFileName)
            if dla.isTable(targetDS):
                arcpy.MakeTableView_management(targetDS, layer, None,
                                               dla.workspace, fieldInfo)
            else:
                arcpy.MakeFeatureLayer_management(targetDS, 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")
コード例 #2
0
ファイル: dlaPreview.py プロジェクト: Esri/data-assistant
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")
コード例 #3
0
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")
コード例 #4
0
 |    http://www.apache.org/licenses/LICENSE-2.0
 |
 | Unless required by applicable law or agreed to in writing, software
 | distributed under the License is distributed on an "AS IS" BASIS,
 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | See the License for the specific language governing permissions and
 | limitations under the License.
 ------------------------------------------------------------------------------
 """
# dlaReplaceByField.py - use Replace field settings to replace content in a database or service.
# --------------------------------------------------------------------------------------------------------------
'''
Tool to replace data by field value or where clause. The script calls dlaPublish.publish with one or more
xml file names separated by semi colons - the way that a multiple file parameter is passed from Geoprocessing tools.

Data will be deleted in the target dataset using the Replace By Settings, and all data from the source will be appended.
'''
import dlaPublish, arcpy, dla

dlaPublish._useReplaceSettings = True  # setting this to True will use ReplaceByField logic

arcpy.AddMessage("Replacing by Field Value")

xmlFileNames = arcpy.GetParameterAsText(
    0)  # xml file name as a parameter, multiple values separated by ;
dla._errCount = 0

dlaPublish.publish(xmlFileNames)  # perform the processing

dla.writeFinalMessage("Data Assistant - Replace Data")
コード例 #5
0
ファイル: dlaAppendData.py プロジェクト: Esri/data-assistant
 |
 | Unless required by applicable law or agreed to in writing, software
 | distributed under the License is distributed on an "AS IS" BASIS,
 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | See the License for the specific language governing permissions and
 | limitations under the License.
 ------------------------------------------------------------------------------
 """
# dlaAppendData.py - Append Data to a database or service.
# --------------------------------------------------------------------------------------------------------------
'''
Tool to append data to a target dataset. The script calls dlaPublish.publish with one or more
xml file names separated by semi colons - the way that a multiple file parameter is passed from Geoprocessing tools.

No data will be deleted in the target dataset, and all data from the source will be appended.
'''

import dlaPublish, arcpy, dla

dlaPublish.useReplaceSettings = False # setting this to False will Append data

arcpy.AddMessage("Appending Data")

xmlFileNames = arcpy.GetParameterAsText(0) # xml file name as a parameter, multiple values separated by ;
dla._errCount = 0

dlaPublish.publish(xmlFileNames) # perform the processing

dla.writeFinalMessage("Data Assistant - Append Data")

コード例 #6
0
# dlaReplaceByField.py - use Replace field settings to replace content in a database or service.
# --------------------------------------------------------------------------------------------------------------
'''
Tool to replace data by field value or where clause. The script calls dlaPublish.publish with one or more
xml file names separated by semi colons - the way that a multiple file parameter is passed from Geoprocessing tools.

Data will be deleted in the target dataset using the Replace By Settings, and all data from the source will be appended.
'''
import dlaPublish, arcpy, dla

dlaPublish.useReplaceSettings = True # setting this to True will use ReplaceByField logic

arcpy.AddMessage("Replacing by Field Value")

xmlFileNames = arcpy.GetParameterAsText(0) # xml file name as a parameter, multiple values separated by ;
dla._errorCount = 0

dlaPublish.publish(xmlFileNames) # perform the processing

dla.writeFinalMessage("Data Assistant - Replace Data")

コード例 #7
0
# dlaAppendData.py - Append Data to a database or service.
# --------------------------------------------------------------------------------------------------------------
'''
Tool to append data to a target dataset. The script calls dlaPublish.publish with one or more
xml file names separated by semi colons - the way that a multiple file parameter is passed from Geoprocessing tools.

No data will be deleted in the target dataset, and all data from the source will be appended.
'''

import dlaPublish, arcpy, dla

dlaPublish.useReplaceSettings = False  # setting this to False will Append data

arcpy.AddMessage("Appending Data")

xmlFileNames = arcpy.GetParameterAsText(
    0)  # xml file name as a parameter, multiple values separated by ;
dla._errorCount = 0

dlaPublish.publish(xmlFileNames)  # perform the processing

dla.writeFinalMessage("Data Assistant - Append Data")
コード例 #8
0
ファイル: dlaStage.py プロジェクト: xiaoai-li/data-assistant
def stage(xmlFileNames):
    global source, target, rowLimit

    dla.setWorkspace()
    dla._errCount = 0
    outlayers = []

    for xmlFileName in xmlFileNames.split(';'):
        xmlFileName = dla.getXmlDocName(xmlFileName)
        xmlDoc = dla.getXmlDoc(xmlFileName)
        prj = dla.setProject(xmlFileName, dla.getNodeValue(xmlDoc, "Project"))
        if prj == None:
            dla.addError(
                "Unable to open your project, please ensure it is in the same folder as your current project or your Config file"
            )

        if rowLimit == "" or rowLimit == None:
            rowLimit = None
        if source == "" or source == None:
            source = dla.getDatasetPath(xmlDoc, "Source")
        if target == "" or target == None:
            target = dla.getDatasetPath(xmlDoc, "Target")

        if dla.isTable(source) or dla.isTable(target):
            datasetType = 'Table'
        else:
            datasetType = 'FeatureClass'

        targetName = dla.getStagingName(source, target)
        targetDS = os.path.join(dla.workspace, targetName)

        res = dlaExtractLayerToGDB.extract(xmlFileName, rowLimit,
                                           dla.workspace, source, targetDS,
                                           datasetType)
        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)
                if dla.isTable(targetDS):
                    arcpy.MakeTableView_management(targetDS, layertmp)
                else:
                    arcpy.MakeFeatureLayer_management(targetDS, layertmp)
                fieldInfo = dla.getLayerVisibility(layertmp, xmlFileName)
                if dla.isTable(targetDS):
                    arcpy.MakeTableView_management(targetDS, layer, None,
                                                   dla.workspace, fieldInfo)
                else:
                    arcpy.MakeFeatureLayer_management(targetDS, layer, None,
                                                      dla.workspace, fieldInfo)
                # should make only the target fields visible
                outlayers.append(layer)
                ### *** need to insert tag in xml file...
                dla.insertStagingElement(xmlDoc)
                try:
                    xmlDoc.writexml(open(xmlFileName, 'wt', encoding='utf-8'))
                    dla.addMessage('Staging element written to config file')
                except:
                    dla.addMessage("Unable to write data to xml file")
                xmlDoc.unlink()
        else:
            dla.addError("Failed to Extract data")
            print("Failed to Extract data")
    if outlayers != []:
        arcpy.SetParameter(_derived, ";".join(outlayers))
    dla.writeFinalMessage("Data Assistant - Stage")