Select to view content in your preferred language

Batch Define projection with Python

2226
2
09-22-2010 07:48 AM
SofiaStouki
Emerging Contributor
Hi all,

I am fairly new to Python and I have been trying to make a script work-to assign a GC system to a number of shapefiles in a folder.(The GC system is currently Unknown so I cannot use the other tools in batch mode)

I am using Python 2.5 and Arc 9.3.1 but I keep getting errors
( for fc in fcS:
TypeError: 'geoprocessing list object' object is not iterable)

that don't really tip me off about what it s going wrong (newbie)

My code is:
import arcgisscripting
gp = arcgisscripting.create()

gp.workspace = "P:\Proj"
gp.toolbox = "management"
coordsys = "Coordinate Systems/Projected Coordinate Systems/National Grids/British National Grid.prj"
fcs = gp.ListFeatureClasses()
for fc in fcS:
    gp.defineprojection(fcS, coordsys)

I am certain there are a lot of errors there, but if anyone can assist with the iteration/listing of the shapefiles in the folder it would be great.

Thanks in advance for any suggestions.
S.
0 Kudos
2 Replies
JohnHauck
Frequent Contributor
Prior to 9.3 the ListFeatureClasses method returned an enumeration object. An enumeration requires that you call it's Next method to navigate through the values.

At 9.3 the ListFeatureClasses method returns a Python list that you will be able to use in a for loop as in your sample code.

I would suggest that you change the following line:

gp = arcgisscripting.create()

to

gp = arcgisscripting.create(9.3)


See the following help documents for additional details.

Comparing 93 and 92 geoprocessors

Differences between geoprocessor versions
0 Kudos
SofiaStouki
Emerging Contributor
Hi John,

thank you for your reply. After getting feedback from the forum users and going through some articles, I managed to get my script to work. I have posted the details at the Functions-Geoprocessing forum

( http://forums.arcgis.com/threads/13474-Batch-define-projection-with-Python )

Thanks again!
Regards,
S.
0 Kudos