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.
in tools like ListRasters the "*" acts as a wildcard that will take any string name. So if you have "DEM*" it will return any jpegs that begin with "DEM" and have any characters following it. This does not work with arcpy.RasterToOtherFormat_conversion as an input, since it is checking for a raster at a specific file path, not attempting to find multiple rasters as the ListRasters does. ListRasters is intended to get a list of all the rasters of the name and type you indicated, which you can then use as the input for other geoprocessing tools.
Ian,
when i run the code i get:
>>> 2015-03-25_084900.jpg converted >>>
but when i open r"C:\Project\out\OtherFormat" there no tiff raster
Ian,
when i try to convert tiff to jpg with:
import arcpy,os,sys,string import arcpy.mapping from arcpy import env env.workspace = r"C:\Project\out\OtherFormat" rasters = arcpy.ListRasters("*", "TIFF") for raster in rasters: print(raster) arcpy.RasterToOtherFormat_conversion(rasters ,"OtherFormat","JPEG") print 'converted'
the code just run without any messages and the tif raster does not converted
almost there.
in the arcpy.RasterToOtherFormat_conversion, you are passing along rasters, which is your list of rasters instead of the individual rasters which would just be your variable, raster.
Not this:
arcpy.RasterToOtherFormat_conversion(rasters ,"OtherFormat","JPEG")
But this:
arcpy.RasterToOtherFormat_conversion(raster ,"OtherFormat","JPEG")
the result is:
>>> ================================ RESTART ================================ >>> >>>
and there no converted rasters in OtherFormat folder. i tried also to convert bmp and png format to jpg- with no success .
I'm not sure if you need an app within Arc to do this or not, but I do know that I have successfully converted jpegs to tiffs in a free application called QGIS. It lets you keep the same projection, and isn't too difficult to use. No coding required. Granted, I'm fairly certain the programmers in here likely could keep working with you until the code works.
Lisa, programming isn't required to do this for a single tif, but it sounds like she wants to convert an entire folders worth of tifs to jpegs. It fine to go and do manually if you have just a few, but it sound like they could have many tifs to be converted, so a script to do it all could save lots of time.
Hey Ian,
I do batches of a few hundred at a time on QGIS all the time. The only manual step would be the input test of one or two to make sure the output is how someone needs it to be. It's all good though as I am learning so much from watching you all adjust the script.
I'm still just a student and haven't been able to look into Open Source GIS a whole lot, though it sounds like it would be fairly easy to do in QGIS, more so then running a tool like that in batch mode in ArcGIS. Python just helps augment ArcGIS geoprocessing tools to make them more effective.
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).