예제 #1
0
        public static bool InsertShapeLayer(Boolean IsEqual, ILayer pFlayer)//插入矢量图
        {
            int count = MainFrom.m_mapControl.LayerCount;

            if (count == 0)
            {
                MainFrom.groupLayer.Add(pFlayer);
                MainFrom.m_mapControl.AddLayer(MainFrom.groupLayer);
            }
            else
            {
                for (int m = count - 1; m >= 0; m--)
                {
                    IMapLayers pLayers = MainFrom.m_mapControl.Map as IMapLayers;
                    ILayer     pGL     = MainFrom.m_mapControl.get_Layer(m);
                    if (pGL.Name == MainFrom.groupLayer.Name)
                    {
                        IsEqual = true;
                        if (pGL is IGroupLayer)
                        {
                            pLayers.InsertLayerInGroup((IGroupLayer)pGL, pFlayer, false, 0);
                        }
                    }
                }
                if (!IsEqual)
                {
                    MainFrom.groupLayer.Add(pFlayer);
                    MainFrom.m_mapControl.AddLayer(MainFrom.groupLayer);
                }
            }
            return(IsEqual);
        }
예제 #2
0
        private static void AddRasterLayer(Raster gRaster, IRasterRenderer rasterRenderer, string sRasterName, IGroupLayer pGrpLyr, string sHeader = null, short fTransparency = -1, bool ExpandLegend = true)
        {
            if (pGrpLyr != null)
            {
                IRasterLayer pResultLayer = ArcMapUtilities.IsRasterLayerInGroupLayer(gRaster.GISFileInfo, pGrpLyr);
                if (pResultLayer is ILayer)
                {
                    return;
                }
            }

            IRasterLayer   rasterLayer = new RasterLayer();
            IRasterDataset pRDS        = ArcMapUtilities.GetRasterDataset(gRaster);

            rasterLayer.CreateFromDataset(pRDS);
            if (rasterRenderer != null)
            {
                rasterLayer.Renderer = rasterRenderer;
            }

            if (rasterLayer != null)
            {
                IMapLayers pMapLayers = (IMapLayers)ArcMap.Document.FocusMap;
                if (!string.IsNullOrEmpty(sRasterName))
                {
                    rasterLayer.Name = sRasterName;
                }

                if (!string.IsNullOrEmpty(sHeader))
                {
                    ESRI.ArcGIS.Carto.ILegendInfo pLegend = (ESRI.ArcGIS.Carto.ILegendInfo)rasterLayer;
                    pLegend.LegendGroup[0].Heading = sHeader;
                }

                if (fTransparency >= 0)
                {
                    ILayerEffects pLayerEffects = (ILayerEffects)rasterLayer;
                    pLayerEffects.Transparency = fTransparency;
                }

                if (pGrpLyr == null)
                {
                    pMapLayers.InsertLayer(rasterLayer, false, 0);
                }
                else
                {
                    pMapLayers.InsertLayerInGroup(pGrpLyr, rasterLayer, false, 0);
                }

                // Collapse or expand the legend in the ToC (e.g. Hillshade should be collapsed)
                ((ILegendGroup)((ILegendInfo)rasterLayer).LegendGroup[0]).Visible = ExpandLegend;
            }

            int refsLeft = 0;

            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(pRDS);
            }while (refsLeft > 0);

            refsLeft = 0;
            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterLayer);
            }while (refsLeft > 0);
        }
예제 #3
0
        public override void OnClick()
        {//XZQLocation
            if (_hook == null)
            {
                return;
            }
            if (_hook.MainUserControl == null)
            {
                return;
            }
            DevComponents.AdvTree.AdvTree xzqTree = _hook.XZQTree;
            IGeometry xzqGeo = ModGetData.getExtentByXZQ(xzqTree.SelectedNode);

            if (xzqGeo == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到相应的行政区范围!");
                return;
            }
            try
            {
                Plugin.Application.IAppFormRef pAppFormRef = _AppHk as Plugin.Application.IAppFormRef;
                FrmSheetMapUserSet_ZTbat       batZT       = new FrmSheetMapUserSet_ZTbat(_AppHk.ArcGisMapControl, pAppFormRef.MainForm, xzqTree.SelectedNode.Text);
                batZT.WriteLog = WriteLog;//ygc 2012-9-12 是否写日志
                if (!(batZT.ShowDialog(pAppFormRef.MainForm) == DialogResult.OK))
                {
                    return;
                }
                if (this.WriteLog)
                {
                    Plugin.LogTable.Writelog("出" + this._Caption);
                }
                IMap pMap = batZT.Map;
                if (pMap.LayerCount == 0)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到图层。");
                    return;
                }
                string xzqdmFD = "";
                //构造晕线和渲染图层
                IFeatureClass xzqFC = ModGetData.getFCByXZQ(xzqTree.SelectedNode, ref xzqdmFD);
                if (xzqFC != null && xzqdmFD != null)
                {
                    ILayer hachureLyr = GeoPageLayoutFn.createHachureLyr(xzqFC, xzqdmFD, xzqTree.SelectedNode.Name);
                    if (hachureLyr != null)
                    {
                        IMapLayers  pMapLayers  = pMap as IMapLayers;
                        IGroupLayer pGroupLayer = pMap.get_Layer(0) as IGroupLayer;
                        if (pGroupLayer != null)
                        {
                            pMapLayers.InsertLayerInGroup(pGroupLayer, hachureLyr, false, 0);
                        }
                    }
                }
                GeoPageLayout pGL = new GeoPageLayout(pMap, xzqGeo, batZT.GetScale, xzqTree.SelectedNode.Text, 1);
                pGL.WriteLog       = WriteLog;//ygc 2012-9-12 是否写日志
                pGL.typePageLayout = 5;
                pGL.MapOut();
            }
            catch (Exception ex)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", ex.Message);
            }
        }
예제 #4
0
        public override void OnClick()
        {//XZQLocation
            if (_hook == null) return;
            if (_hook.MainUserControl == null) return;
            DevComponents.AdvTree.AdvTree xzqTree = _hook.XZQTree;
            IGeometry xzqGeo = ModGetData.getExtentByXZQ(xzqTree.SelectedNode);
            if (xzqGeo == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到相应的行政区范围!");
                return;
            }
            try
            {
                Plugin.Application.IAppFormRef pAppFormRef = _AppHk as Plugin.Application.IAppFormRef;
                if (this.WriteLog)
                {
                    Plugin.LogTable.Writelog("出" + this._Caption);
                }
                IMap pMap = null;
                bool isSpecial = ModGetData.IsMapSpecial();
                if (isSpecial)
                {
                    pMap = new MapClass();
                    ModGetData.AddMapOfByXZQ(pMap, "ZTGH", "", _hook.ArcGisMapControl.Map, xzqTree.SelectedNode.Text);
                    if (pMap.LayerCount == 0)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到图层。");
                        return;
                    }
                    ModuleMap.LayersComposeEx(pMap);//图层排序
                }
                else
                {
                    IObjectCopy pOC = new ObjectCopyClass();
                    pMap = pOC.Copy(_hook.ArcGisMapControl.Map) as IMap;//复制地图
                }
                if (pMap.LayerCount == 0)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到图层。");
                    return;

                }
                string xzqdmFD = "";
                //构造晕线和渲染图层
                IFeatureClass xzqFC = ModGetData.getFCByXZQ(xzqTree.SelectedNode, ref xzqdmFD);
                if (xzqFC != null && xzqdmFD != null)
                {
                    ILayer hachureLyr = GeoPageLayoutFn.createHachureLyr(xzqFC, xzqdmFD, xzqTree.SelectedNode.Name);
                    if (hachureLyr != null)
                    {
                        IMapLayers pMapLayers = pMap as IMapLayers;
                        IGroupLayer pGroupLayer = pMap.get_Layer(0) as IGroupLayer;
                        if (pGroupLayer != null)
                        {
                            pMapLayers.InsertLayerInGroup(pGroupLayer, hachureLyr, false, 0);
                        }

                    }
                }



                GeoPageLayout pGL = new GeoPageLayout();
                pGL.WriteLog = WriteLog;//ygc 2012-9-12 是否写日志
                pGL.pageLayoutZTGHTXQT(pMap, xzqGeo, xzqTree.SelectedNode.Text);
                
            }
            catch(Exception ex)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", ex.Message);
            }
        }
예제 #5
0
        public static void AddToMapVector(FileInfo sSource, string sDisplayName, IGroupLayer pGrpLyr, string displayField, IFeatureRenderer pRenderer, string queryFilter, string labelField, short fTransparency = -1)
        {
            if (string.IsNullOrEmpty(sDisplayName))
            {
                throw new ArgumentNullException("Display Name", "Null or empty display Name");
            }

            IFeatureLayer pResultLayer = IsFeatureLayerInGroupLayer(sSource.FullName, pGrpLyr);


            IFeatureWorkspace pWS = (IFeatureWorkspace)ArcMapUtilities.GetWorkspace(sSource);
            IFeatureClass     pFC = pWS.OpenFeatureClass(Path.GetFileNameWithoutExtension(sSource.FullName));

            pResultLayer = new FeatureLayer();
            pResultLayer.FeatureClass = pFC;
            if (fTransparency >= 0)
            {
                ILayerEffects pLayerEffects = (ILayerEffects)pResultLayer;
                pLayerEffects.Transparency = fTransparency;
            }

            if (!string.IsNullOrEmpty(sDisplayName))
            {
                pResultLayer.Name = sDisplayName;
            }

            IMapLayers pMapLayers = (IMapLayers)ArcMap.Document.FocusMap;

            if (pGrpLyr == null)
            {
                pMapLayers.InsertLayer(pResultLayer, true, 0);
            }
            else
            {
                pMapLayers.InsertLayerInGroup(pGrpLyr, pResultLayer, true, 0);
            }

            if (pRenderer != null)
            {
                ((IGeoFeatureLayer)pResultLayer).Renderer = pRenderer;
            }

            if (!string.IsNullOrEmpty(labelField))
            {
                IGeoFeatureLayer pGFL = pResultLayer as IGeoFeatureLayer;

                // This first attempt seems to set the label field, but doesn't
                // cause the labeling to refresh and take effect
                //IDisplayString displayString = pGFL as IDisplayString;
                //IDisplayExpressionProperties properties = displayString.ExpressionProperties;
                //properties.Expression = string.Format("[{0}]", labelField);

                // This second attempt takes more effort but actually works
                // https://community.esri.com/thread/19005
                IAnnotateLayerPropertiesCollection labelPropsCollection = pGFL.AnnotationProperties;
                labelPropsCollection.Clear();

                //IBasicOverposterLayerProperties pBOLayerProps = new BasicOverposterLayerProperties();
                //pBOLayerProps.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon
                //pBOLayerProps.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape
                //pBOLayerProps.FeatureWeight = esriBasicOverposterWeight.esriNoWeight
                //pBOLayerProps.LabelWeight = esriBasicOverposterWeight.esriLowWeight

                //Dim tSym As ITextSymbol
                //Set tSym = New TextSymbol
                //Dim font As IFontDisp
                //Set font = tSym.font
                //font.Bold = False
                //font.size = 6
                //tSym.font = font

                ILabelEngineLayerProperties aLELayerProps = (ILabelEngineLayerProperties) new LabelEngineLayerProperties();
                aLELayerProps.Expression = string.Format("[{0}]", labelField);

                //Set aLELayerProps.Symbol = tSym
                //Set aLELayerProps.BasicOverposterLayerProperties = pBOLayerProps
                IAnnotateLayerProperties lProps = aLELayerProps as IAnnotateLayerProperties;
                lProps.Class = "Any Name";
                labelPropsCollection.Add(lProps);

                pGFL.DisplayAnnotation = true;
            }

            if (pRenderer is IUniqueValueRenderer)
            {
                // If you didn't use a color ramp that was predefined in a style,
                // you need to use "Custom" here, otherwise use the name of the color ramp you chose.
                ((IGeoFeatureLayer)pResultLayer).DisplayField = displayField;

                // This makes the layer properties symbology tab show the correct interface
                IUID pUID = new UIDClass();
                pUID.Value = "{683C994E-A17B-11D1-8816-080009EC732A}";
                ((IGeoFeatureLayer)pResultLayer).RendererPropertyPageClassID = pUID as UIDClass;
            }

            if (!string.IsNullOrEmpty(queryFilter))
            {
                ((IFeatureLayerDefinition)pResultLayer).DefinitionExpression = queryFilter;
            }

            int refsLeft = 0;

            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(pFC);
            }while (refsLeft > 0);

            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(pResultLayer);
            }while (refsLeft > 0);

            ArcMap.Document.UpdateContents();
            ArcMap.Document.ActiveView.Refresh();
            ArcMap.Document.CurrentContentsView.Refresh(null);
        }
예제 #6
0
        /// <summary>
        /// 对mapcontrol上groupLayer内的图层进行排序
        /// </summary>
        /// <param name="groupLayer"></param>
        public static void LayersComposeEx(IMap pMap, IGroupLayer groupLayer)
        {
            //判断参数有效性
            if (pMap == null)
            {
                return;
            }
            if (groupLayer == null)
            {
                return;
            }
            ICompositeLayer comLayer   = groupLayer as ICompositeLayer;
            int             iCount     = comLayer.Count;
            IMapLayers      pMapLayers = pMap as IMapLayers;

            //对Dimension层进行排序 冒泡排序
            for (int iIndex = 0; iIndex < iCount; iIndex++)
            {
                ILayer TempLayeri = comLayer.get_Layer(iIndex) as ILayer;
                for (int jindex = iIndex + 1; jindex < iCount; jindex++)
                {
                    ILayer TempLayerj = comLayer.get_Layer(jindex) as ILayer;
                    if (TempLayeri != null && TempLayerj != null)
                    {
                        //获取图层顺序号
                        string strOrderid_i = GetOrderIDofLayer(TempLayeri);
                        string strOrderid_j = GetOrderIDofLayer(TempLayerj);
                        int    iOrderi      = -1;
                        int    iOrderj      = -1;

                        if (!strOrderid_i.Equals("") && !strOrderid_j.Equals(""))
                        {
                            try
                            {
                                iOrderi = int.Parse(strOrderid_i);
                                iOrderj = int.Parse(strOrderid_j);
                            }
                            catch
                            { }
                        }
                        if (iOrderi > 0 && iOrderj > 0)
                        {
                            if (iOrderi > iOrderj)
                            {
                                groupLayer.Delete(TempLayerj);
                                pMapLayers.InsertLayerInGroup(groupLayer, TempLayerj, false, iIndex);
                                TempLayeri = comLayer.get_Layer(iIndex) as ILayer;
                            }
                        }
                        else
                        {
                            int intDataTypeID_i = GetDataTypeIDofLayer(TempLayeri);
                            int intDataTypeID_j = GetDataTypeIDofLayer(TempLayerj);
                            if (intDataTypeID_i > intDataTypeID_j)
                            {
                                groupLayer.Delete(TempLayerj);
                                pMapLayers.InsertLayerInGroup(groupLayer, TempLayerj, false, iIndex);
                                TempLayeri = comLayer.get_Layer(iIndex) as ILayer;
                            }
                        }
                    }
                }
            }
        }