IGPUtilities.DecodeRasterLayer() crashes when 2 layers has same name

614
2
02-15-2013 02:21 AM
ØyvindIdland
New Contributor III
I got a case here, where two layers has the same name. One of them is a raster layer, the other one is a feature layer.

The raster layer is a parameter in a GP tool. When using it as an argument in DecodeRasterLayer(),I get an exception with
this message: "HRESULT E_FAIL has been returned from a call to a COM component"

This happens only if I run the tool as a background process. Otherwise, it works fine.

Before calling DecodeRasterLayer(), I yield the layer data type via AddMessage(). In both cases (background and foreground),
I get correct datatype (Name = "GPRasterLayer", DisplayName = "Raster Layer").

Its probably not a good practice to have duplicate layer names, but what users do is outside my control..

Is there something that can be done here ? (Except loop through the layers and look for duplicate names,
and then quit the tool with a a message that tells the user to rename the layer..
)

- Oyvind
0 Kudos
2 Replies
AlexanderGray
Occasional Contributor III
It depends on your application but you should be able to pass the data source (full path to raster or raster object) to the GP tool as an alternative to the layer name.  More of a workaround than a solution.
0 Kudos
ØyvindIdland
New Contributor III
It depends on your application but you should be able to pass the data source (full path to raster or raster object) to the GP tool as an alternative to the layer name.  More of a workaround than a solution.


Yep, that is already an option 🙂
The user can select either a raster layer or a physical file from disk.

I added a check for duplicates in UpdateMessages() (in case the param type is a layer), so they have to rename the layer before executing the tool.

- Oyvind
0 Kudos