#1 Thu 07 April 2005 09:16
- Dedieu64
- Invité
ArcMap - Programme qui ajoute un shapefile ?
Bonjour,
Je suis etudiant et je voudrais connaitre le script sous Visual Basic pour ArcMap (de ArcGis) me permettant d'ajouter un shapefile sur une carte....
Merci de votre aide.
je me suis inspire de ca mais c'est pour ajouter un *.lyr, mais je voudrais pouvoir ajouter un *.shp:
Code:
Public Sub AddLayerFileToMap() Dim filePath As String filePath = D:..... *.lyr Dim pGxLayer As IGxLayer Dim pGxFile As IGxFile Set pGxLayer = New GxLayer Set pGxFile = pGxLayer pGxFile.Path = filePath Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument pMxDoc.FocusMap.AddLayer pGxLayer.Layer End Sub
#2 Thu 07 April 2005 09:16
- ODevArc
- Invité
Re: ArcMap - Programme qui ajoute un shapefile ?
Bonjour,
Dans l'aide ArcObject on trouve cela : Add a Shapefile Programmatically
Description:
This sampleadds a shapefile to the focus map.
How to use:
1. Paste the code into VBA.
2. Modify the code to point to a shapefile on your system.
3. Run the routine from the Macros dialog.
Code:
Public Sub AddShapeFile()
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pFeatureWorkspace As IFeatureWorkspace
Dim pFeatureLayer As IFeatureLayer
Dim pMxDocument As IMxDocument
Dim pMap As IMap
'Create a new ShapefileWorkspaceFactory object and open a shapefile folder
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile( c:arcgisarcexe82ArcObject Developer KitDataWorld , 0)
'Create a new FeatureLayer and assign a shapefile to it
Set pFeatureLayer = New FeatureLayer
Set pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass("Country")
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName
'Add the FeatureLayer to the focus map
Set pMxDocument = Application.Document
Set pMap = pMxDocument.FocusMap
pMap.AddLayer pFeatureLayer
End SubCela semble correspondre a ce que vous cherchez a faire.
Olivier
#3 Thu 07 April 2005 09:16
- Mathias
- Invité
Re: ArcMap - Programme qui ajoute un shapefile ?
Bonjour,
Peut etre avec ca :
Code:
' Ajout d'une couche SHP a la carte ' IN : ShpPath : Chemin complet du doccier ex : h:Temp ' ShpName : Nom de la couche ex : monshape.shp Public Sub Addshapelayer(ShpPath As String, ShpName As String) Debug.Print EXECUTION de AddShapeLayer ' declaration du document Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument ' declaration de l'espace de travail : shape Dim pWorkspaceFactory As IWorkspaceFactory Set pWorkspaceFactory = New ShapefileWorkspaceFactory ' ouverture de l'espace de travail Dim pWorkspace As IFeatureWorkspace ' path du dossier Set pWorkspace = pWorkspaceFactory.OpenFromFile(ShpPath, 0) ' ouverture du shape Dim pClass As IFeatureClass 'nom de la couche Set pClass = pWorkspace.OpenFeatureClass(ShpName) ' declaration d'une couche d'entite Dim pLayer As IFeatureLayer Set pLayer = New FeatureLayer ' affectation du shape a cette couche Set pLayer.FeatureClass = pClass pLayer.Name = pClass.AliasName '-affichage de cette couche pMxDoc.AddLayer pLayer ' reactualisation de l'affichage pMxDoc.ActiveView.PartialRefresh esriViewGeography, pLayer, Nothing End Sub
Cordialement
Mathias


