Uunable to use 'arcpy.env.workspace' properly !

1251
7
04-01-2012 04:14 AM
AdelItani
New Contributor II
arcpy.env.workspace doest not work when we use barename for input file ?

# arcpy10.py
# CPython 2.6, ArcGIS 10, IDLE, windows_XP

import arcpy, sys
import arcpy.mapping
from arcpy import env
arcpy.env.overwriteOutput = True

arcpy.env.workspace = "d:\\test"

# Fullpath of input file.
arcpy.FloatToRaster_conversion(
"d:\\test\\14605430.flt",
"14605430.tif")

try:
# No fullpath of input file.
arcpy.FloatToRaster_conversion(
"14605430.flt",
"14605430.img")

except:
print arcpy.GetMessages()
sys.exit()


"""
Converting floating point file to grid ...
Executing: FloatToRaster 14605430.flt d:\test\14605430.img
Start Time: Sun Apr 01 12:58:49 2012
Failed to execute. Parameters are not valid.
ERROR 000865: Input floating point raster file: 14605430.flt does not exist.
Failed to execute (FloatToRaster).
Failed at Sun Apr 01 12:58:49 2012 (Elapsed Time: 0.00 seconds)
"""
Tags (2)
7 Replies
StacyRendall1
Occasional Contributor III
There are two ways of accessing submodules (arcpy is a module, env (arcpy.env) is a submodule). In your code you are mixing them up, which is at least going to cause some issues...

Because you used:
from arcpy import env

Env is imported as its own module, so later on you should access it with:
env.workspace = "d:\\test"


The other way to do it is just:
import arcpy

Env is still a submodule of arcpy, so later on you should access it with:
arcpy.env.workspace = "d:\\test"


After that you should use the Not Full path method you have shown in your original post...
AdelItani
New Contributor II
Thanks Stacy for help, but i still have ERROR

import arcpy
import arcpy.mapping
arcpy.env.workspace = "d:\\test"
arcpy.env.overwriteOutput = True

try:
    arcpy.FloatToRaster_conversion(
        "14605430.flt",
        "14605430.tif")
except:
    print arcpy.GetMessages()


""" ERROR 010158: Unable to open file \14605430.flt.
    ERROR 010067: Error in executing grid expression.
"""
0 Kudos
DarrenWiens2
MVP Honored Contributor
"The file must have a .flt extension. There must be a header file in association with the floating-point binary file, with a .hdr extension."

Does your .flt have an associated .hdr file?
0 Kudos
AdelItani
New Contributor II
Yes Daren, there is two files: d:\test\14605430.flt, d:\test\14605430.hdr

Besides that, this script with replacing arcpy by arcgisscripting,
and with small editing, was run succefully on ArcGIS 9.2 and 9.3 .
0 Kudos
DarrenWiens2
MVP Honored Contributor
Does it happen to work if you change the name so it doesn't start with a number? I don't know about .flt or .tif, but some file formats don't like that.

Also, does it work properly if you use the entire filename rather than relying on the workspace environment?
0 Kudos
AdelItani
New Contributor II
Thanks Darren

I included zip-file 'p4605430_flt.zip' with files 'p4605430.flt' and 'p4605430.hdr',
and i am still facing the same error, after changing the line to:
arcpy.FloatToRaster_conversion("p4605430.flt", "p4605430.tif")

Where it does work properly with full_path_name without workspace environment.
0 Kudos
DarrenWiens2
MVP Honored Contributor
I tried your code with the same result (it didn't work when setting the workspace environment). I don't have any explanation, perhaps someone from ESRI can speak to this.

You can fake a workspace environment with the following (it's basically just using the whole path):
import arcpy
import arcpy.mapping
workspace = "d:\\test\\"
arcpy.env.overwriteOutput = True

try:
    arcpy.FloatToRaster_conversion(
        workspace + "p4605430.flt",
        workspace + "p4605430.tif")
except:
    print arcpy.GetMessages()
0 Kudos