Select to view content in your preferred language

ArcObjects 10.1, C#, export "Create Steepest Path" output to shapefile

2867
2
Jump to solution
10-15-2013 06:10 AM
MartinGrünig
Deactivated User
Hi
I'm using ArcObjects 10.1 and C# and would like to export the result of the "Create Steepest Path" Tool into a new Shapefile or FeatureClass. I thought that the result of the "Create Steepest Path" Tool is a graphic line which will be stored in ArcMap (ActiveGraphicsLayer). After executing the "Create Steepest Path" Tool a graphic line is created and displayed but the ActiveGraphicsLayer seems to be empty. pElement in the code below, which should contain the graphic line, is empty. Any suggestion?

       // Umwandlung Graphik-Linie in 3D Shape
        public void ConvertGraphicTo3DShape(string aName, string aPath, ESRI.ArcGIS.Carto.IActiveView pActiveView)
        {
            ...

            // Shape WorkspaceFactory
            ESRI.ArcGIS.Geodatabase.IWorkspaceFactory pWSF =
                new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();

            // Workspace
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace pFWS =
                (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)pWSF.OpenFromFile(StrOutPath,0);
           
            // Geometry Typ
            ESRI.ArcGIS.Geometry.esriGeometryType pGeomType =
                esriGeometryType.esriGeometryPolyline;

            // Shape-Datei anlegen (Methode "CreateShape" aus Klasse "CreateShapeFile")
            CreateShapeFile pShape = new CreateShapeFile();
            ESRI.ArcGIS.Geodatabase.IFeatureClass pOutFC =
                pShape.CreateShape(pFWS, aPath, aName, pGeomType, null);

            // Feature Cursor
            ESRI.ArcGIS.Geodatabase.FeatureCursor pFCur =
                (ESRI.ArcGIS.Geodatabase.FeatureCursor)pOutFC.Insert(true);

            // Memory Buffer
            ESRI.ArcGIS.Geodatabase.IFeatureBuffer pFBuff =
                (ESRI.ArcGIS.Geodatabase.IFeatureBuffer)pOutFC.CreateFeatureBuffer();

            // Aktive Karte
            ESRI.ArcGIS.Carto.IMap pMxMap = pActiveView.FocusMap;

            // Graphic Container
            //ESRI.ArcGIS.Carto.IGraphicsContainer pGC = pActiveView.GraphicsContainer;
            ESRI.ArcGIS.Carto.IGraphicsContainer pGC =
                (ESRI.ArcGIS.Carto.IGraphicsContainer)pMxMap;
           
            // Polyline Grafikelemente in die Shape-Datei schreiben
            ESRI.ArcGIS.Carto.IElement pElement =
                (ESRI.ArcGIS.Carto.IElement)pGC.Next();

            while (!(pElement == null))
            {
                if (pElement.Geometry.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
                {
                    pFBuff.Shape = pElement.Geometry;
                    pFCur.InsertRow(pFBuff);
                }
                pElement = pGC.Next();
            }
            pFCur.Flush();

            ...
       }

Thank you for your help.
Martin
0 Kudos
1 Solution

Accepted Solutions
MartinGrünig
Deactivated User
Hi Duncan

Thank you for your precious input. I could solve the problem changing my code as follows (ArcMap.Document.ActiveView and MapClass instead of IActiveView.FocusMap and double-check if the view is the MapView):

...

// ActiveView
ESRI.ArcGIS.Carto.IActiveView pAView = ArcMap.Document.ActiveView;


// Transformation nur in der MapView möglich (nicht in der LayoutView)
            ESRI.ArcGIS.Carto.IMap pMxMap = new MapClass();
            if (pAView is IMap)
            {
               
// Map               
pMxMap = (ESRI.ArcGIS.Carto.IMap)pAView;

               
// Graphics Container
                ESRI.ArcGIS.Carto.IGraphicsContainer pGC =
                    (ESRI.ArcGIS.Carto.IGraphicsContainer)pMxMap;
                pGC.Reset();


// Polyline Grafikelemente in die Shape-Datei schreiben
                ESRI.ArcGIS.Carto.IElement pElement =
                   (ESRI.ArcGIS.Carto.IElement)pGC.Next();

                while (!(pElement == null))
                {
                    if (pElement.Geometry.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
                    {
                        pFBuff.Shape = pElement.Geometry;
                        pFCur.InsertRow(pFBuff);
                    }
                    pElement = pGC.Next();
                }

...

}


Martin

View solution in original post

0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Here are a few ideas to help you debug.

  1. When you create your steepest path line, right click on it and set the Name property to something then when you get a handle on the element see if you can display the name in a message box via the IElementProperties interface? This at least tells you that you managed to get a handle on the graphic element. May be stick some other random graphic on the map with a name?

  2. Is your pActiveView pointing to the map and not page layout?

  3. The IGraphicsContainer is implemented by several classes, map being one of them. The graphic may have ended up being associated with a layer rather than the map , have a look at IGraphicsLayer?

Duncan
0 Kudos
MartinGrünig
Deactivated User
Hi Duncan

Thank you for your precious input. I could solve the problem changing my code as follows (ArcMap.Document.ActiveView and MapClass instead of IActiveView.FocusMap and double-check if the view is the MapView):

...

// ActiveView
ESRI.ArcGIS.Carto.IActiveView pAView = ArcMap.Document.ActiveView;


// Transformation nur in der MapView möglich (nicht in der LayoutView)
            ESRI.ArcGIS.Carto.IMap pMxMap = new MapClass();
            if (pAView is IMap)
            {
               
// Map               
pMxMap = (ESRI.ArcGIS.Carto.IMap)pAView;

               
// Graphics Container
                ESRI.ArcGIS.Carto.IGraphicsContainer pGC =
                    (ESRI.ArcGIS.Carto.IGraphicsContainer)pMxMap;
                pGC.Reset();


// Polyline Grafikelemente in die Shape-Datei schreiben
                ESRI.ArcGIS.Carto.IElement pElement =
                   (ESRI.ArcGIS.Carto.IElement)pGC.Next();

                while (!(pElement == null))
                {
                    if (pElement.Geometry.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
                    {
                        pFBuff.Shape = pElement.Geometry;
                        pFCur.InsertRow(pFBuff);
                    }
                    pElement = pGC.Next();
                }

...

}


Martin
0 Kudos