Sunday, 17 June 2018

arcgis desktop - Repointing Datasource of layers using ArcObjects


I'm currently working on a ArcObjects C# project that will repoint datasources for layers of various types. Basically a database is maintained that holds the old datasource connections and the new connections. When the user presses a button, the application goes through all the current layers in ArcDesktop and compares the layers current datasource with the new one. If there is a difference, it resets the datasource.


However, I'm not quite sure how to access the datasource, and in my perusings of this stackexchange, I noticed someone who was working on something similar, but they were using raster layers. I'm not too familiar with ArcGIS and didn't know if I needed to handle feature layers differently as he mentions he already found a solution for feature layers.


Here's the section I'm trying to change in ArcDesktop:enter image description here


I have everything working just fine except the changing of those datasources. I found this resource on arcgis, but it doesn't appear to change those strings, though I could be mistaken.


This is what I currently have:


//Loop through all layers and get their information

pEnumLayer.Reset();
pLayer = pEnumLayer.Next();
while (pLayer != null)
{
Log.Debug("Manipulating the layer: " + pLayer.Name);
IDataLayer dataLayer = (IDataLayer)pLayer;
var datasource = dataLayer.DataSourceName; // this is what I believe to be the current datasource

Log.Debug("Repaired layer: " + pLayer.Name);
pLayer = pEnumLayer.Next();

}

Is that the correct datasource I'm looking for? If so, would all I need to do to change the datasource is to set that variable to the new datasource string and then redraw the map?



Answer



Esri's online help, there are examples of this problem, you can refer to this example.


URL: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//00490000002r000000


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...