I have around 57 map packages that I need to salvage layer data from. The layer files were incorrectly saved with absolute paths instead of relative paths so they won't display unless they are opened in the map package. I want to get rid of the map packages because they take up a lot of time and server space.

My goal is to somehow retrieve these layer files and save them to a server where they can be accessed easier. Exporting them isn't an option because I need to keep them in a layer file format to preserve aspects of the data. Opening the map package and trying to save them out as layer files again dosen't seem to work either, the layer files seem stuck looking back at the original creator's C: drive.

  • 1
    You realize that inside a map package is an MXD, not a lyr file? That said, you might be able to pull the MXD out of the MPK, and save the layers inside that to new .LYR files... – KHibma Dec 11 '18 at 15:48
  • Yes, I am aware. The mxd is where I am trying to save these layer files out from. Sorry for not being clearer. – Rfriedri341 Dec 11 '18 at 20:09

You can probably do something like this, but at the moment I cannot test it and I'm not sure about the Map Package bit (never have to deal with one of them)

mxd = arcpy.mapping.MapDocument(mxd_path) #this may not work in your case, not sure about Map Packages
for lyr in arcpy.mapping.ListLayers(mxd):
    lyr.saveACopy(new_lyr_path) # new_lyr_path needs to change every loop following your logic

I suggest you open the MPK and then use Set Data Sources to change the data sources in bulk from your home directory to your preferred data source location. Then you will be able to save .lyr files that point to the preferred sources.

You can change the data path(s) with this tool, but not the name of the feature class(es) themselves.

Set Data Sources will create a new copy of your MXD. You can follow these steps from a Catalog window in ArcMap, or save the MXD first and then do the work in ArcCatalog.

  1. In Catalog, right-click the MXD and choose Set Data Source(s)...
  2. In the Set Data Sources window, choose a new output MXD location and filename.
  3. For each data source, choose Replace or Replace All and specify an updated data source.

enter image description here

  1. When you are done setting paths, choose OK.
  2. Launch the new MXD and save your .lyr files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.