0

I have a CostDistanceCode that works correctly. I cannot cast the IGeoDataset result into a raster. The last line returns a null raster. How can I resolve this?

            // Declare the output raster object
            //Note: Adjust the IDistanceOp.CostDistance method options to suit your applications need.         
            IDistanceOp distanceOp = new RasterDistanceOpClass();
            object object_missing1 = System.Type.Missing;
            object object_missing2 = System.Type.Missing;

            IFeatureClass in_source_Featuer2 = null;
            ClsGeneral.OpenFeatureClass(cmbSource.SelectedValue.ToString(), cmbSource.Text, out in_source_Featuer2);

            IRaster backlinkraster = new Raster();
            IGeoDataset g1 = in_source_Featuer2 as IGeoDataset;
            IGeoDataset g2 = rasOut as IGeoDataset;

            IGeoDataset geoDataset_output = distanceOp.CostDistance(g1, g2, ref object_missing1, ref object_missing2);
            IRasterDataSet raster_out = geoDataset_output  as IRasterDataSet ;
1
  • Did you try casting it to an IRaster instead of an IRasterDataSet ? Dec 1 '15 at 23:36
2

According to the API CostDistance() returns a Raster object which is a "a transient representation of raster data ". If you want to persist this object you should be able to save it to a RasterDataset using the ISaveAs2 interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.