annotate contrib/python/FixWorkspacePaths.py @ 281:dee641d0ab8b release-1.0

Removed tag release-
author Stephan Holl <stephan.holl@intevation.de>
date Thu, 06 Oct 2011 13:39:09 +0200
parents 4dc2b9aa3c57
children
rev   line source
256
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
1 #
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
2 # Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
3 #
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
4 # This file is part of MXD2map.
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
5 #
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
6 # This program is free software under the LGPL (>=v2.1)
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
7 # Read the file LICENCE.txt coming with the software for details
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
8 # or visit http://www.gnu.org/licenses/ if it does not exist.
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
9 #
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
10 # MXD2map has been developed on behalf of the
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
11 # Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
12 # by Intevation GmbH.
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
13 #
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
14 # Authors:
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
15 # Raimund Renkert <raimund.renkert@intevation.de>
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
16 # Bjoern Schilberg <bjoern.schilberg@intevation.de>
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
17 # Stephan Holl <stephan.holl@intevation.de>
4dc2b9aa3c57 Added LGPL header.
raimund renkert <raimund.renkert@intevation.de>
parents: 114
diff changeset
18
114
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
19 import arcpy, os
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
20
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
21 inputMXD = arcpy.GetParameterAsText(0)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
22
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
23 newpath = r'C:\mxd-konverter\testdata-frida'
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
24
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
25 rootdir = inputMXD
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
26
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
27 for root, subFolders, files in os.walk(rootdir):
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
28 for file in files:
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
29 f = os.path.join(root, file)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
30 if os.path.isfile(f):
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
31 basename, extension = os.path.splitext(f)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
32 if extension.lower() == ".mxd":
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
33 print "Bearbeitet Dokument %s" % f
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
34 mxd = arcpy.mapping.MapDocument(f)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
35 #Report broken sources
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
36 if len(arcpy.mapping.ListBrokenDataSources(mxd)) > 0:
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
37 for brkLyr in arcpy.mapping.ListBrokenDataSources(mxd):
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
38 if brkLyr.supports("dataSource"):
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
39 oldpath = brkLyr.dataSource
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
40 oldworkspace = brkLyr.workspacePath
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
41 print "Old dataSource-Path %s, old workspacePath %s " % (oldpath, oldworkspace)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
42 # Replace
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
43 brkLyr.findAndReplaceWorkspacePath(oldworkspace, newpath)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
44 print "Corrected path: %s" % brkLyr.workspacePath
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
45 print "Corrected dataSource: %s" %brkLyr.dataSource
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
46 mxd.save()
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
47 print "Wrote file %s" % f
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
48 print arcpy.GetMessages()
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
49 else:
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
50 print "keine kaputten Layer gefunden"
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
51
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
52 del mxd
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)