arcgis engine入门体会(一)

来源:互联网 发布:淘宝客网站备案 编辑:程序博客网 时间:2024/04/28 07:28
  1. point几何对象建立:
IPoint pPiont = new PointClass();pPiont.X = 100;pPiont.Y = 100;
  1. mutipoint 几何对象建立:
//定义第一个点IPoint pPiont1 = new PointClass();pPiont1.X = 100;pPiont2.Y = 100;//定义第二个点IPoint pPiont2 = new PointClass();pPiont2.X = 200;pPiont2.Y = 200;//....构建其他点IPointCollection pMultipoint = new MultipointClass();object o = Type.Missing;//添加第一个点,不需要设置点的顺序,参数设置为Type.MissingpMultipoint.AddPoint(pPiont1, ref o, ref o);//添加第二个点,不需要设置点的顺序,参数设置为Type.MissingpMultipoint.AddPoint(pPiont2, ref o, ref o);//...添加其他点
  1. 使用IGeometryColletion接口创建一个PloyLine对象
//创建一个polyline对象//定义第一个点IPoint pPiont1 = new PointClass();pPiont1.X = 100;pPiont1.Y = 100;//定义第二个点IPoint pPiont2 = new PointClass();pPiont2.X = 200;pPiont2.Y = 200;//创建一个line对象ILine pLine = new LineClass();//设置Line对象的起始终止点pLine.PutCoords(pPiont1, pPiont2);//QI到ISegmentIsegment pSegment = pLine as ISegment;//创建一个Path对象ISegmentCollection pPath = new PathClass();object o = Type.Missing;//通过ISegmentCollection接口为Path对象添加Segment对象pPath.AddSegment(pSegment, ref o, ref o);//创建一个Polyline对象IGeometryCollection pPolyline = new PolylineClass();//通过IGeometryCollection为Polyline对象添加Path对象pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);
  1. 构建一个Polygon
//创建一个Ring对象,通过ISegmentCollection接口向其中添加Segment对象ISegmentCollection pSegCollection = new RingClass();object o = Type.Missing;pSegCollection.AddSegment(pSegment1, ref o, ref o);pSegCollection.AddSegment(pSegment2, ref o, ref o);//QI到IRing接口封闭Ring对象,使其有效IRing pRing = pSegCollection as IRing;pRing.Close();//使用Ring对象构建Polygon对象IGemetryCollection pGeometryColl = new PolygonClass();pGeometryColl.AddGeometry(pRing, ref o, ref o);
  1. 一条10千米的Curve对象,获取2-5千米处的公路曲线代码片段
//QI到ICurve接口ICurve pCurve = pPolyline as ICurve;//创建一个Polyline对象ICurve pNewCurve = new PolylineClass();bool btrue = true;//获取-5千米间的曲线对象pCurve.GetSubcurve(2, 5, btrue, out pNewCurve);
  1. 构建一个Multipatch几何对象
/// <summary>        /// 构建Multipatch几何对象        /// </summary>        /// <returns>返回Multipatch几何对象</returns>        public IMultiPatch CreateMultipatch()        {            try            {                 //创建图形材质对象                IGeometryMaterial texture = new IGeometryMaterial();                texture.TextureImage = @"C:\Temp\MyImage.jpg";                //创建材质列表对象                IGeometryMaterialList materialList = new IGeometryMaterialList();                //向材质列表添加材质                materialList.AddMaterial(texture);                //创建GeneralMultiPatchCreator对象                IGeneralMultiPatchCreator multiPatchCreator = new GeneralMultiPatchCreatorClass();                multiPatchCreator.Init(4, 1, false, false, false, 4, materialList);                //设置Part:可以使三角扇或环                multiPatchCreator.SetPatchType(0, esriPatchType.esriPatchTypeTriangleStrip);                multiPatchCreator.SetMaterialIndex(0,0);                multiPatchCreator.SetPatchPointIndex(0, 0);                //创建真实points                WKSPointZ upperLeft = new WKSPointZ();                WKSPointZ lowerLeft = new WKSPointZ();                WKSPointZ upperRight = new WKSPointZ();                WKSPointZ loweRight = new WKSPointZ();                upperLeft.X = 0;                upperLeft.Y = 0;                upperLeft.Z = 0;                upperRight.X = 300;                upperRight.Y = 0;                upperRight.Z = 0;                lowerLeft.X = 0;                lowerLeft.Y = 0;                lowerLeft.Z = -100;                loweRight.X = 300;                loweRight.Y = 1;                loweRight.Z = -100;                multiPatchCreator.SetWKSPointZ(0, ref upperRight);                multiPatchCreator.SetWKSPointZ(1, ref loweRight);                multiPatchCreator.SetWKSPointZ(2, ref upperLeft);                multiPatchCreator.SetWKSPointZ(3, ref lowerLeft);                //设置贴图的点                WKSPoint textureUpperLeft = new WKSPoint();                WKSPoint textureLowerLeft = new WKSPoint();                WKSPoint textureUpperRight = new WKSPoint();                WKSPoint textureLowerRight = new WKSPoint();                textureUpperLeft.X = 0; textureUpperLeft.Y = 0;                textureUpperRight.X = 1; textureUpperRight.Y = 0;                textureLowerLeft.X = 0; textureLowerLeft.Y = 1;                textureLowerRight.X = 1; textureLowerRight.Y = 1;                multiPatchCreator.SetTextureWKSPoint(0, ref textureUpperRight);                multiPatchCreator.SetTextureWKSPoint(1, ref textureLowerRight);                multiPatchCreator.SetTextureWKSPoint(2, ref textureUpperLeft);                multiPatchCreator.SetTrxtureWKSPoint(3, ref textureLowerLeft);                //创建MultiPatch对象                IMultiPatch multiPatch = multiPatchCreator.CreateMultiPatch() as IMultiPatch;                return multiPatch;            }            catch(Exception Err)            {                MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK,MessageBoxIcon.Information);            }           }
  1. 通过IGeometryCollection创建一个Polygon
/// <summary>        /// 构造Polygon对象        /// </summary>        /// <param name="pRingList">Ring对象集合</param>        /// <returns>返回一个Polygon对象</returns>        private IPolygon ConstructorPolygon(List<IRing> pRingList)        {            try            {                //创建一个Polygon对象                IGeometryCollection pGCollection = new PolygonClass();                object o = Type.Missing;                //遍历Ring集合                for (int i = 0; i < pRingList.Count; i++)                {                    //通过IGeometryCollection接口的AddGeometry方法向Polygon对象中添加Ring子对象                    pGCollection.AddGeometry(pRingList[i], ref o, ref o);                }                //QI至ITopologicalOperator                ITopologicalOperator pToplogical = pGCollection as ITopologicalOperator;                //执行Simplify操作                pToplogical.Simplify();                IPolygon pPolygon = pGCollection as IPolygon;                //返回Polygom                return pPolygon;            }            catch (Exception Err)            {                 MessageBox.Show(Err.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information);                return null;            }        }
  1. 合并两个polygon对象为一个polygone对象
private IPolygon MergePolygons(IPolygon firstPolygon, IPolygon SecondPolygon)        {            try            {                //创建一个Polygon对象                IGeometryCollection pGCollection1 = new PolygonClass();                IGeometryCollection pGCollection2 = firstPolygon as IGeometryCollection;                IGeometryCollection pGCollection3 = SecondPolygon as IGeometryCollection;                //添加firstPolygon                pGCollection1.AddGeometryCollection(pGCollection2);                //添加SecondPolygon                pGCollection1.AddGeometryCollection(pGCollection3);                //QI至ITopologicalOperator                ITopologicalOperator pTopological = pGCollection1 as ITopologicalOperator;                //执行Simplify操作                pTopological.Simplify();                IPolygon pPolygon = pGCollection1 as IPolygon;                //返回Polygon对象                return pPolygon;            }            catch(Exception Err)            {                 MessageBox.Show(Err.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information);                return null;            }        }
  1. 改变一个图层的参考
private void ChangeLayerRef(IFeature pFeatureLayer, int gcsType)    {        try        {            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;            //QI到IGeoDataset            IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;            //QI到IGeoDatasetSchemaEdit            IGeoDatasetSchemaEdit pGeoDatabaseSchemaEdit = pGeoDataset as IGeoDatasetSchemaEdit;            if(pGeoDatabaseSchemaEdit.CanAlterSpatialReference == true)            {                //创建SpatiaReferenceEnciroment对象                ISpatialReferenceFactory2 pSpaRefFactory = new SpatialReferenceEnviromentClass();                //创建地理坐标系对象                IGeographicCoordinateSystem pNewGeoSys = pSpaRefFactory.CreateGeographicCoordinateSystem(gcsType);//4212代表背景1954                pGeoDatabaseSchemaEdit.AlterSpatialReference(pNewGeoSys);            }        }            catch(Exception Err)        {                MessageBox.Show(Err.Message,"提示",MessageBoxButtons.OK, MessageBoxIcon.Information);            }    }

基本上是对点线面的操作方法,使用IGeometryCollection合并

原创粉丝点击