How to Add layers with Python

1024
5
08-19-2012 09:08 AM
Angel_ReynaldoCardenas_Huerta
New Contributor
how I do this in python

this is in VBA

Public Sub AddLayer() 'adiciona el layer al map
GetT
  'Open Feature Class
  Set pWorkFact = New AccessWorkspaceFactory
  If sPathBase = "" Then
    Exit Sub
  Else
  Set pFWorkspace = pWorkFact.OpenFromFile(sPathBase, 0)
  End If
  Set pFeatureClass = pFWorkspace.OpenFeatureClass(sql)
  'Create new layer
  Set pFeatureLayer = New FeatureLayer
  Set pFeatureLayer.FeatureClass = pFeatureClass

pFeatureLayer.Name = FRBROW.ComboBox1.Value & " - " & FRBROW.ComboBox2.Value
  'Add layer to map
  Set pDoc = ThisDocument
  Set pMap = pDoc.FocusMap
  Set pActiveView = pMap
  pMap.AddLayer pFeatureLayer
  pActiveView.Refresh
End Sub
Tags (2)
0 Kudos
5 Replies
GraemeBrowning
Occasional Contributor III
A good starting point for this is the AddLayer documentation along with the RefreshActiveView documentation.

If you start with those examples, and don't get all the way to a solution, then post your "code so far" to elicit help to finish it off.

- Graeme
0 Kudos
MarcinGasior
Occasional Contributor III
0 Kudos
Angel_ReynaldoCardenas_Huerta
New Contributor
thank you very much for your answers Graeme and Marcin , achieve load the feature class to ArcMap, but I had a problem, and it will not let me upload it again because I created entities, which can not be repeated, the code I use is

arcpy.makefeaturelayer_management ("path or featureclass", "alias")

there is another way to do this without my block to add again the same featureclass?

the other inconsistency I had is that I arcgis10 hangs, and the program runs only a short time within ArcMap

a query, how I would spend my VBA code to. NET and then load it as dll or tlb?

thanks in advance

Angel Cardenas
0 Kudos
GraemeBrowning
Occasional Contributor III
Don't be afraid to thank us by upvoting our contributions 😉

Without seeing your code and any errors it generates it is hard to be sure what your block may be.

However, I would think that you only need to do MakeFeatureLayer on a particular Feature Class once and then to use SelectLayerByAttributes and SelectLayerByLocation with the selection type set to "CLEAR_SELECTION" in between each issuance to do repeated selections on the same Feature Class via its Feature Layer.

- Graeme
0 Kudos
Angel_ReynaldoCardenas_Huerta
New Contributor
thanks for your prompt reply Graeme, blocking is that I can not add more featureclass again, either by script or by ArcCatalog, the erro is, existing entity ("featureclass alias name")

There is another way to add without my block to add the same again?

thanks in advance

Angel Cardenas
0 Kudos