Esempio n. 1
0
        internal void addFeatureClassToMapAsLayer(ref IFeatureClass fc, string LayerName)
        {
            try
            {
                // define a new layer for the asset catalog
                IFeatureLayer player = new FeatureLayer();
                player.FeatureClass = fc;
                player.Name         = LayerName;

                // TODO: Specifically set the Spatial Reference

                //Create a GxLayer to stylize the layer.
                ESRI.ArcGIS.Catalog.IGxLayer gxLayerCls = new ESRI.ArcGIS.Catalog.GxLayer();
                ESRI.ArcGIS.Catalog.IGxFile  gxFile     = (ESRI.ArcGIS.Catalog.IGxFile)gxLayerCls;
                //Explicit Cast.

                // create an assembly file object to determine where on the system this is running
                log.Debug("Attempting to locate the executing extension assembly.");
                Uri assemblyUri = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
                System.IO.FileInfo assemblyFileInfo
                    = new System.IO.FileInfo(Path.GetDirectoryName(assemblyUri.LocalPath));
                log.Debug("Executing from: " + assemblyFileInfo.FullName);

                //Set the path for where the layer file is located on disk.
                gxFile.Path = assemblyFileInfo.FullName + @"\GME_Catalog_Style.lyr";
                log.Debug("lyr Path: " + gxFile.Path);

                // validate the symbology layers exist
                if (!(gxLayerCls.Layer == null))
                {
                    // create a geo feature layer for the master symbology
                    IGeoFeatureLayer symbologyGeoFeatureLayer = gxLayerCls.Layer as IGeoFeatureLayer;

                    // create a geo feature layer for the new features
                    IGeoFeatureLayer pGeoFeatureLayer = player as IGeoFeatureLayer;

                    // apply the renderer from the template to the new feature layer
                    pGeoFeatureLayer.Renderer = symbologyGeoFeatureLayer.Renderer;
                }

                // add the layer to the map
                m_map.AddLayer(player);
            }
            catch (System.Exception ex)
            {
                // an error occured
                log.Error(ex);
                System.Windows.Forms.MessageBox.Show("Unable to add feature class to the map.");
            }
        }
Esempio n. 2
0
        internal static ILayer OpenLayerFile(string path)
        {
            // Create a new GxLayer
            ESRI.ArcGIS.Catalog.IGxLayer gxLayer = new ESRI.ArcGIS.Catalog.GxLayerClass();

            ESRI.ArcGIS.Catalog.IGxFile gxFile = (ESRI.ArcGIS.Catalog.IGxFile)gxLayer; //Explicit Cast

            // Set the path for where the layerfile is located on disk
            gxFile.Path = path;


            if (!(gxLayer.Layer == null))
            {
                return(gxLayer.Layer);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        internal void addFeatureClassToMapAsLayer(ref IFeatureClass fc, string LayerName, string whereClause)
        {
            try
            {
                // define a new layer for the asset catalog
                IFeatureLayer player = new FeatureLayer();
                player.FeatureClass = fc;
                player.Name         = LayerName;

                // TODO: Specifically set the spatial reference

                // Set up the query
                ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
                queryFilter.WhereClause = whereClause;

                // create a feature selection object
                ESRI.ArcGIS.Carto.IFeatureSelection featureSelection
                    = player as ESRI.ArcGIS.Carto.IFeatureSelection; // Dynamic Cast

                // Perform the selection
                featureSelection.SelectFeatures(queryFilter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew, false);

                //Create a GxLayer to stylize the layer.
                ESRI.ArcGIS.Catalog.IGxLayer gxLayerCls = new ESRI.ArcGIS.Catalog.GxLayer();
                ESRI.ArcGIS.Catalog.IGxFile  gxFile     = (ESRI.ArcGIS.Catalog.IGxFile)gxLayerCls;
                //Explicit Cast.

                // create an assembly file object to determine where on the system this is running
                log.Debug("Attempting to locate the executing extension assembly.");
                Uri assemblyUri = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
                System.IO.FileInfo assemblyFileInfo
                    = new System.IO.FileInfo(Path.GetDirectoryName(assemblyUri.LocalPath));
                log.Debug("Executing from: " + assemblyFileInfo.FullName);

                //Set the path for where the layer file is located on disk.
                gxFile.Path = assemblyFileInfo.FullName + "\\GME_Catalog_Style.lyr";
                log.Debug("lyr Path: " + gxFile.Path);

                // validate the symbology layers exist
                if (!(gxLayerCls.Layer == null))
                {
                    // create a geo feature layer for the master symbology
                    IGeoFeatureLayer symbologyGeoFeatureLayer = gxLayerCls.Layer as IGeoFeatureLayer;

                    // create a geo feature layer for the new features
                    IGeoFeatureLayer pGeoFeatureLayer = player as IGeoFeatureLayer;

                    // apply the renderer from the template to the new feature layer
                    pGeoFeatureLayer.Renderer = symbologyGeoFeatureLayer.Renderer;
                }

                // add the layer to the map
                m_map.AddLayer(player);

                // Flag the new selection
                ArcMap.Document.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);

                // manually trigger the selection has changed event to determine if the buttons should re-enable
                ArcMap_SelectionChanged();
            }
            catch (System.Exception ex)
            {
                // an error occured
                log.Error(ex);
                System.Windows.Forms.MessageBox.Show("Unable to add feature class to the map.");
            }
        }