Python 脚本不适用于版本化功能 Class

Python Script not working on Versioned Feature Class

我有一个非常有用的地理处理脚本,直到将数据源移动到必须启用版本控制的要素数据集。

当此脚本指向要素数据集外的图层时,它运行良好。当我指向要素数据集中的图层时,脚本仍在运行……没有错误,但没有保存更新。关于为什么会发生这种情况的任何想法?示例代码如下:

import arcpy, os
arcpy.env.overwriteOutput = 1

# Set workspace and input fc variables
folderPath = r"S:\Data\Fires\Fire_Mapping_Analysis"
arcpy.env.workspace = folderPath + "\EmerOps as GIS.sde\EmerOps.GIS.FireBoundaries"
scratch_workspace = r"S:\Data\Fires\Fire_Mapping_Analysis\Fire_Map_Reports_Review.gdb"
BrushFire_fc = "\EmerOps.GIS.BrushFireAnalysis"

# Geoprocessing - Calculate fire acreage, perimeter, and class

print("Calculating Fire acreage, perimeter, and class...")
coords = "PROJCS['NAD_1983_StatePlane_California_V_FIPS_0405_Feet',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',6561666.666666666],PARAMETER['False_Northing',1640416.666666667],PARAMETER['Central_Meridian',-118.0],PARAMETER['Standard_Parallel_1',34.03333333333333],PARAMETER['Standard_Parallel_2',35.46666666666667],PARAMETER['Latitude_Of_Origin',33.5],UNIT['Foot_US',0.3048006096012192]]"
arcpy.management.CalculateGeometryAttributes(BrushFire_fc, "GIS_ACRES AREA;PERIMETER PERIMETER_LENGTH", "MILES_US",
                                             "ACRES", coords, "SAME_AS_INPUT")

# Fire Classes by acreage

fields = ['GIS_ACRES', 'CLASS']

with arcpy.da.UpdateCursor(BrushFire_fc, fields) as cursor:
    for row1 in cursor:
        if (row1[0] > 4999.5):
            row1[1] = "G"
            cursor.updateRow(row1)
        elif (row1[0] > 999.5 and row1[0] < 4999.4):
            row1[1] = "F"
            cursor.updateRow(row1)
        elif (row1[0] > 299.5 and row1[0] < 999.4):
            row1[1] = "E"
            cursor.updateRow(row1)
        elif (row1[0] > 99.95 and row1[0] < 299.4):
            row1[1] = "D"
            cursor.updateRow(row1)
        elif (row1[0] > 9.95 and row1[0] < 99.94):
            row1[1] = "C"
            cursor.updateRow(row1)
        elif (row1[0] > 0.255 and row1[0] < 9.94):
            row1[1] = "B"
            cursor.updateRow(row1)
        elif (row1[0] <= 0.254):
            row1[1] = "A"
            cursor.updateRow(row1)

        else:
            print("No records found")
        # print(str(row1.FIRE_NAME) + ", Class " + row1.CLASS)    
    

图层已版本化。我认为这在这里也发挥了很大的作用。

密钥正在使用 arcpy.da.Editor。该脚本会 运行,但如果没有编辑器,编辑将不会保存。这似乎是使用版本化数据集时的关键。

#Start edit session on versioned dataset
edit = arcpy.da.Editor(workspace, exclude feature dataset from path)
edit.startEditing(False, True)
edit.startOperation()

#geoprocessing during the edit session then...

#Stop editing and save edits
edit.stopOperation()
edit.stopEditing(True)