Пример #1
0
        public string Statistic(string layerName, string fieldName, IMap imap)
        {
            DataOperator    pDo  = new DataOperator(imap, null);
            IFeatureLayer   pFl  = (IFeatureLayer)pDo.GetLayerbyName(layerName);
            IFeatureClass   pFcl = pFl.FeatureClass;
            IDataStatistics pDst = new DataStatistics();
            IFeatureCursor  pFc;

            pFc = pFcl.Search(null, false);
            ICursor pCs = (ICursor)pFc;

            pDst.Cursor = pCs;
            pDst.Field  = fieldName;
            IStatisticsResults StartReasult;

            StartReasult = pDst.Statistics;
            double dMax, dMin, dMean;

            dMax  = StartReasult.Maximum;
            dMin  = StartReasult.Minimum;
            dMean = StartReasult.Mean;
            string sReasult;

            sReasult = "最大面积为" + dMax.ToString() + ";最小面积为" + dMin.ToString() + ";平均面积为" + dMean.ToString();
            return(sReasult);
        }
Пример #2
0
        public bool Buffer(string layerName, string sWhere, int iSize, IMap imap)
        {
            IFeatureClass pFcl;
            IFeature      pF;
            IGeometry     pGt;
            DataOperator  pDo = new DataOperator(imap, null);
            IFeatureLayer pFl = (IFeatureLayer)pDo.GetLayerbyName(layerName);

            pFcl = pFl.FeatureClass;
            IQueryFilter pQf = new QueryFilterClass();

            pQf.WhereClause = sWhere;
            IFeatureCursor pFc;

            pFc = (IFeatureCursor)pFcl.Search(pQf, false);
            int count = pFcl.FeatureCount(pQf);

            pF  = pFc.NextFeature();
            pGt = pF.Shape;
            ITopologicalOperator pTo       = (ITopologicalOperator)pGt;
            IGeometry            pGtBuffer = pTo.Buffer(iSize);
            ISpatialFilter       pSf       = new SpatialFilter();

            pSf.Geometry   = pGtBuffer;
            pSf.SpatialRel = esriSpatialRelEnum.esriSpatialRelIndexIntersects;
            IFeatureSelection pFs = (IFeatureSelection)pFl;

            pFs.SelectFeatures(pSf, esriSelectionResultEnum.esriSelectionResultNew, false);
            return(true);
        }
Пример #3
0
        public bool QueryIntersect(string srcLayerName, string tgtLayerName, IMap imap, esriSpatialRelationEnum spatialRel)
        {
            DataOperator pDo = new DataOperator(imap, null);
            //定义并根据图层名称获取图层对象
            IFeatureLayer iSrcLayer = new FeatureLayerClass();

            iSrcLayer = (IFeatureLayer)pDo.GetLayerbyName(srcLayerName);
            IFeatureLayer iTgtLayer = (IFeatureLayer)pDo.GetLayerbyName(tgtLayerName);
            //通过查询过滤获取continent层中亚洲几何
            IGeometry      pGt;
            IFeature       pF;
            IFeatureCursor pFcs;
            IFeatureClass  pFcl;
            IQueryFilter   pQf = new QueryFilter();

            pQf.WhereClause = "CONTINENT='Asia'";//设置查询条件
            pFcs            = iTgtLayer.FeatureClass.Search(pQf, false);
            pF  = pFcs.NextFeature();
            pGt = pF.Shape;
            try
            {
                pFcl = iSrcLayer.FeatureClass;
            }
            catch
            {
            }
            ISpatialFilter pSf = new SpatialFilter();

            pSf.Geometry    = pGt;
            pSf.WhereClause = "POP_RANK=5";//人口等级低于5的城市
            pSf.SpatialRel  = (ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum)spatialRel;
            //定义要素选择对象,以要素搜索图层进行实例化
            IFeatureSelection pFs = (IFeatureSelection)iSrcLayer;

            //以空间过滤器对要素进行选择,并建立新选择集
            try
            {
                pFs.SelectFeatures(pSf, esriSelectionResultEnum.esriSelectionResultNew, false);
            }
            catch
            {
            }
            return(true);
        }
Пример #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            double bufferDistance;

            double.TryParse(txtBufferDistance.Text, out bufferDistance);
            if (0.0 == bufferDistance)
            {
                MessageBox.Show("距离设置错误", "Error!");
                return;
            }
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(txtOutputPath.Text)) || ".shp" != System.IO.Path.GetExtension(txtOutputPath.Text))
            {
                MessageBox.Show("输出格式错误!");
                return;
            }
            if (comboBoxLayer.Items.Count <= 0)
            {
                return;
            }
            DataOperator  pDo = new DataOperator(m_map, null);
            IFeatureLayer pFl = (IFeatureLayer)pDo.GetLayerbyName(comboBoxLayer.SelectedItem.ToString());
            Geoprocessor  gp  = new Geoprocessor();

            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = true;
            string unit = "Kilometers";

            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(pFl, txtOutputPath.Text, Convert.ToString(bufferDistance) + "" + unit);
            try
            {
                IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);
            }
            catch
            {
            }
            string fileDirectory = txtOutputPath.Text.ToString().Substring(0, txtOutputPath.Text.LastIndexOf("\\"));
            int    j;

            j = txtOutputPath.Text.LastIndexOf("\\");
            string            tmpstr = txtOutputPath.Text.ToString().Substring(j + 1);
            IWorkspaceFactory pWsf   = new ShapefileWorkspaceFactory() as IWorkspaceFactory;
            IWorkspace        pWs    = pWsf.OpenFromFile(fileDirectory, 0);
            IFeatureWorkspace pFs    = pWs as IFeatureWorkspace;
            IFeatureClass     pFc    = pFs.OpenFeatureClass(tmpstr);
            IFeatureLayer     pfl    = new FeatureLayer() as IFeatureLayer;

            pfl.FeatureClass = pFc;
            IRgbColor pColor = new RgbColor() as IRgbColor;

            pColor.Red          = 255;
            pColor.Green        = 0;
            pColor.Blue         = 0;
            pColor.Transparency = 255;
            ILineSymbol pOutline = new SimpleLineSymbol();

            pOutline.Width      = 2;
            pOutline.Color      = pColor;
            pColor              = new RgbColor();
            pColor.Red          = 255;
            pColor.Green        = 0;
            pColor.Blue         = 0;
            pColor.Transparency = 100;
            ISimpleFillSymbol pFillSymbol = new SimpleFillSymbol();

            pFillSymbol.Color   = pColor;
            pFillSymbol.Outline = pOutline;
            pFillSymbol.Style   = esriSimpleFillStyle.esriSFSSolid;
            ISimpleRenderer  pRen;
            IGeoFeatureLayer pGeofl = pfl as IGeoFeatureLayer;

            pRen            = pGeofl.Renderer as ISimpleRenderer;
            pRen.Symbol     = pFillSymbol as ISymbol;
            pGeofl.Renderer = pRen as IFeatureRenderer;
            ILayerEffects pLayerEffects = pfl as ILayerEffects;

            pLayerEffects.Transparency = 150;
            m_mapControl.AddLayer((ILayer)pfl, 0);
            MessageBox.Show(comboBoxLayer.SelectedText + "缓冲区生成成功!");
        }