| |
# gp_prj_assign.py
#
# Batch assignment of coordinate reference systems to feature classes
'''Batch assing coordinate systems'''
import os, sys, string, win32com.client
# start reporting
import time
me=os.path.splitext(os.path.basename(sys.argv[0]))[0]
print "\n",__doc__,"\n",me,"started at: " + str(time.asctime())
timestamp=time.clock()
# Create the Geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
try:
path=sys.argv[1] #1
except:
path="G:\\beta_test\\Tests\\wf\\test_b_def\\" #1
oplist=[]
gp.workspace = path
fclist = gp.ListFeatureClasses("*") #2
fclist.reset()
fc=fclist.next()
while fc:
desc=gp.describe(fc)
SR = desc.SpatialReference
if SR.Name == "Unknown": #3
print fc,"has unknown CRS."
oplist.append(fc)
fc=fclist.next()
if len(oplist) == 0:
print "All CRS are known."
sys.exit(0)
crs="27700" # British National Grid
print "assigning",crs,"to",len(oplist),"feature classes..."
for fc in oplist:
print fc
try:
gp.DefineProjection_management (fc, crs) #4
print "CRS",crs,"assigend"
except:
print "could not assing CRS",crs,"to", fc
gp.GetMessages()
delta=time.clock()-timestamp
timestamp=time.clock()
print me,"successfully finished:",str(time.asctime()),"\nTotal time in sec:",str(delta),"\n"
|