How to add Raster Mosaic to Map from Enterprise GDB (PRO SDK)

722
3
Jump to solution
06-11-2018 12:28 PM
DevonCanady
New Contributor II

I am able to connect to an sde geodatabase and obtain a handle on a raster dataset, but I can't figure out how to add this dataset to my map. I don't see how I would use a Uri since it doesn't exist in a file, and I don't know how to obtain an Item or CIMDataconnection from a RasterDataset type - since these are the three data types allowed in LayerFactory.Instance.CreateMosaicLayer().

var connectionProps = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
{
    AuthenticationMode = AuthenticationMode.OSA,
    Instance = "instance",
    Database = "sdeDOQTX1996",
};
var doq96GDB = new Geodatabase(connectionProps);
var doqDataset = doq96GDB.OpenDataset<RasterDataset>("sdeDOQTX1996.DBO.Zone14_mosaic");

//LayerFactory.Instance.CreateMosaicLayer(?, map, 0);
0 Kudos
1 Solution

Accepted Solutions
Prashant_MukeshMangtani
Esri Contributor

Devon,

That is a good question. You don't need the raster dataset object to create a layer, you have all the information you need before that step already. Once you have a geodatabase object, you can create a CIMStandardDataConnection object using it and then use that to create a mosaic layer. Sample code below.

// Create the data connection object.

string workspaceConnectionString = geodatabase.GetConnectionString();
CIMStandardDataConnection dataConnection = new CIMStandardDataConnection();
// Setup the data connection object.
dataConnection.WorkspaceFactory = WorkspaceFactory.SDE;
dataConnection.WorkspaceConnectionString = workspaceConnectionString;

dataConnection.DatasetType = esriDatasetType.esriDTMosaicDataset;
dataConnection.Dataset = "sdeDOQTX1996.DBO.Zone14_mosaic";

// Create the layer.
rasterLayer = (MosaicLayer)LayerFactory.Instance.CreateLayer(dataConnection, map);

You can create a raster, mosaic or image service layer using the CreateLayer method.

Hope that helps.

-Prashant

View solution in original post

0 Kudos
3 Replies
Prashant_MukeshMangtani
Esri Contributor

Devon,

That is a good question. You don't need the raster dataset object to create a layer, you have all the information you need before that step already. Once you have a geodatabase object, you can create a CIMStandardDataConnection object using it and then use that to create a mosaic layer. Sample code below.

// Create the data connection object.

string workspaceConnectionString = geodatabase.GetConnectionString();
CIMStandardDataConnection dataConnection = new CIMStandardDataConnection();
// Setup the data connection object.
dataConnection.WorkspaceFactory = WorkspaceFactory.SDE;
dataConnection.WorkspaceConnectionString = workspaceConnectionString;

dataConnection.DatasetType = esriDatasetType.esriDTMosaicDataset;
dataConnection.Dataset = "sdeDOQTX1996.DBO.Zone14_mosaic";

// Create the layer.
rasterLayer = (MosaicLayer)LayerFactory.Instance.CreateLayer(dataConnection, map);

You can create a raster, mosaic or image service layer using the CreateLayer method.

Hope that helps.

-Prashant

0 Kudos
DevonCanady
New Contributor II

Great, thanks! I just couldn't find any docs on how to use a CIMDataConnection.

0 Kudos
DrewDowling
Occasional Contributor III

I had a similar issue trying to add a table with geometry from a non SDE database. I found that after I had a refrence to the table I could call  the GetDataConnection method and it worked.

Here is my code in case it helps others.

                DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.Hana)
                {
                    AuthenticationMode = AuthenticationMode.DBMS,
                    Instance = @"mydbinstance",
                    User = "username",
                    Password ="*****"
                };
                using (Database db = new Database(connectionProperties))
                {
                    QueryDescription qds = db.GetQueryDescription(" select GEF_OBJECTID, GEF_OBJKEY, OBJNR, ERNAM, ERDAT, KTEXT, IDAT2, AENAM, ARTPR, GEF_SHAPE from schema.tablename", "MySelect");
                    Table pTab = db.OpenTable(qds)
                    FeatureLayer pFL = (FeatureLayer) LayerFactory.Instance.CreateLayer(pTab.GetDataConnection(), MapView.Active.Map, 0);

                }

devonc1301 wrote:

I am able to connect to an sde geodatabase and obtain a handle on a raster dataset, but I can't figure out how to add this dataset to my map. I don't see how I would use a Uri since it doesn't exist in a file, and I don't know how to obtain an Item or CIMDataconnection from a RasterDataset type - since these are the three data types allowed in LayerFactory.Instance.CreateMosaicLayer().

 

var connectionProps = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
{
    AuthenticationMode = AuthenticationMode.OSA,
    Instance = "instance",
    Database = "sdeDOQTX1996",
};
var doq96GDB = new Geodatabase(connectionProps);
var doqDataset = doq96GDB.OpenDataset<RasterDataset>("sdeDOQTX1996.DBO.Zone14_mosaic");

//LayerFactory.Instance.CreateMosaicLayer(?, map, 0);
0 Kudos