+ Reply to Thread
Results 1 to 8 of 8

Thread: Copying a layer - basic question but still clueless

  1. #1
    G IS
    Join Date
    Jun 2012
    Posts
    41
    Points
    0
    Answers Provided
    0


    0

    Default Copying a layer - basic question but still clueless

    Hi friends,

    I just want to copy a layer in my script. I can't seem to find any resources regarding this, but it's like one of the most basic things to do manually in ArcMap itself.

    Essentially, I just want to be able to copy a layer (and then rename it a bit and change it's source).

    How is this done?

    Thanks!

  2. #2
    Solomon Pulapkura
    Join Date
    May 2010
    Posts
    97
    Points
    33
    Answers Provided
    5


    0

    Default Re: Copying a layer - basic question but still clueless

    You need to use arcpy.Copy_management
    http://help.arcgis.com/en/arcgisdesk...00000051000000
    Solomon Pulapkura
    VESTRA Resources, Inc.
    www.vestra.com

  3. #3
    G IS
    Join Date
    Jun 2012
    Posts
    41
    Points
    0
    Answers Provided
    0


    0

    Default Re: Copying a layer - basic question but still clueless

    Hi Solomon,

    Thanks for that. But actually I just want to copy a layer within my map template itself, I do not want to copy any shapefiles or feature classes.

    Any idea how to do this?

    Thanks!

  4. #4
    Solomon Pulapkura
    Join Date
    May 2010
    Posts
    97
    Points
    33
    Answers Provided
    5


    0

    Default Re: Copying a layer - basic question but still clueless

    I dont think there is. You can copy a layer to disk using arcpy.mapping but not copy a layer in the TOC. Is that what you are doing?
    Instead of copy, you can use arcpy.mapping's AddLayer function to add the same layer again.
    Solomon Pulapkura
    VESTRA Resources, Inc.
    www.vestra.com

  5. #5
    G IS
    Join Date
    Jun 2012
    Posts
    41
    Points
    0
    Answers Provided
    0


    0

    Default Re: Copying a layer - basic question but still clueless

    Thanks Solomon.

    It worked using your suggestion.

    Unfortunately I can't get the symbology I want. Neither arcpy.ApplySymbologyFromLayer_management nor arcpy.mapping.UpdateLayer are working for me. The symbology remains however it came into my map.

    Thanks for the reply!

  6. #6
    Christopher Thompson
    Join Date
    Apr 2010
    Posts
    239
    Points
    121
    Answers Provided
    19


    0

    Default Re: Copying a layer - basic question but still clueless

    Unfortunately rendering your data is difficult in python and I'm experiencing similar concerns. UpdateLayer seems to be the best approach but you will have to have to pre-create 'template' layers that you reference to do that, which depending on your application may obviate the whole point of writing code to do this. The ability to render from code seems to be one of those things that ESRI wants you to use ArcObjects for.

  7. #7
    Solomon Pulapkura
    Join Date
    May 2010
    Posts
    97
    Points
    33
    Answers Provided
    5


    0

    Default Re: Copying a layer - basic question but still clueless

    How are you referencing the layer you want to change symbology to?

    If you are using arcpy.mapping's Layer function, try using arcpy.mapping's ListLayers function instead.
    Solomon Pulapkura
    VESTRA Resources, Inc.
    www.vestra.com

  8. #8
    G IS
    Join Date
    Jun 2012
    Posts
    41
    Points
    0
    Answers Provided
    0


    0

    Default Re: Copying a layer - basic question but still clueless

    Hi guys,

    Thanks for the replies!

    I have no idea what I did, but after several attempts of trial and error I eventually got it. Now to figure out how to order my layers properly

    Code:
        #newcontours
        for LGA in LGAlist:
            inContours = LGAtoContours[LGA]
            outContours = 'Contours 10m - ' + str(LGA)
            #   arcpy.AddMessage(outContours)
            arcpy.MakeFeatureLayer_management(inContours,outContours)
            contourlayer = arcpy.mapping.Layer(outContours)
            arcpy.mapping.AddLayer(df, contourlayer, "Top")
            updateContoursLayer = arcpy.mapping.ListLayers(mxd,outContours, df)[0]
            sourceContoursLayer = arcpy.mapping.Layer(r"U:\Layers\Contours 10m.lyr")
            arcpy.mapping.UpdateLayer(df, updateContoursLayer, sourceContoursLayer, True)

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts