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");
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
Solved! Go to Solution.
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?
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?"
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.
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.