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
Solved! Go to Solution.
Chris. This is a bug which we are aware of. We will try and fix this for the next release of Pro.
Chris. This is a bug which we are aware of. We will try and fix this for the next release of Pro.
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
Hello Chris,
We can confirm this fix is included with the upcoming Pro 2.2 release.
Many thanks
Chris
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
Prashant
That's very useful. I can work with that. Perhaps a more useful error message in a future build?
Chris
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.
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