Raster SetWidth not working

225
8
Jump to solution
04-23-2018 08:38 AM
Highlighted
New Contributor

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);

   raster.SetSpatialReference(spatialReference);

   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
   raster.SetHeight(500);

   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

Chris

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Contributor

Chris. This is a bug which we are aware of. We will try and fix this for the next release of Pro.

View solution in original post

Reply
0 Kudos
8 Replies
Highlighted
Esri Contributor

Chris. This is a bug which we are aware of. We will try and fix this for the next release of Pro.

View solution in original post

Reply
0 Kudos
Highlighted
New Contributor

Prashant

Many thanks.  I’ll stop beating my head against it until 2.2 comes out.  As a work-around, is there any way of specifying the Pyramid layer that the Raster is to use?  If so I could use set the Extent and then use PixelBlocks to pull out the pixels at the resolution I need.

As a side note, are you aware that if you try to export (SaveAs) the raster using JPG rather than TIFF the call returns a ‘Feature has empty geometry’ error?

Chris

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hello Chris, 

We can confirm this fix is included with the upcoming Pro 2.2 release.

Reply
0 Kudos
Highlighted
New Contributor

Many thanks

Chris

Reply
0 Kudos
Highlighted
Esri Contributor

Chris,

Regarding the below, JPEG only supports 8bit so if you use it for bit depths other than 8bit then you will get the below error.

"As a side note, are you aware that if you try to export (SaveAs) the raster using JPG rather than TIFF the call returns a ‘Feature has empty geometry’ error?"

-Prashant

Reply
0 Kudos
Highlighted
New Contributor

Prashant

That's very useful.  I can work with that.  Perhaps a more useful error message in a future build?

Chris

Reply
0 Kudos
Highlighted
Esri Contributor

Hi @Prashant Mukesh Mangtani,

I can manage to save width, height, extent with save as in 2.4.

But somehow it change the cell size Y. 

Example , original cell size is 299.463 for X, Y. after setting width/height/extent save as another set. 

Cell size become X => 299.463 and Y =>  28291.448382

Have tried with  rasterDataset.CreateDefaultRaster(); and  rasterDataset.CreateFullRaster();

What could be the issue?

Have attached the result raster files as well.

Reply
0 Kudos
Highlighted
Esri Contributor

Than,

After you set extent and height, if your new extent is different or your new height is different that will account for the change in Y cell size, i.e. (XMax-XMin)/Height = CellSize Y.

Is what you are seeing not following these rules? Another thing to check if when you set the extent and height if its actually correctly being set. Try getting right after or debug through to see if its correctly set.

-Prashant

Reply
0 Kudos