在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#图形和图像处理 → 基于AE的空间分析

基于AE的空间分析

C#图形和图像处理

下载此实例
  • 开发语言:C#
  • 实例大小:0.11M
  • 下载次数:32
  • 浏览次数:287
  • 发布时间:2019-06-19
  • 实例类别:C#图形和图像处理
  • 发 布 人:UP gis
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 空间 空间分析

实例介绍

【实例简介】

空间分析应用程序,包括建立缓冲区,边界线等十种空间分析方法

【实例截图】

from clipboard

【核心代码】

       private void loadMapDocument()
        {
            System.Windows.Forms.OpenFileDialog openFIleDialog;
            openFIleDialog  = new OpenFileDialog();
            openFIleDialog.Title = "打开地图文档";
            openFIleDialog.Filter = "map document(*.mxd)|*.mxd";
            openFIleDialog.ShowDialog();
            string filePath = openFIleDialog.FileName;
            if (axMapControl1.CheckMxFile(filePath))
            {
                axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
                axMapControl1.LoadMxFile(filePath, 0, Type.Missing);
                axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
            }
            else
            {
                MessageBox .Show (filePath "不是有效文档");
            }
        }
        //获取简单线符号
        private ISymbol getSimpleLineSymbol()
        {
            ISimpleLineSymbol SimpleLineSymbol = new SimpleLineSymbolClass();
            SimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot;
            SimpleLineSymbol.Width = 10;
            IRgbColor rgbColor = getRgb (255, 0, 0);
            SimpleLineSymbol.Color = rgbColor;
            ISymbol symbol = SimpleLineSymbol as ISymbol;
            symbol.ROP2  = esriRasterOpCode.esriROPNotXOrPen;
            return symbol;
        }
        //获取简单面填充符号
        private ISimpleFillSymbol getSimpleFillSymbol(int fillColor, int lineColor)
        {
            ISimpleFillSymbol SimpleFillSymbol = new SimpleFillSymbolClass();
            SimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
            SimpleFillSymbol.Color = getRgb(255, 0, 0);
            //创建边线符号
            ISimpleLineSymbol SimpleLineSymbol = new SimpleLineSymbolClass();
            SimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot;
            SimpleLineSymbol.Color = getRgb(0, lineColor, 0);
            SimpleLineSymbol.Width = 5;
            ISymbol symbol = SimpleLineSymbol as ISymbol;
            symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
            SimpleFillSymbol.Outline = SimpleLineSymbol;
            return SimpleFillSymbol;
        }
        //创建颜色带
        private IColorRamp CreatAlogrithmicColorRamp(int count)
        {
            //创建一个新CreatAlogrithmicColorRamp对象
            IAlgorithmicColorRamp algColorRamp = new AlgorithmicColorRampClass();
            IRgbColor fromColor = new RgbColorClass();
            IRgbColor toColor = new RgbColorClass();
            //创建起始颜色对象
            fromColor.Red = 255;
            fromColor.Green = 0;
            fromColor.Blue = 0;
            //创建终止颜色对象
            toColor.Red = 0;
            toColor.Green = 0;
            toColor.Blue = 255;
            //设置 AlgorithmicColorRampClass的起止属性
            algColorRamp.ToColor = fromColor;
            algColorRamp.FromColor = toColor;
            //设置梯度类型
            algColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
            //设置颜色带颜色数量
            algColorRamp.Size = count;
            //创建颜色带、
            bool bture = true;
            algColorRamp.CreateRamp(out bture);
            return algColorRamp;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            loadMapDocument();
        }
        //boundery
        private void button1_Click(object sender, EventArgs e)
        {
            IFeatureLayer featureLayer;
            IFeatureCursor featureCursor;
            featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            featureCursor = featureLayer.FeatureClass.Search(null, true);
            IFeature feature;
                    IGeometry geometry;
                    ISymbol symbol;
                    IActiveView activeView = this.axMapControl1.ActiveView;
                    feature = featureCursor.NextFeature();
                    while  (feature != null)
                    {
                        if (feature.get_Value(feature.Fields.FindField("Continent")).ToString() == "Europe")
                        {
                            IPolygon polygon;
                            polygon = feature.Shape as IPolygon;
                            ITopologicalOperator topo = polygon as ITopologicalOperator;
                            topo.Simplify();
                            geometry = topo.Boundary;
                            if   (geometry != null)
                            {
                                if (geometry.GeometryType == esriGeometryType.esriGeometryPolyline)
                                {
                                    symbol = getSimpleLineSymbol() as ISymbol;
                                    activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
                                    activeView.ScreenDisplay.SetSymbol(symbol);
                                    activeView.ScreenDisplay.DrawPolyline(geometry);
                                    activeView.ScreenDisplay.FinishDrawing();
                                    activeView.ScreenDisplay.FinishDrawing();
                                }
                            }
                        }
                        feature = featureCursor.NextFeature();
                    }
                }

        //装换像素到地图单位
        private double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
        {
            tagRECT pRect = pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();
            int piexlExtent = pRect.right - pRect.left;
            double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
            double sizeOfOnePixel = realWorldDisplayExtent / piexlExtent;
            return pixelUnits * sizeOfOnePixel;
        }
        //buffer
        private void button2_Click(object sender, EventArgs e)
        {

            IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            IFeatureCursor featureCursor;
            IFeature feature;
            IGeometry geometry;
            IActiveView activeView = this.axMapControl1.ActiveView;
            ITopologicalOperator topo;
            featureCursor = featureLayer.FeatureClass.Search(null, false);
            feature = featureCursor.NextFeature();
            ISpatialFilter spatialFilter = new SpatialFilterClass();
            IFeatureSelection featureSelection;
            ISymbol symbol = getSimpleFillSymbol(255, 125) as ISymbol;
            if (feature != null)
            {
                    topo = feature.Shape as ITopologicalOperator;
                    double bufferLength = ConvertPixelsToMapUnits(activeView, 2);
                    geometry = topo.Buffer(bufferLength);
                    activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
                    activeView.ScreenDisplay.SetSymbol(symbol);
                    activeView.ScreenDisplay.DrawPolygon(geometry);
                    activeView.ScreenDisplay.FinishDrawing();
                    //spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    //spatialFilter.Geometry = geometry;
                    //spatialFilter.GeometryField = featureLayer.FeatureClass.ShapeFieldName;
                    //spatialFilter.SubFields = "continent";
                    //spatialFilter.WhereClause = "";//
                    //featureSelection = featureLayer as IFeatureSelection;
                    //featureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
                    //ISelectionSet selectionSet = featureSelection.SelectionSet;
                    //ICursor cursor;
                    //selectionSet.Search(null, true, out cursor);
                    //feature = featureCursor.NextFeature();
                    //while (feature != null)
                    //{
                    //    this.axMapControl1.Map.SelectFeature(featureLayer, feature);
                    //    feature = featureCursor.NextFeature();
                    //}
                    activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
               
                  }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            IFeatureCursor featureCursor;
            IFeature feature;
            IGeometry geometry;
            IActiveView activeView = this.axMapControl1.ActiveView;
            ITopologicalOperator topo;
            featureCursor = featureLayer.FeatureClass.Search(null, false );
            feature = featureCursor.NextFeature();
            ISpatialFilter spatialFilter = new SpatialFilterClass();
            IFeatureSelection featureSelection;
            IEnvelope env = new EnvelopeClass();
            if (feature != null)
            {
                topo = feature.Shape as ITopologicalOperator;
                env = feature.Shape.Envelope;
                double width, height;
                width = env.XMax - env.XMin;
                height = env.YMax - env.YMin;
                env.XMin = env.XMin width / 3;
                env.YMin = env.YMin height / 3;
                env.XMax =env .XMax -width /3;
                env.YMax = env.YMax - height / 3;
                geometry = new PolygonClass();
                topo.QueryClipped(env, geometry);
                ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
                activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
                activeView.ScreenDisplay.SetSymbol(symbol);
                activeView.ScreenDisplay.DrawPolygon(geometry);
                activeView.ScreenDisplay.FinishDrawing();
                activeView.ScreenDisplay.FinishDrawing();

            }

        }
        //construction
        private void button4_Click(object sender, EventArgs e)
        {
            IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            IFeature feature;
                 IActiveView activeView = this.axMapControl1.ActiveView;
                 ITopologicalOperator topo;
                 object missing = Type.Missing;
                 IGeometryCollection geometryCollection = new GeometryBagClass();
                 for (int i = 0; i < 3; i )
                 {
                     feature = featureLayer.FeatureClass.GetFeature(i);
                     geometryCollection.AddGeometry(feature.Shape, ref missing, ref missing);
                 }
                 IPolygon newPolygon = new PolygonClass();
                 topo = newPolygon as ITopologicalOperator;
                 topo.ConstructUnion(geometryCollection as IEnumGeometry);
                 ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
                 activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
                 activeView.ScreenDisplay.SetSymbol(symbol);
                 activeView.ScreenDisplay.DrawPolygon(newPolygon as IGeometry);
                 activeView.ScreenDisplay.FinishDrawing();
                 activeView.ScreenDisplay.FinishDrawing();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            IFeature feature;
            IActiveView activeView = this.axMapControl1.ActiveView;
            ITopologicalOperator topo;

            IGeometry geometry;
            feature = featureLayer.FeatureClass.GetFeature(0);
            topo = feature.Shape as ITopologicalOperator;
            geometry = topo.ConvexHull();

            ISymbol symbol = getSimpleLineSymbol();
            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(symbol);
            activeView.ScreenDisplay.DrawPolyline (geometry);
            activeView.ScreenDisplay.FinishDrawing();
            activeView.ScreenDisplay.FinishDrawing();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            IFeature feature;
            IActiveView activeView = this.axMapControl1.ActiveView;
            ITopologicalOperator topo;
            IGeometry leftGeometry, rightGeometry;
            feature = featureLayer.FeatureClass.GetFeature(0);
            topo = feature.Shape as ITopologicalOperator;
            IEnvelope env = feature.Shape.Envelope;
            IPolyline polyline = new PolylineClass();
            IPoint point = new PointClass();
            point.PutCoords(env.XMax, env.YMax);
            polyline.FromPoint = point;
            point.PutCoords(env.XMax, env.YMax);
            polyline.ToPoint = point;
            topo.Cut(polyline, out leftGeometry, out rightGeometry);
            ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(symbol);
            activeView.ScreenDisplay.DrawPolygon(leftGeometry );
            activeView.ScreenDisplay.FinishDrawing();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            IFeature feature;
            IActiveView activeView = this.axMapControl1.ActiveView;
            ITopologicalOperator topo;

            IGeometry geometry;
            feature = featureLayer.FeatureClass.GetFeature(0);
            topo = feature.Shape as ITopologicalOperator;
            IEnvelope env = feature.Shape.Envelope;
            double width, height;
            width = env.XMax - env.XMin;
            height = env.YMax - env.YMin;
            object Missing = Type.Missing;
            IPolygon polygon = new PolygonClass();
            IPointCollection pointCollection = polygon as IPointCollection;
            IPoint point = new PointClass();
            point.PutCoords(env.XMin width / 3, env.YMin height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMin width / 3, env.YMin - height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMax  - width / 3, env.YMax  - height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMax - width / 3, env.YMax height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            geometry = topo.Difference(polygon as IGeometry);
            ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(symbol);
            activeView.ScreenDisplay.DrawPolygon(geometry );
            activeView.ScreenDisplay.FinishDrawing();
           
        }

        private void button8_Click(object sender, EventArgs e)
        {
            IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            IFeature feature;
            IActiveView activeView = this.axMapControl1.ActiveView;
            ITopologicalOperator topo;

            IGeometry geometry;
            feature = featureLayer.FeatureClass.GetFeature(0);
            topo = feature.Shape as ITopologicalOperator;
            IEnvelope env = feature.Shape.Envelope;
            double width, height;
            width = env.XMax - env.XMin;
            height = env.YMax - env.YMin;
            object Missing = Type.Missing;
            IPolygon polygon = new PolygonClass();
            IPointCollection pointCollection = polygon as IPointCollection;
            IPoint point = new PointClass();
            point.PutCoords(env.XMin width / 3, env.YMin height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMin width / 3, env.YMin - height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMax - width / 3, env.YMax - height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMax - width / 3, env.YMax height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            polygon.SimplifyPreserveFromTo();
            geometry = topo.Intersect(polygon as IGeometry, esriGeometryDimension.esriGeometry2Dimension);
            ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(symbol);
            activeView.ScreenDisplay.DrawPolygon(geometry);
            activeView.ScreenDisplay.FinishDrawing();

        }

        private void button9_Click(object sender, EventArgs e)
        {
            IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            IFeature feature;
            IActiveView activeView = this.axMapControl1.ActiveView;
            ITopologicalOperator topo;

            IGeometry geometry;
            feature = featureLayer.FeatureClass.GetFeature(0);
            topo = feature.Shape as ITopologicalOperator;
            IEnvelope env = feature.Shape.Envelope;
            double width, height;
            width = env.XMax - env.XMin;
            height = env.YMax - env.YMin;
            object Missing = Type.Missing;
            IPolygon polygon = new PolygonClass();
            IPointCollection pointCollection = polygon as IPointCollection;
            IPoint point = new PointClass();
            point.PutCoords(env.XMin width / 3, env.YMin height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMin width / 3, env.YMin - height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMax width / 3, env.YMax - height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMax width / 3, env.YMax height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            polygon.SimplifyPreserveFromTo();
            geometry = topo.SymmetricDifference(polygon as IGeometry);
            ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(symbol);
            activeView.ScreenDisplay.DrawPolygon(geometry);
            activeView.ScreenDisplay.FinishDrawing();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            IFeature feature;
            IActiveView activeView = this.axMapControl1.ActiveView;
            ITopologicalOperator topo;

            IGeometry geometry;
            feature = featureLayer.FeatureClass.GetFeature(0);
            topo = feature.Shape as ITopologicalOperator;
            IEnvelope env = feature.Shape.Envelope;
            double width, height;
            width = env.XMax - env.XMin;
            height = env.YMax - env.YMin;
            object Missing = Type.Missing;
            IPolygon polygon = new PolygonClass();
            IPointCollection pointCollection = polygon as IPointCollection;
            IPoint point = new PointClass();
            point.PutCoords(env.XMin width / 3, env.YMin height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMin width / 3, env.YMin - height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMax width / 3, env.YMax - height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(env.XMax width / 3, env.YMax height / 3);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            polygon.SimplifyPreserveFromTo();
            geometry = topo.Union(polygon as IGeometry);

            ISimpleFillSymbol simpleFillSymbol = getSimpleFillSymbol(255, 255);
            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(simpleFillSymbol as ISymbol );
            activeView.ScreenDisplay.DrawPolygon(geometry as IGeometry );
            activeView.ScreenDisplay.FinishDrawing();
        }
       
    }
}

标签: 空间 空间分析

实例下载地址

基于AE的空间分析

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警