How to set JPEG2000 quality for geoprocessor

851
1
10-25-2011 02:38 PM
SteveStanton
New Contributor
I'm using the ProjectRaster tool to re-project a JPEG2000 file, and noticed that the file size increased quite a bit (from 18Mb to 117Mb). I've tried using the GeoProcessor.SetEnvironmentValue method to make sure it uses JPEG2000 compression, but I'm not sure how to specify the quality value. Looking at some online help for scripting, it appeared that you can set the quality by appending a number to the compression type, so I tried the following:

Geoprocessor gp = new Geoprocessor();
gp.SetEnvironmentValue("Compression", "JPEG2000 50");


However my resultant file is the same size regardless of the number tagged on the end. Looking into one of the xml files that get produced alongside the resultant file, it does appear to have picked up the compression type. But there's no mention of quality. So is there some other way to specify it?

P.S. I've seen the IGPRasterGDBEnvCompression interface, but it would appear to relate to rasters in a GDB, and I'm only working with plain old files.
0 Kudos
1 Reply
SteveStanton
New Contributor
I haven't found any way to specify the quality value for the geoprocessor, so I thought I'd try using ISaveAs to post-process the result that comes out of ProjectRaster. My test code produced 3 results as follows:

IWorkspaceFactory wsfac = new RasterWorkspaceFactoryClass();
IWorkspace ws = wsfac.OpenFromFile(@"C:\Data", 0);
IRasterDataset rds = (ws as IRasterWorkspace).OpenRasterDataset("GpOutput.jp2");
IRasterStorageDef sd = new RasterStorageDefClass();

(rds as ISaveAs2).SaveAsRasterDataset("ResultNull.jp2", ws, "JP2", sd);

sd.CompressionType = esriRasterCompressionType.esriRasterCompressionJPEG2000;
sd.CompressionQuality = 50;
(rds as ISaveAs2).SaveAsRasterDataset("Result50.jp2", ws, "JP2", sd);

sd.CompressionQuality = 75;
(rds as ISaveAs2).SaveAsRasterDataset("Result75.jp2", ws, "JP2", sd);


And the results are all the same (and equal to the input). So it looks like SaveAsRasterDataset doesn't do anything with the supplied RasterStorageDef. Has anyone had success with this?
0 Kudos