Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have the code that gets the layers from SDE, but when i add them to the map they have a different symbology. there is about 80 layers and i am accessing the SDE by getting the workspace from a selected layer in the TOC. The symbology renderer layer files are located in a directory. So all i want to do is loop through the directory and get the renderer for each layer in my list. But my code only gets the renderer for 1 file not for all? How can i compare feature class names so it van get the renderer for each layer by using the feature class name?? I appreciate your time and any ideas.

Public Sub AddSDECoverageLayer()

Dim pMxDoc As IMxDocument
Dim pMap As IMap

Set pMxDoc = ThisDocument

 Dim intX As Integer

'Add each FeatureLayer to the map document
'This should assign layer names to the layer it gets from SDE
'But it only gives the first layer in the list a layer name. 
'There is about 80 layers so cant do if statement 80 time
'What other way can i do this?? 

For intX = 0 To ListBox2.ListCount - 1

       Dim xsClass As String
       xsClass = ListBox2.List(intX)
       Dim xs As String
       If xsClass = "PROPERTY_ADMIN.topo_ownership" Then
       xs = "MM Ownership"
       End If
       If xs = "PROPERTY_ADMIN.MM_Rights_of_Way" Then
       xs = "Rights of way"
       End If

      Dim pFLayerXS As IFeatureLayer

      Set pFLayerXS = importData(pFWorkspace, xsClass, xs)

      pMxDoc.FocusMap.AddLayer pFLayerXS



End Sub


Public Function importData(pWorkspace As IWorkspace, FClass As String, fcName As      String) As IFeatureLayer

'Function to create Feature layer from Feature class
Dim pFeatureWorkspace As IFeatureWorkspace
Dim pFClass As IFeatureClass
Dim pUnknown As IUnknown
Dim pMxDoc As IMxDocument
Dim pFeatureLayer As IFeatureLayer
Dim pDataSet As IDataset
Dim pFLayer As IFeatureLayer

 ' Get the selected layer
Set pMxDoc = ThisDocument
Set pUnknown = pMxDoc.SelectedLayer 'pMxDoc.FocusMap.Layer(0)
 If Not TypeOf pUnknown Is IFeatureLayer Then
 Exit Function
End If
Set pFLayer = pUnknown

' Make sure the layer is from SDE and get the parent workspace
Set pDataSet = pFLayer.FeatureClass

Set pFWorkspace = pDataSet.workspace
Set pWorkspace = pFWorkspace
If Not pWorkspace.Type = esriRemoteDatabaseWorkspace Then
MsgBox "Not an SDE feature class"
Exit Function
End If
Set pDataSet = pWorkspace

Set pFeatureWorkspace = pWorkspace
Dim intY As Integer
For intY = 0 To ListBox2.ListCount - 1
Set pFClass = pFeatureWorkspace.OpenFeatureClass _

Set pFLayer = New FeatureLayer
Set pFLayer.FeatureClass = pFClass

Dim pGFLayer As IGeoFeatureLayer
Set pGFLayer = pFLayer

Dim intz As Integer
For intz = 0 To ListBox2.ListCount - 1

'This gets the renderer but only for one layer, 
'How can i make it get the renderer for all the layers in the list.
'There is 80 layers, in a directory. i just need to assign the renderer
'from this directoryto eac item in the list box

If ListBox2.List(intz) = "PROPERTY_ADMIN.topo_ownership" Then
  Set pGFLayer.Renderer = GetRenderer("V:\Arc\Layers\MM Ownership.lyr")

  End If
  If ListBox2.List(intz) = "PROPERTY_ADMIN.MM_Rights_of_Way" Then
  Set pGFLayer.Renderer = GetRenderer("V:\Arc\Layers\MM Rights of Way.lyr")
End If

 pFLayer.Name = fcName

Set importData = pFLayer

Exit Function

End Function
share|improve this question
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.