Setting projection in a python script - 9.3

292
1
07-20-2011 01:10 AM
RichardWhite2
New Contributor
Hi,

I have a python script that batch converts ascii files to other raster types.

How do I hard code in a projection, in this case wgs84, so it sets the projection after each ascii file is converted. Below is the part of the code that does the conversion;

# Loop through the list of input Rasters and convert/copy each to the output geodatabase or folder
    for inRaster in inRasters_list:
        # Get filename correct
        rasterBaseWithExt = os.path.split(inRaster)[1]
        rasterBase = string.split(rasterBaseWithExt,".")[0]
        ourRasterBase = rasterBase
        rasterBase = "\\" + rasterBase
        outRaster = outWorkspace + rasterBase + ext
       
        try:
           
            # Copy/Convert the inRaster to the outRaster
            gp.ASCIIToRaster_conversion(inRaster, outRaster, format)
##            gp.ASCIIToRaster_conversion(inRaster, outRaster, "FLOAT")
            # If the Copy/Convert was successfull add a message stating this
            gp.AddMessage(msgSuccess + "%s To %s \n\n" % (rasterBaseWithExt, ourRasterBase))

Thanks for any help.

Regards,

R.
Tags (2)
0 Kudos
1 Reply
curtvprice
MVP Esteemed Contributor
How do I hard code in a projection, in this case wgs84, so it sets the projection after each ascii file is converted.


I believe if you set the output coordinate system environment before you start creating rasters it will write that coordinate system to the output rasters. If that fails, you can allways use the Define Projection (management) tool.

gp.outputCoordinateSystem =  "GEOGCS['GCS_WGS_1984'," \
  "DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]]," \
   PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"
0 Kudos