This document is archived and information here might be outdated. Recommended version. |
Generate a diagram from features selected in a geographic map
/// <summary> /// Generate a diagram from features selected in a geographic map /// </summary> /// <param name="pMap">Geographic map containing the input selected GIS features</param> /// <param name="schemDiagClass">SchematicDiagramClass; that is, diagram template on which the generated diagram is based</param> /// <param name="schemDiagramContainer">SchematicDiagramContainer where the generated diagram will be stored</param> /// <param name="DiagramName">Name for the generated diagram</param> /// <returns>ESRI.ArcGIS.Schematic.ISchematicDiagram</returns> ///<remarks></remarks> public ESRI.ArcGIS.Schematic.ISchematicDiagram GenerateDiagramFromMap(ESRI.ArcGIS.Carto.IMap pMap, ESRI.ArcGIS.Schematic.ISchematicDiagramClass schemDiagClass, ESRI.ArcGIS.Schematic.ISchematicDiagramContainer schemDiagramContainer, string DiagramName) { // if DiagramName is empty exit if (DiagramName.Length == 0) return null; // cast SchematicDiagramClass into ISchematicBuilder ESRI.ArcGIS.Schematic.ISchematicBuilder schBuilder=(ESRI.ArcGIS.Schematic.ISchematicBuilder)schemDiagClass; // create the ISchematicStandardBuilderContext Type objectType=Type.GetTypeFromProgID("esriSchematic.SchematicStandardBuilderContext"); // if objectType is null, the BuilderContext cannot be created, then exit if (objectType == null) return null; ESRI.ArcGIS.Schematic.ISchematicStandardBuilderContext schBuilderCtxt; schBuilderCtxt=Activator.CreateInstance(objectType) as ESRI.ArcGIS.Schematic.ISchematicStandardBuilderContext; // get the selected features in the map ESRI.ArcGIS.Geodatabase.IEnumFeature enumFeature=(ESRI.ArcGIS.Geodatabase.IEnumFeature)pMap.FeatureSelection; // initialize the ISchematicStandardBuilderContext with the selection set schBuilderCtxt.InitialObjects=new EnumSchematicObject(enumFeature); // generate the schematic diagram ESRI.ArcGIS.Schematic.ISchematicDiagram GeneratedDiagram=schBuilder.GenerateDiagram(DiagramName, schemDiagramContainer, null, (ESRI.ArcGIS.Schematic.ISchematicBuilderContext)schBuilderCtxt, null); return GeneratedDiagram; } public class EnumSchematicObject : ESRI.ArcGIS.Geodatabase.IEnumObject { private ESRI.ArcGIS.Geodatabase.IEnumFeature m_pIEnumFeature; public EnumSchematicObject(ESRI.ArcGIS.Geodatabase.IEnumFeature pEnumFeature) { m_pIEnumFeature=pEnumFeature; } public ESRI.ArcGIS.Geodatabase.IObject Next() { if (m_pIEnumFeature != null) return (ESRI.ArcGIS.Geodatabase.IObject)m_pIEnumFeature.Next(); else return null; } public void Reset() { if (m_pIEnumFeature != null) m_pIEnumFeature.Reset(); } }
''' <summary> ''' Generate a diagram from features selected in a geographic map ''' </summary> ''' <param name="pMap">Geographic map containing the input selected GIS features</param> ''' <param name="schemDiagClass">SchematicDiagramClass; that is, diagram template on which the generated diagram is based</param> ''' <param name="schemDiagramContainer">SchematicDiagramContainer where the generated diagram will be stored</param> ''' <param name="DiagramName">Name for the generated diagram</param> ''' <returns>The generated ESRI.ArcGIS.Schematic.ISchematicDiagram</returns> Public Function GenerateDiagramFromMap(ByVal pMap As ESRI.ArcGIS.Carto.IMap, ByVal schemDiagClass As ESRI.ArcGIS.Schematic.ISchematicDiagramClass, ByVal schemDiagramContainer As ESRI.ArcGIS.Schematic.ISchematicDiagramContainer, ByVal DiagramName As String) As ESRI.ArcGIS.Schematic.ISchematicDiagram ' if DiagramName is empty exit If (DiagramName.Length=0) Then Return Nothing ' cast SchematicDiagramClass into ISchematicBuilder Dim schBuilder As ESRI.ArcGIS.Schematic.ISchematicBuilder=TryCast(schemDiagClass, ESRI.ArcGIS.Schematic.ISchematicBuilder) ' create the ISchematicStandardBuilderContext Dim objectType As Type=Type.GetTypeFromProgID("esriSchematic.SchematicStandardBuilderContext") ' if objectType is nothing, the BuilderContext cannot be created, then exit If (objectType Is Nothing) Then Return Nothing Dim schBuilderCtxt As ESRI.ArcGIS.Schematic.ISchematicStandardBuilderContext schBuilderCtxt=TryCast(Activator.CreateInstance(objectType), ESRI.ArcGIS.Schematic.ISchematicStandardBuilderContext) ' get the selected features in the map Dim enumFeature As ESRI.ArcGIS.Geodatabase.IEnumFeature=TryCast(pMap.FeatureSelection, ESRI.ArcGIS.Geodatabase.IEnumFeature) ' initialize the ISchematicStandardBuilderContext with the selection set schBuilderCtxt.InitialObjects=New EnumSchematicObject(enumFeature) ' generate the schematic diagram Return schBuilder.GenerateDiagram(DiagramName, schemDiagramContainer, Nothing, TryCast(schBuilderCtxt, ESRI.ArcGIS.Schematic.ISchematicBuilderContext), Nothing) End Function Public Class EnumSchematicObject Implements ESRI.ArcGIS.Geodatabase.IEnumObject Private m_pIEnumFeature As ESRI.ArcGIS.Geodatabase.IEnumFeature Public Sub New(ByVal pEnumFeature As ESRI.ArcGIS.Geodatabase.IEnumFeature) m_pIEnumFeature=pEnumFeature End Sub Public Function [Next]() As ESRI.ArcGIS.Geodatabase.IObject Implements ESRI.ArcGIS.Geodatabase.IEnumObject.Next If (m_pIEnumFeature IsNot Nothing) Then Return TryCast(m_pIEnumFeature.Next(), ESRI.ArcGIS.Geodatabase.IObject) Else Return Nothing End If End Function Public Sub Reset() Implements ESRI.ArcGIS.Geodatabase.IEnumObject.Reset If (m_pIEnumFeature IsNot Nothing) Then m_pIEnumFeature.Reset() End Sub End Class