POST
|
No worries, seems like the code is working now. Thanks a trillion for your outstanding help.
... View more
11-06-2012
08:52 AM
|
0
|
0
|
706
|
POST
|
looks like i forgot a bracket at the end, sorry! os.rename(os.path.join(inDir,InAsciiFile), os.path.join(inDir,InAsciiFilename)) Thank you for getting back to me. I am really sorry to bother you again but there is again error and this time is with ascii2raster conversion: Traceback (most recent call last):
File "C:\Users\rumana\Desktop\My EFDC\Data\AVHRR\BatchAscii2Raster5.py", line 23, in <module>
gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFilename), os.path.join(OutRaster,InAsciiFilename.rsplit(".")[0][:11]), "FLOAT")
ExecuteError: ERROR 000875: Output raster: C:/Users/rumana/Desktop/My EFDC/Data/AVHRR/SST_Feb11/RasterUp_Feb11\SST2011_037's workspace is an invalid output workspace.
ERROR 000581: Invalid parameters.
Failed to execute (ASCIIToRaster).
... View more
11-06-2012
08:35 AM
|
0
|
0
|
706
|
POST
|
os.rename() needs a full path to the filename, or it won´t work. Try this: os.rename(os.path.join(inDir,InAsciiFile), os.path.join(inDir,InAsciiFilename) Thanks a lot for the help. I replaced os.rename with your code. But I got Token Error: EOF in multi-line statement. How do I fixed that? # Import system modules
import arcgisscripting, os
# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
# Set local variables
InAsciiFile = None
inDir = r"C:/Users/rumana/Desktop/My EFDC/Data/AVHRR/SST_Feb11"
OutRaster = "C:/Users/rumana/Desktop/My EFDC/Data/AVHRR/SST_Feb11/RasterUp_Feb11"
#gp.outputCoordinateSystem = r"Coordinate Systems\Projected Coordinate Systems\UTM\NAD 1983\NAD 1983 UTM Zone 17N.prj"
for InAsciiFile in os.listdir(inDir):
if InAsciiFile.rsplit(".")[-1] == "asc":
if InAsciiFile.startswith("2011"):
InAsciiFilename = "SST" + InAsciiFile.replace("_glsea","")
os.rename(os.path.join(inDir,InAsciiFile), os.path.join(inDir,InAsciiFilename)
InAsciiFile = InAsciiFilename
print InAsciiFile
# Process: ASCIIToRaster_conversion
gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFilename), os.path.join(OutRaster,InAsciiFilename.rsplit(".")[0][:11]), "FLOAT")
... View more
11-05-2012
10:16 AM
|
0
|
0
|
783
|
POST
|
I have found out two things: Error: when the ascii file starts with number say 2011_001.asc it doesn't work, whereas it works with glsea1.asc. I tried renaming the files in the code as below: But also getting error message. # Import system modules
import arcgisscripting, os
# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
# Set local variables
InAsciiFile = None
inDir = r"C:/Users/rumana/Desktop/My EFDC/Data/AVHRR/SST_Feb11"
OutRaster = "C:/Users/rumana/Desktop/My EFDC/Data/AVHRR/SST_Feb11/RasterUp_Feb11"
#gp.outputCoordinateSystem = r"Coordinate Systems\Projected Coordinate Systems\UTM\NAD 1983\NAD 1983 UTM Zone 17N.prj"
for InAsciiFile in os.listdir(inDir):
if InAsciiFile.rsplit(".")[-1] == "asc":
if InAsciiFile.startswith("2011"):
InAsciiFilename = "SST" + InAsciiFile.replace("_glsea","")
os.rename(InAsciiFile, InAsciiFilename)
print InAsciiFilename
# Process: ASCIIToRaster_conversion
gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFilename), os.path.join(OutRaster,InAsciiFilename.rsplit(".")[0][:11]), "FLOAT") Error Message: Traceback (most recent call last): File "C:\Users\rumana\Desktop\My EFDC\Data\AVHRR\BatchAscii2Raster3.py", line 18, in <module> os.rename(InAsciiFile, InAsciiFilename) WindowsError: [Error 2] The system cannot find the file specified Can you help me out please? Thanks.
... View more
11-02-2012
03:45 PM
|
0
|
0
|
783
|
POST
|
I have found out two things: Error1: Run Time Error Not Initialized was due to license problem, ArcGIS license server was down, now it is fixed. Error2: when the ascii file starts with number say 2011_001.asc it doesn't work, whereas it works with glsea1.asc. 2011_001.asc Traceback (most recent call last): File "C:/Users/rumana/Desktop/My EFDC/Data/AVHRR/BatchAscii2Raster3.py", line 18, in <module> gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFile), os.path.join(OutRaster,InAsciiFile.rsplit(".")[0][:9]), "INTEGER") ExecuteError: ERROR 999999: Error executing function. Failed to rename the specified file Failed to execute (ASCIIToRaster). What will be the most effective thing to do in this case? File naming was done by some third party (from where I downloaded the files) and I have around 200 files which needed to be converted to Raster format.
... View more
10-29-2012
10:36 AM
|
0
|
0
|
783
|
POST
|
I am using ArcGIS 9.3 and Python 2.5 does it have a problem with version?
... View more
10-29-2012
09:46 AM
|
0
|
0
|
783
|
POST
|
Try reducing the name splitting from 13 to 9 characters. It may be that it is a multi band raster and doesn't support 13 character file names. You can read about the formatting required for Esri Grids here. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009t0000000w000000 I seem to recall some issues when a file name starts with numeric characters, but that may be a different format I am thinking of. I checked with 9 but getting the same error. I have attached a sample data file. Thanks a lot for helping me out, please take your time.
... View more
10-29-2012
08:54 AM
|
0
|
0
|
783
|
POST
|
To change the output name you could do something like this. Changing the output to only take the first 13 characters of the input file name. If you want it to be more dynamic, splitting on a specific string etc then you could incorporate that also. At that point I would probably create an output raster variable to create the name. gp.ASCIIToRaster_conversion(os.path.join(inDir, InAsciiFile), os.path.join(OutRaster, InAsciiFile.rsplit(".")[0][:13]), "FLOAT") Thank you very much for reply. I tried your code, only changed "FLOAT" to "INTEGER", cause I need integer values. Got following error: 2011_001_glsea.asc Traceback (most recent call last): File "C:\Users\rumana\Desktop\My EFDC\Data\AVHRR\BatchAscii2Raster2.py", line 18, in <module> gp.ASCIIToRaster_conversion(os.path.join(inDir, InAsciiFile), os.path.join(OutRaster, InAsciiFile.rsplit(".")[0][:13]), "INTEGER") RuntimeError: NotInitialized I never got this error before and I tested your code with an ascii file which has name length less than 13 characters. It worked then.
... View more
10-29-2012
08:28 AM
|
0
|
0
|
783
|
POST
|
Hello mzcoyle, I tried your code for batch processing of ASCII to Raster. It works but I got one problem. How do I rename ASCII files or output Raster files, cause my ASCII files have more than 13 characters? mzcoyle: I tested this one and it works. Make sure your file names are less than 13 characters. Code: # Import system modules import arcgisscripting, os # Create the Geoprocessor object gp = arcgisscripting.create() # Set local variables InAsciiFile = None inDir = r"C:\GIS\ascii" OutRaster = "C:/GIS/Exports" gp.outputCoordinateSystem = r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" for InAsciiFile in os.listdir(inDir): if InAsciiFile.rsplit(".")[-1] == "asc": print InAsciiFile # Process: ASCIIToRaster_conversion gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFile), os.path.join(OutRaster,InAsciiFile.rsplit(".")[0]), "FLOAT")
... View more
10-28-2012
12:19 PM
|
0
|
0
|
2240
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|