Hi
I have several rasters( jpg files ) and i want convert them to tif files to file " OtherFormat" in env.workspace with arcpy. In my code i try to convert all jpg file:
import arcpy,os,sys,string import arcpy.mapping from arcpy import env env.workspace = r"C:\Project\out" arcpy.RasterToOtherFormat_conversion("*.jpg","OtherFormat","TIFF") print 'converted'
but get en error:
ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Rasters: Dataset *.jpg does not exist or is not supported Failed to execute (RasterToOtherFormat).
any help would be great
Solved! Go to Solution.
There are several errors in your code. Have a look at the code below:
import arcpy in_folder = r"C:\Forum\TIFF2JPG\tiff" out_folder = r"C:\Forum\TIFF2JPG\jpg" arcpy.env.workspace = in_folder rasters = arcpy.ListRasters("*", "TIF") print rasters for raster in rasters: print raster # RasterToOtherFormat_conversion (Input_Rasters, Output_Workspace, {Raster_Format}) arcpy.RasterToOtherFormat_conversion(raster, out_folder, "JPEG")
Changes to the code:
The result that is printed is
[u'image00.tif', u'image01.tif', u'image02.tif', u'image03.tif'] image00.tif image01.tif image02.tif image03.tif
The out_folder contains the 4 jpg's names image00.jpg to image03.jpg including wordfiles.
No "black areas" are invented in the output. However if your input has a larger area than your data extent, this will be exported too. Also when run within the Python window of ArcMap, extent environment settings will influence the result. The black area is how in TIFF imagery the nodata is represented by default.
To convert JPG to TIFF just invert the TIF and JPEG settings (and point to the correct folders).
Have you seen this ArcGIS Desktop ? I'm not a developer, so I probably can't help with code questions, but I did notice a sample code in here that is similar to yours that I thought might help.
Hi Lisa, yes i based my code from there- thanks
The list of jpgs should be a list (string) separated by semicolons. Use arcpy.ListRasters to obtain the list of input jpgs and format the list into a string using the semicolon as separator.
Hi Xander, i try this:
import arcpy,os,sys,string import arcpy.mapping from arcpy import env env.workspace = r"C:\Project\out" rasters = arcpy.ListRasters("*", "JPG") for raster in rasters: print(raster) arcpy.RasterToOtherFormat_conversion("*.jpg","OtherFormat","TIFF") print 'converted'
but get en error:
>>> BSM-1534.jpg Traceback (most recent call last): File "C:\Users\htr\Desktop\python2.py", line 11, in <module> arcpy.RasterToOtherFormat_conversion("*.jpg","OtherFormat","TIFF") File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\conversion.py", line 2753, in RasterToOtherFormat raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Rasters: Dataset *.jpg does not exist or is not supported Failed to execute (RasterToOtherFormat).
in the work space i do have jpg rasters
you need to replace
arcpy.RasterToOtherFormat_conversion("*.jpg","OtherFormat","TIFF")
with
arcpy.RasterToOtherFormat_conversion(raster , "OtherFormat","TIFF")
List Rasters returns a list of raster string paths, so when you loop through them, raster represents the file path for the raster you want converted.
what the meaning of the " * " ?
when i add the tif to mxd i get the raster and black area a round:
Have you set the NoData value for display?
how can i know what to set?