Select to view content in your preferred language

ISaveAs GeoTIFF and Georeference information

763
5
09-30-2010 01:51 PM
DavidZwarg
Emerging Contributor
Hello,

I am attempting to run some geoprocessing on a raster, then save the result to a GeoTIFF.  I do this in ArcObjects by using ISaveAs on an IGeoDataset:

IWorkspace rws = null;
try {
  rws = (IWorkspace)SetRasterWorkspace(path);
  ISaveAs saveMe = (ISaveAs)raster;
  saveMe.SaveAs( name, rws, "TIFF" );
}
finally {
  COMHelper.SafeRelease(rws);
}


HOWEVER, this does not save the Spatial Reference or Georeference information in the GeoTIFF.  This is extremely frustrating, because if I copy a raster from GRID to TIF, the georeference gets saved with the GeoTIFF.  If I inspect my raster variable from the above, I can find a temporary location of the raster with the following command in my VS-2008 'Immediate Window':

((IRaster2)raster).RasterDataset

{System.__ComObject}
    [System.__ComObject]: {System.__ComObject}
    CompleteName: "C:\\Documents and Settings\\STANDARD\\ASPNET\\Local Settings\\Temp\\raster3"
    CompressionType: "Default"
    Format: "GRID"
    SensorType: "Map Info"



And this is a GRID, with a Spatial Reference and the Georeference information intact.  If this is the case, why does it get lost in the ISaveAs operation?  Is there any way (in ArcObjects) to COPY this temporary raster to a GeoTIFF, instead of SaveAs, so I can preserve the Spatial Reference and Georeference information?

Please advise,
David
0 Kudos
5 Replies
RobertBerger
Occasional Contributor
Hi David,

In general, when the input raster has a set spatial reference, then the saveas will honor that. Does you input grid have a spatial reference, you just open it, and then saveas tiff or do you apply the spatial reference (or transformation) yourself?
There are some help topics regarding doing the transformations through code: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_perform_a_geodat...
Also, if you're changing the spatial reference, consider doing this on the RasterBandCollection:
RasterBandCollection = RasterDataset.CreateFullRaster
RasterProps = RasterBandCollection
RasterProps.SpatialReference = YourNewSpatialReference
RasterBandCollection.SaveAs

Hope this helps.

Robert
0 Kudos
DavidZwarg
Emerging Contributor
Hello Robert,

Thanks for your reply.

My 'starting' raster is an elevation GeoTIFF with spatial and georeference properties set.  I perform a Hillshade operation (ISurfaceOp.HillShade) and generate a hillshade raster.  I save the generated hillshade raster as a GeoTIFF.

I do not apply the spatial reference myself; I assumed that if the input raster dataset had these properties set, the output raster dataset would have these properties set.

Any ideas?
David
0 Kudos
RobertBerger
Occasional Contributor
Hi David,

How do you move from the GeoDataset to the Raster? Is there a reason you go down to the raster rather than the RasterDataset? I agree with you, the GeoDataset from the hillshade op should continue to have a spatial reference, and saveAs should persist that without issues.

Robert
0 Kudos
DavidZwarg
Emerging Contributor
Hello Robert,

My procedure is as follows:

  1. Set an input RasterWorkspace

  2. Open a RasterDataset from workspace

  3. Cast RasterDataset to IGeoDataset

  4. Perform SurfaceOp.Hillshade

  5. Set an output RasterWorkspace

  6. Cast IGeoDataset to ISaveAs2

  7. Call SaveAs() on the ISaveAs2, with the output workspace, and format of "TIFF"


I'll do some testing to see if using the RasterBandCollection.SaveAs is any different.

David
0 Kudos
DavidZwarg
Emerging Contributor
Update:

The georeference information is lost when calling the save methods in the ASPNET worker process (within a web service), but preserved when calling the save methods from the command line.

The mystery deepens...
0 Kudos