Exemple #1
0
        public static void OpenFeatureClass(AxMapControl MapControl,
                                            IFeatureClassName pFcName, ListView listview1)
        {
            try
            {
                MapControl.Map.ClearLayers();
                MapControl.SpatialReference = null;
                IName         pName = pFcName as IName;
                IFeatureClass pFc   = pName.Open() as IFeatureClass;

                listview1.Items.Clear();
                listview1.Columns.Clear();
                LoadListView(pFc, listview1);

                IFeatureCursor pCursor = pFc.Search(null, false);
                IFeature       pfea    = pCursor.NextFeature();
                int            j       = 0;
                while (pfea != null)
                {
                    ListViewItem lv = new ListViewItem();

                    for (int i = 0; i < pfea.Fields.FieldCount; i++)
                    {
                        string sFieldName = pfea.Fields.get_Field(i).Name;
                        lv.SubItems.Add(FeatureHelper.GetFeatureValue(pfea, sFieldName).ToString());
                    }

                    lv.Tag = pfea;
                    if (j % 2 == 0)
                    {
                        lv.BackColor = System.Drawing.Color.GreenYellow;
                    }
                    listview1.Items.Add(lv);
                    pfea = pCursor.NextFeature();
                    j++;
                }
                LSGISHelper.OtherHelper.ReleaseObject(pCursor);
                //最后加载图形数据


                if (pFcName.FeatureType == esriFeatureType.esriFTRasterCatalogItem)
                {
                    ESRI.ArcGIS.Carto.IGdbRasterCatalogLayer pGdbRCLayer = new ESRI.ArcGIS.Carto.GdbRasterCatalogLayerClass();
                    pGdbRCLayer.Setup(pFc as ITable);
                    MapControl.Map.AddLayer(pGdbRCLayer as ILayer);
                }
                else if ((pFcName.FeatureType == esriFeatureType.esriFTSimple) ||
                         (pFcName.FeatureType == esriFeatureType.esriFTComplexEdge) ||
                         (pFcName.FeatureType == esriFeatureType.esriFTComplexJunction) ||
                         (pFcName.FeatureType == esriFeatureType.esriFTSimpleEdge) ||
                         (pFcName.FeatureType == esriFeatureType.esriFTSimpleJunction))
                {
                    IFeatureLayer pLayer = new FeatureLayerClass();
                    pLayer.FeatureClass = pFc;
                    pLayer.Name         = (pFc as IDataset).Name;
                    MapControl.Map.AddLayer(pLayer as ILayer);
                }
                else if (pFcName.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    ILayer pLayer = OpenAnnotationLayer(pFc);
                    pLayer.Name = (pFc as IDataset).Name;
                    MapControl.Map.AddLayer(pLayer as ILayer);
                }

                MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            catch (Exception ex)
            { }
        }
        public static void OpenFeatureClass(AxMapControl MapControl,
            IFeatureClassName pFcName, ListView listview1)
        {
            try
            {
                MapControl.Map.ClearLayers();
                MapControl.SpatialReference = null;
                IName pName = pFcName as IName;
                IFeatureClass pFc = pName.Open() as IFeatureClass;

                listview1.Items.Clear();
                listview1.Columns.Clear();
                LoadListView(pFc, listview1);

                IFeatureCursor pCursor = pFc.Search(null, false);
                IFeature pfea = pCursor.NextFeature();
                int j = 0;
                while (pfea != null)
                {
                    ListViewItem lv = new ListViewItem();

                    for (int i = 0; i < pfea.Fields.FieldCount; i++)
                    {
                        string sFieldName = pfea.Fields.get_Field(i).Name;
                        lv.SubItems.Add(FeatureHelper.GetFeatureValue(pfea, sFieldName).ToString());
                    }

                    lv.Tag = pfea;
                    if (j % 2 == 0)
                    {
                        lv.BackColor = System.Drawing.Color.GreenYellow;
                    }
                    listview1.Items.Add(lv);
                    pfea = pCursor.NextFeature();
                    j++;
                }
                LSGISHelper.OtherHelper.ReleaseObject(pCursor);
                //最后加载图形数据

                if (pFcName.FeatureType == esriFeatureType.esriFTRasterCatalogItem)
                {
                    ESRI.ArcGIS.Carto.IGdbRasterCatalogLayer pGdbRCLayer = new ESRI.ArcGIS.Carto.GdbRasterCatalogLayerClass();
                    pGdbRCLayer.Setup(pFc as ITable);
                    MapControl.Map.AddLayer(pGdbRCLayer as ILayer);
                }
                else if ((pFcName.FeatureType == esriFeatureType.esriFTSimple) ||
                     (pFcName.FeatureType == esriFeatureType.esriFTComplexEdge) ||
                    (pFcName.FeatureType == esriFeatureType.esriFTComplexJunction) ||
                    (pFcName.FeatureType == esriFeatureType.esriFTSimpleEdge) ||
                     (pFcName.FeatureType == esriFeatureType.esriFTSimpleJunction))
                {

                    IFeatureLayer pLayer = new FeatureLayerClass();
                    pLayer.FeatureClass = pFc;
                    pLayer.Name = (pFc as IDataset).Name;
                    MapControl.Map.AddLayer(pLayer as ILayer);
                }
                else if (pFcName.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    ILayer pLayer = OpenAnnotationLayer(pFc);
                    pLayer.Name = (pFc as IDataset).Name;
                    MapControl.Map.AddLayer(pLayer as ILayer);
                }

                MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            catch (Exception ex)
            { }
        }