AnsweredAssumed Answered

Raster SetWidth not working

Question asked by chrisb_b on Apr 23, 2018
Latest reply on May 30, 2018 by chrisb_b

I'm trying to export (SaveAs) a raster as a TIFF.  Exporting the whole raster works.  Setting the (geographic) extent and exporting works. But setting the Width and Height before exporting only sets teh Height.

This is called from a button AddIn:

System.Uri uri = new Uri("e:\\ESRI_GDB\\Southampton.gdb");

QueuedTask.Run(() =>

   FileGeodatabaseConnectionPath path = new FileGeodatabaseConnectionPath(uri);

   Geodatabase gdb = new Geodatabase(path);

   RasterDataset rasterDataset = gdb.OpenDataset<RasterDataset>("Raster_250");

   Raster raster = rasterDataset.CreateFullRaster();

   SpatialReference spatialReference = SpatialReferenceBuilder.CreateSpatialReference(27700);


   Envelope ext = EnvelopeBuilder.CreateEnvelope(400000, 100000, 450000, 150000, spatialReference); // select an area

   int W = raster.GetWidth(); // original raster is 4040 columns
   int H = raster.GetHeight(); // 3880 rows

   raster.SetWidth(500);   // try to set the size of the output raster

   W = raster.GetWidth(); // still 4040 columns
   H = raster.GetHeight(); // correct at 500 rows

   raster.SetExtent(ext); // select teh geographic area of interest

   FileSystemConnectionPath connectionPath = new FileSystemConnectionPath(new System.Uri(@"C:\Dummy"),    FileSystemDatastoreType.Raster);
   FileSystemDatastore dataStore = new FileSystemDatastore(connectionPath);

   RasterStorageDef rasterStorageDef = new RasterStorageDef();
   rasterStorageDef.SetPyramidLevel(0); // don't want pyramids

   raster.SaveAs("bbtest.tif", dataStore, "TIFF", rasterStorageDef); // creates long thin distorted raster of the correct geographic area


I'm obviously doing something wrong because setting teh raster Width is so simple it shouldn't fail, but I can't for the life of me see what I'm doing wrong.  Can anyone help?


Thanks in advance