-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreproject_folder_contents.py
More file actions
53 lines (39 loc) · 1.8 KB
/
reproject_folder_contents.py
File metadata and controls
53 lines (39 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# This script reprojects all the files in a folder to match the projection of a target dataset (in this case, the one used by the Land Trust of Virginia),
#and skips a file if it's already in the target projection.
# Create the geoprocessor object
import arcgisscripting
gp = arcgisscripting.create(9.3)
#Setting OverWriteOutput to True allows geoprocessing tools to overwrite the output if it already exists.
gp.OverWriteOutput = 1
try:
# Create path variables
targetFolder = "path\\to\\target\\folder"
targetProjectionDataset = "path\\to\\dataset\\with\\desired\\projection"
# Get the spatial reference of the target dataset
descTgtData = gp.Describe(targetProjectionDataset)
srTgtData = descTgtData.SpatialReference
#Get a list of all feature classes in the target folder
gp.Workspace = targetFolder
featureClassList = gp.ListFeatureClasses()
# Loop through all target folder feature classes
for featureClass in featureClassList:
# Get the name of the feature class
desc = gp.Describe(featureClass)
featureClassName = desc.Name
# Get the spatial reference of the feature class
sr = desc.SpatialReference
# Construct the output path
rootName = featureClassName[:-4]
outProjectFeatureClass = targetFolder + "\\" + rootName + "_projected" + ".shp"
# Compare the spatial reference of the feature class with that of the target dataset, and if they do not match,
# perform the projection and report what happened
if sr.Name != srTgtData.Name:
gp.project_management(featureClass, outProjectFeatureClass, srTgtData)
gp.AddMessage("Projected " + featureClassName + " successfully. ")
print "Projected " + featureClassName + " successfully. "
else:
# skip
continue
except:
# Report if there was an error
print gp.GetMessages(2)