Select to view content in your preferred language

arcpy.MakeFeatureLayer_management how to work with versioned layers

4051
0
12-18-2015 05:18 AM
Labels (1)
JoseSanchez
Frequent Contributor
0 0 4,051

Hello everyone,

The following source code shows how to copy features from one feature class (Source) to another feature class (Destination) when both features are versioned.And then remove features copied from the Source

The steps:

  • create a new SDE version a  WorkingVersion
  • select Source Feature Class with features to be copied and make a Feature Layer
  • select Destination Feature Class make a Feature layer
  • ChangeVersion of both feature layers to the  WorkingVersion
  • append features to destination Feature Class
  • delete features from Source Feature Class that were appended
 versions = arcpy.ListVersions(database)
     # Print the versions available to the user

     for version in versions:
        print(version)

        if version == WorkingVersion:
            # Execute DeleteVersion
            arcpy.DeleteVersion_management(database, WorkingVersion)


     # Execute CreateVersion
     arcpy.CreateVersion_management(database, ParentVersion, WorkingVersion, "PUBLIC")


     # Select records with STATUS = 'Completed'  and Historical  records

     arcpy.MakeFeatureLayer_management(SourceFeatureCalss, SourceLayer, "STATUS = 'Completed'", "", " .....")
    # Process: Make Feature Layer (2)
     arcpy.MakeFeatureLayer_management(EditableFeatureClass, AppendedLayer, "", "", "......")


    #
    #  Change Both layers SourceLayer and AppendedLayer To OWNER.WORKINGVERSION version
    #

     arcpy.ChangeVersion_management('SourceLayer','TRANSACTIONAL', WorkingVersion,'')
     # Change to HISTORICALAASIS version
     arcpy.ChangeVersion_management('AppendedLayer','TRANSACTIONAL', WorkingVersion,'')

     # Process: Append...
     arcpy.Append_management("SourceLayer", AppendedLayer, "TEST", "", "")


     # Process: Delete Features...
     arcpy.DeleteFeatures_management(SourceLayer)

     arcpy.ReconcileVersions_management(database,
                                   "ALL_VERSIONS",
                                   "OWNER.ParentVersion",
                                   "OWNER.WORKINGVERSION",
                                   "LOCK_ACQUIRED",
                                   "NO_ABORT",
                                   "BY_OBJECT",
                                   "FAVOR_TARGET_VERSION",
                                   "POST",
                                   "KEEP_VERSION",
                                   scratchFolder + "RecLog.txt")