Raster to ascii

4232
6
04-01-2012 09:19 PM
AprilReside
New Contributor
Hi,
I am trying to convert a raster to ascii in ArcMap 10, but I can only get an output with the .txt file extension - even when I specify .asc
can anyone help?
thanks heaps,
April
0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus
why don't you just rename it outside of arcmap?
0 Kudos
MathewCoyle
Frequent Contributor
Are you sure it isn't appending .TXT to the end of your output? You need to specify the extension if you don't want it to be text directly in the tool parameter.
0 Kudos
curtvprice
MVP Esteemed Contributor
I am trying to convert a raster to ascii in ArcMap 10, but I can only get an output with the .txt file extension - even when I specify .asc


Esri has named this .txt so it easily opens in a text editor from Windows (a good call, IMHO).

If you need the .asc extension for some reason, you could use the Calculate Value tool to rename the file in ModelBuilder with a short python script:

expression:

newext(r"%output ascii txt%","asc")


code:

def newext(file,ext):
    import os
    newfile =  os.path.splitext(file)[0] + "." + ext
    os.rename(file,newfile)
0 Kudos
AprilReside
New Contributor
Hi all,
Many thanks for the help!  It seems that changing the extension .txt to .asc outside of ArcMap worked fine.  Thanks
0 Kudos
SteveLynch
Esri Regular Contributor
April

The default extension in the RasterToASCII GP tool is .txt, however, you can also use .asc

These are the 2 extensions to use. If you create it using the .asc extension then it becomes a supported raster data format, i.e. you can use it in ArcGIS as any other raster dataset (no need to then use ASCIIToRaster).

Please can you share a screenshot of the dialog or are you doing it via scripting.

Thanks
Steve
0 Kudos
OliverBurdekin
New Contributor
Hi Guys,

I've been trying this out and need to do it pro grammatically as I have a lot of rasters I am iterating through to convert to .asc.  I tried specifying this in the raster to ASCII tool but then I end up with %filename%.asc.TXT  I also tried the suggestion above of using calculate value.  I get this error when I run it:

Executing: CreateEnvLayersFile C:\Users\OJB\Desktop\BurdsGIS\CollabPapers\Mimeticus\WorldClim\asc2 C:\Users\OJB\Desktop\BurdsGIS\CollabPapers\Mimeticus\WorldClim\tmin_clip NOT_RECURSIVE
Start Time: Thu Dec 06 14:12:56 2012
Executing (Iterate Rasters): IterateRasters C:\Users\OJB\Desktop\BurdsGIS\CollabPapers\Mimeticus\WorldClim\tmin_clip # # NOT_RECURSIVE
Start Time: Thu Dec 06 14:12:57 2012
Succeeded at Thu Dec 06 14:12:57 2012 (Elapsed Time: 0.00 seconds)
Executing (Raster to ASCII): RasterToASCII C:\Users\OJB\Desktop\BurdsGIS\CollabPapers\Mimeticus\WorldClim\tmin_clip\clip_tmin_1 C:\Users\OJB\Desktop\BurdsGIS\CollabPapers\Mimeticus\WorldClim\asc2\e_clip_tmin_1.TXT
Start Time: Thu Dec 06 14:12:57 2012
Succeeded at Thu Dec 06 14:12:59 2012 (Elapsed Time: 2.00 seconds)
Executing (Calculate Value): CalculateValue newext("C:\Users\OJB\Desktop\BurdsGIS\CollabPapers\Mimeticus\WorldClim\asc2\e_clip_tmin_1.txt","asc") "def newext(file,ext):\n    import os\n    newfile =  os.path.splitext(file)[0] + "." + ext\n    os.rename(file,newfile)" Variant
Start Time: Thu Dec 06 14:12:59 2012
ERROR 000539: Error running expression: newext("C:\Users\OJB\Desktop\BurdsGIS\CollabPapers\Mimeticus\WorldClim\asc2\e_clip_tmin_1.txt","asc") <type 'exceptions.WindowsError'>: [Error 123] The filename, directory name, or volume label syntax is incorrect
Failed to execute (Calculate Value).
Failed at Thu Dec 06 14:12:59 2012 (Elapsed Time: 0.00 seconds)
Failed to execute (CreateEnvLayersFile).
Failed at Thu Dec 06 14:12:59 2012 (Elapsed Time: 3.00 seconds)
0 Kudos