Exemple #1
0
        /// <summary>
        ///添加点图层
        /// </summary>
        /// <param name="axMap"></param>
        /// <param name="longtitude"></param>
        /// <param name="latitude"></param>
        /// <param name="fieldsMap"></param>
        public static IFeature addPointInLayer(AxMapControl axMap, SharedStory story)
        {
            try
            {
                double longitude = Convert.ToDouble(story.Longitude);
                double latitude  = Convert.ToDouble(story.Latitude);
                String storyId   = story.Id;
                String message   = story.Message;

                ILayer layer = getLayerByName(axMap.Map, "story");

                //将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑
                IFeatureLayer featureLayer = layer as IFeatureLayer;
                //定义一个要素集合,并获取图层的要素集合
                IFeatureClass featureClass = featureLayer.FeatureClass;
                //定义一个实现新增要素的接口实例,并该实例作用于当前图层的要素集
                IFeatureClassWrite writer = (IFeatureClassWrite)featureClass;
                //定义一个工作编辑工作空间,用于开启前图层的编辑状态
                IWorkspaceEdit edit = (featureClass as IDataset).Workspace as IWorkspaceEdit;
                //定义一个IFeature实例,用于添加到当前图层上
                IFeature feature;
                //开启编辑状态
                edit.StartEditing(true);
                //开启编辑操作
                edit.StartEditOperation();
                //定义一个点,用来作为IFeature实例的形状属性,即shape属性
                IPoint point;
                //下面是设置点的坐标和参考系
                point = new PointClass();
                point.SpatialReference = axMap.SpatialReference;
                point.X = longitude;
                point.Y = latitude;

                //将IPoint设置为IFeature的shape属性时,需要通过中间接口IGeometry转换
                IGeometry geometry = point;
                //实例化IFeature对象, 这样IFeature对象就具有当前图层上要素的字段信息
                feature = featureClass.CreateFeature();
                //设置IFeature对象的形状属性
                feature.Shape = geometry;

                //添加字段
                int index = featureClass.FindField("story_id");
                feature.Value[index] = storyId;



                feature.Store();              //保存IFeature对象
                writer.WriteFeature(feature); //将IFeature对象,添加到当前图层上
                edit.StopEditOperation();     //停止编辑操作
                edit.StopEditing(true);       //关闭编辑状态,并保存修改

                axMap.Refresh();              //刷新地图

                return(feature);
            }
            catch
            {
                return(null);
            }
        }
Exemple #2
0
        public void AddPolygonByWrite(AxMapControl axMapControl1, IFeatureLayer l, double x, double y)
        {
            ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType;
            if (featype == esriGeometryType.esriGeometryPolygon)//判断层是否为线层
            {
                //IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer;
                IFeatureClass      fc = l.FeatureClass;
                IFeatureClassWrite fr = fc as IFeatureClassWrite;
                IWorkspaceEdit     w  = (fc as IDataset).Workspace as IWorkspaceEdit;
                IFeature           f;
                //可选参数的设置
                object Missing = Type.Missing;
                IPoint p       = new PointClass();
                w.StartEditing(true);
                w.StartEditOperation();

                f = fc.CreateFeature();
                //定义一个多义线对象
                IRgbColor color = new RgbColor();
                // 设置颜色属性
                color.Red          = 255;
                color.Transparency = 255;
                IGeometry iGeom = axMapControl1.TrackPolygon();
                AddRegion(axMapControl1, iGeom);
                f.Shape = iGeom;
                fr.WriteFeature(f);
                w.StopEditOperation();
                w.StopEditing(true);
            }
        }
Exemple #3
0
        public void AddPointByWrite(IFeatureLayer l, double x, double y)
        {
            ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType;
            if (featype == esriGeometryType.esriGeometryPoint)//判断层是否为点层
            {
                // IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer;
                IFeatureClass      fc = l.FeatureClass;
                IFeatureClassWrite fr = fc as IFeatureClassWrite;
                IWorkspaceEdit     w  = (fc as IDataset).Workspace as IWorkspaceEdit;
                IFeature           f;
                IPoint             p;

                w.StartEditing(true);
                w.StartEditOperation();

                f = fc.CreateFeature();
                p = new PointClass();
                p.PutCoords(x, y);
                f.Shape = p;
                fr.WriteFeature(f);

                w.StopEditOperation();
                w.StopEditing(true);
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            pLayer = this.axMapControl1.get_Layer(i);                                            //所要加的层
            IFeatureLayer      pFeatureLyr = pLayer as IFeatureLayer;                            //将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑
            IFeatureClass      pFeatCls    = pFeatureLyr.FeatureClass;                           //定义一个要素集合,并获取图层的要素集合
            IFeatureClassWrite fr          = (IFeatureClassWrite)pFeatCls;                       //定义一个实现新增要素的接口实例,并该实例作用于当前图层的要素集
            IWorkspaceEdit     w           = (pFeatCls as IDataset).Workspace as IWorkspaceEdit; //定义一个工作编辑工作空间,用于开启前图层的编辑状态
            IFeature           f;                                                                //定义一个IFeature实例,用于添加到当前图层上

            w.StartEditing(true);                                                                //开启编辑状态
            w.StartEditOperation();                                                              //开启编辑操作
            IPoint p;                                                                            //定义一个点,用来作为IFeature实例的形状属性,即shape属性

            //下面是设置点的坐标和参考系
            p = new PointClass();
            p.SpatialReference = this.axMapControl1.SpatialReference;
            p.X = 600;
            p.Y = 500;

            //将IPoint设置为IFeature的shape属性时,需要通过中间接口IGeometry转换
            IGeometry peo;

            peo     = p;
            f       = pFeatCls.CreateFeature(); //实例化IFeature对象, 这样IFeature对象就具有当前图层上要素的字段信息
            f.Shape = peo;                      //设置IFeature对象的形状属性
            f.set_Value(3, "house1");           //设置IFeature对象的索引是3的字段值
            f.Store();                          //保存IFeature对象
            fr.WriteFeature(f);                 //将IFeature对象,添加到当前图层上
            w.StopEditOperation();              //停止编辑操作
            w.StopEditing(true);                //关闭编辑状态,并保存修改
            this.axMapControl1.Refresh();       //刷新地图
        }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            name = textBox1.Text;
            ID   = textBox2.Text;

            //开启编辑状态
            IWorkspaceFactory pWorkspaceFactory;

            pWorkspaceFactory = new AccessWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWorkspace;

            pFeatureWorkspace = pWorkspaceFactory.OpenFromFile("ShpData/Nanjing.mdb", 0) as IFeatureWorkspace;
            IWorkspaceEdit pWorkspaceEdit;

            pWorkspaceEdit = pFeatureWorkspace as IWorkspaceEdit;
            pWorkspaceEdit.StartEditing(false);
            pWorkspaceEdit.StartEditOperation();

            IFeatureClassWrite fr = fea_class as IFeatureClassWrite;

            if (type == 1)  //添加要素
            {
                //添加要素
                IFeature pFeature;
                pFeature       = fea_class.CreateFeature();
                pFeature.Shape = point;

                pFeature.set_Value(2, name);
                pFeature.set_Value(3, ID);
                fr.WriteFeature(pFeature);

                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature);
                pFeature = null;
            }
            else if (type == 2)  //修改要素
            {
                fea.set_Value(2, name);
                fea.set_Value(3, ID);
                fr.WriteFeature(fea);
            }

            pWorkspaceEdit.StopEditOperation();
            pWorkspaceEdit.StopEditing(true);
            this.Hide();
            MessageBox.Show("操作成功!", "提示");
        }
Exemple #6
0
        /// <summary>
        ///添加点图层
        /// </summary>
        /// <param name="axMap"></param>
        /// <param name="longtitude"></param>
        /// <param name="latitude"></param>
        /// <param name="fieldsMap"></param>
        public static IFeature addPointInLayer(AxMapControl axMap, String layerName, double longtitude, double latitude)
        {
            ILayer layer = getLayerByName(axMap.Map, layerName);

            //将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑
            IFeatureLayer featureLayer = layer as IFeatureLayer;
            //定义一个要素集合,并获取图层的要素集合
            IFeatureClass featureClass = featureLayer.FeatureClass;
            //定义一个实现新增要素的接口实例,并该实例作用于当前图层的要素集
            IFeatureClassWrite writer = (IFeatureClassWrite)featureClass;
            //定义一个工作编辑工作空间,用于开启前图层的编辑状态
            IWorkspaceEdit edit = (featureClass as IDataset).Workspace as IWorkspaceEdit;
            //定义一个IFeature实例,用于添加到当前图层上
            IFeature feature;

            //开启编辑状态
            edit.StartEditing(true);
            //开启编辑操作
            edit.StartEditOperation();
            //定义一个点,用来作为IFeature实例的形状属性,即shape属性
            IPoint point;

            //下面是设置点的坐标和参考系
            point = new PointClass();
            point.SpatialReference = axMap.SpatialReference;
            point.X = longtitude;
            point.Y = latitude;

            //将IPoint设置为IFeature的shape属性时,需要通过中间接口IGeometry转换
            IGeometry geometry = point;

            //实例化IFeature对象, 这样IFeature对象就具有当前图层上要素的字段信息
            feature = featureClass.CreateFeature();
            //设置IFeature对象的形状属性
            feature.Shape = geometry;

            feature.Store();              //保存IFeature对象
            writer.WriteFeature(feature); //将IFeature对象,添加到当前图层上
            edit.StopEditOperation();     //停止编辑操作
            edit.StopEditing(true);       //关闭编辑状态,并保存修改

            axMap.Refresh();              //刷新地图

            return(feature);
        }
Exemple #7
0
        private static void SetStudentInfo(IFeatureLayer featureLayer, IFeature feature, object Id, object SID, object SNAME, object SSEX, object SBIRTH, object SHOME)
        {
            IFeatureClassWrite pWrite = featureLayer.FeatureClass as IFeatureClassWrite;
            IWorkspaceEdit     pEdit  = (featureLayer.FeatureClass as IDataset).Workspace as IWorkspaceEdit;

            pEdit.StartEditing(true);
            pEdit.StartEditOperation();
            feature.set_Value(featureLayer.FeatureClass.Fields.FindField("Id"), Id);
            feature.set_Value(featureLayer.FeatureClass.Fields.FindField("SID"), SID);
            feature.set_Value(featureLayer.FeatureClass.Fields.FindField("SNAME"), SNAME);
            feature.set_Value(featureLayer.FeatureClass.Fields.FindField("SSEX"), SSEX);
            feature.set_Value(featureLayer.FeatureClass.Fields.FindField("SBIRTH"), SBIRTH);
            feature.set_Value(featureLayer.FeatureClass.Fields.FindField("SHOME"), SHOME);
            feature.Store();
            pWrite.WriteFeature(feature);
            pEdit.StopEditOperation();
            pEdit.StopEditing(true);
        }
Exemple #8
0
        //确定键
        private void buttonOK_Click(object sender, EventArgs e)
        {
            double dL = 0.0, dB = 0.0, dZJ = 0.0;
            bool   bL  = double.TryParse(textBoxLong.Text, out dL);   //经度
            bool   bB  = double.TryParse(textBoxLat.Text, out dB);    //纬度
            bool   bZJ = double.TryParse(textBoxLevel.Text, out dZJ); //震级

            time = textBoxTime.Text;                                  //时间

            //开启编辑状态
            IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(dataFile, 0) as IFeatureWorkspace;
            IWorkspaceEdit    pWorkspaceEdit    = pFeatureWorkspace as IWorkspaceEdit;

            pWorkspaceEdit.StartEditing(false);
            pWorkspaceEdit.StartEditOperation();
            //插入余震点数据
            IFeatureClass      pFeatureClassPoint = pFeatureLayerPoint.FeatureClass;
            IFeatureClassWrite fwritePoint        = pFeatureClassPoint as IFeatureClassWrite;
            IFeature           pFeaturePoint      = pFeatureClassPoint.CreateFeature();
            IPointCollection   pointCollection    = new MultipointClass();
            IPoint             pPoint             = new PointClass();
            IGeoDataset        pGeoDataset        = pFeatureClassPoint as IGeoDataset;
            //记录空间投影信息
            ISpatialReference spatialReference = pGeoDataset.SpatialReference;

            //输入经纬度
            pPoint.PutCoords(dL, dB);
            pPoint.SpatialReference = spatialReference;
            pointCollection.AddPoint(pPoint, ref _missing, ref _missing);
            pFeaturePoint.Shape = pointCollection as IGeometry;
            //设置属性值
            pFeaturePoint.set_Value(3, dZJ);
            pFeaturePoint.set_Value(5, time + "," + textBoxLevel.Text);
            fwritePoint.WriteFeature(pFeaturePoint);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaturePoint);

            pFeaturePoint = null;
            pWorkspaceEdit.StopEditOperation();
            pWorkspaceEdit.StopEditing(true);
            this.Hide();
            MessageBox.Show("操作成功!", "提示");
        }
Exemple #9
0
        public void featureClassWrite(IFeatureClass sourceFeatureClass, IFeatureClass targetFeatureClass)
        {
            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.WhereClause = queryClause;
            IFeatureCursor     cursor            = sourceFeatureClass.Search(queryFilter, true);
            IFeature           sourceFeature     = cursor.NextFeature();
            IFeatureClassWrite featureClassWrite = targetFeatureClass as IFeatureClassWrite;
            ISet setAdd = new SetClass();

            while (sourceFeature != null)
            {
                IFeature targetFeature = targetFeatureClass.CreateFeature();

                //如果是线或面要素类需要执行下Simplify,这里用的点要素类,不做验证了
                targetFeature.Shape = sourceFeature.ShapeCopy;

                for (int i = 0; i < sourceFeature.Fields.FieldCount; i++)
                {
                    IField field = sourceFeature.Fields.get_Field(i);
                    if (field.Type != esriFieldType.esriFieldTypeOID && field.Type != esriFieldType.esriFieldTypeGeometry && field.Type != esriFieldType.esriFieldTypeGlobalID && field.Type != esriFieldType.esriFieldTypeGUID)
                    {
                        string fieldName = field.Name;
                        int    index     = targetFeature.Fields.FindField(fieldName);
                        if (index > -1 && fieldName != "Shape_Length" && fieldName != "Shape_Area")
                        {
                            targetFeature.set_Value(index, sourceFeature.get_Value(i));
                        }
                    }
                }
                //setAdd.Add(targetFeature);
                featureClassWrite.WriteFeature(targetFeature);
                sourceFeature = cursor.NextFeature();
            }
            //featureClassWrite.WriteFeatures(setAdd);//与WriteFeature没啥效率上的区别
            ComReleaser.ReleaseCOMObject(cursor);

            IFeatureClassManage targetFeatureClassManage = targetFeatureClass as IFeatureClassManage;

            targetFeatureClassManage.UpdateExtent();
        }
Exemple #10
0
        public void AddLineByWrite(AxMapControl axMapControl1, IFeatureLayer l, double x, double y)
        {
            ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType;
            if (featype == esriGeometryType.esriGeometryPolyline)//判断层是否为线层
            {
                //IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer;
                IFeatureClass      fc = l.FeatureClass;
                IFeatureClassWrite fr = fc as IFeatureClassWrite;
                IWorkspaceEdit     w  = (fc as IDataset).Workspace as IWorkspaceEdit;
                IFeature           f;
                //可选参数的设置
                object Missing = Type.Missing;
                IPoint p       = new PointClass();
                w.StartEditing(true);
                w.StartEditOperation();

                f = fc.CreateFeature();
                //定义一个多义线对象
                IRgbColor color = new RgbColor();
                // 设置颜色属性
                color.Red          = 255;
                color.Transparency = 255;

                //ISimpleLineSymbol PlyLine = new SimpleLineSymbolClass();
                //PlyLine.Color = color;
                //PlyLine.Style = esriSimpleLineStyle.esriSLSInsideFrame;
                //PlyLine.Width = 1;

                IGeometry iGeom = axMapControl1.TrackLine();

                AddLine(axMapControl1, iGeom);

                f.Shape = iGeom;
                fr.WriteFeature(f);
                w.StopEditOperation();
                w.StopEditing(true);
            }
        }
Exemple #11
0
        /// <summary>
        /// 创建等高线*.shp文件的主方法
        /// </summary>
        /// <param name="lux">左上投影x坐标</param>
        /// <param name="luy">左上投影y坐标</param>
        /// <param name="luz">左上投影z坐标</param>
        /// <param name="rlx">右下投影x坐标</param>
        /// <param name="rly">右下投影y坐标</param>
        /// <param name="rlz">右下投影z坐标</param>
        /// <param name="m_interval">采样间隔</param>
        /// <returns>等高线*.shp文件的文件名</returns>
        public string CreateContourShape(ISGWorld61 sgworld, double lux, double luy, double luz, double rlx, double rly, double rlz, double m_interval)
        {
            double width = sgworld.CoordServices.GetDistance(lux, luy, rlx, luy);
            double hight = sgworld.CoordServices.GetDistance(lux, luy, lux, rly);

            if (width < 5 || hight < 10)
            {
                MessageBox.Show("范围过小!", "SUNZ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(null);
            }
            if ((width / 1000) * (hight / 1000) > 40)
            {
                if (MessageBox.Show("范围超出40平分公里,系统计算时间比较长,是否继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                }
                else
                {
                    return(null);
                }
            }
            this.Interval = m_interval;
            this.Random   = System.Guid.NewGuid().ToString().Substring(0, 6).ToLower();
            CopyFolder(Application.StartupPath + "\\Convert\\TemPoints", Application.StartupPath + "\\Convert\\PointsResult\\" + this.Random);
            IWorkspaceFactory  pWorkspaceFactory = new ShapefileWorkspaceFactory();
            IWorkspace         pWorkspace        = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\Convert\\PointsResult\\" + this.Random, 0);
            IFeatureWorkspace  pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
            IFeatureClass      pFeatureClass     = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(Application.StartupPath + "\\Convert\\PointsResult\\" + Random + "\\TemPointLayer.shp"));
            IFeatureClassWrite fr = (IFeatureClassWrite)pFeatureClass;
            IWorkspaceEdit     w  = (pFeatureClass as IDataset).Workspace as IWorkspaceEdit;
            IFeature           f;

            w.StartEditing(true);
            w.StartEditOperation();
            int EastPointCount = (int)(width / 5);
            int NothPointCount = (int)(hight / 5);

            for (int j = 0; j < NothPointCount; j++)
            {
                ESRI.ArcGIS.Geometry.IPoint p;
                p = new ESRI.ArcGIS.Geometry.PointClass();
                ESRI.ArcGIS.Geometry.IZAware iz = p as ESRI.ArcGIS.Geometry.IZAware;
                iz.ZAware = true;
                p.X       = lux;
                p.Y       = luy;
                p.Z       = luz;

                ESRI.ArcGIS.Geometry.IGeometry peo;
                peo     = p;
                f       = pFeatureClass.CreateFeature();
                f.Shape = peo;
                f.set_Value(3, p.Z);
                f.Store();
                fr.WriteFeature(f);

                for (int i = 0; i < EastPointCount; i++)
                {
                    IPosition61 positionLU = null;
                    ICoord2D    pPoint     = null;
                    if ((j + 2) % 2 == 0)
                    {
                        pPoint = sgworld.CoordServices.MoveCoord(lux, luy, 5, 0);
                    }
                    else
                    {
                        pPoint = sgworld.CoordServices.MoveCoord(lux, luy, -5, 0);
                    }

                    IWorldPointInfo61 pW = sgworld.Terrain.GetGroundHeightInfo(pPoint.X, pPoint.Y, AccuracyLevel.ACCURACY_BEST_FROM_MEMORY, true);
                    positionLU = pW.Position;
                    luz        = positionLU.Altitude;
                    lux        = positionLU.X;
                    luy        = positionLU.Y;
                    p          = new ESRI.ArcGIS.Geometry.PointClass();
                    iz         = p as ESRI.ArcGIS.Geometry.IZAware;
                    iz.ZAware  = true;
                    p.X        = lux;
                    p.Y        = luy;
                    p.Z        = luz;
                    peo        = p;
                    f          = pFeatureClass.CreateFeature();
                    f.Shape    = peo;
                    f.set_Value(3, p.Z);
                    f.Store();
                    fr.WriteFeature(f);
                }
                ICoord2D          pPointL = sgworld.CoordServices.MoveCoord(lux, luy, 0, -5);
                IWorldPointInfo61 pWL     = sgworld.Terrain.GetGroundHeightInfo(pPointL.X, pPointL.Y, AccuracyLevel.ACCURACY_FORCE_BEST_RENDERED, true);
                luz = pWL.Position.Altitude;
                lux = pWL.Position.X;
                luy = pWL.Position.Y;
            }
            w.StopEditOperation();
            w.StopEditing(true);
            CreateTinFromFeature(pFeatureClass);
            return(this.Random);
        }
Exemple #12
0
        /// <summary>
        /// 对指定图层的指定图形,修改其属性值
        /// </summary>
        /// <param name="id">图形的id</param>
        /// <param name="values">字段属性,key为字段名,value为字段值</param>
        /// <param name="layerName">图层名</param>
        public void UpdateFeature(int id, Dictionary <string, string> values, string layerName)
        {
            InitLicense();
            try
            {
                List <FieldInfo> list = GetAllFields(layerName);

                var node = configXml.SelectSingleNode("/Layers/Layer[@Title='" + layerName + "']");

                var            ws   = CreateWorkspace();
                IWorkspaceEdit edit = (IWorkspaceEdit)ws;
                edit.StartEditing(false);
                edit.StartEditOperation();
                var fc                 = ws.OpenFeatureClass(node.Attributes["Name"].Value);
                var feature            = fc.GetFeature(id);
                IFeatureClassWrite fcw = fc as IFeatureClassWrite;
                if (feature != null)
                {
                    foreach (var item in list)
                    {
                        if (values.ContainsKey(item.Name))
                        {
                            var index = feature.Fields.FindField(item.Name);
                            if (index > -1)
                            {
                                var fld   = feature.Fields.get_Field(index);
                                var value = values[item.Name];
                                switch (fld.Type)
                                {
                                case esriFieldType.esriFieldTypeDate:
                                    DateTime dt;
                                    if (DateTime.TryParse(value, out dt))
                                    {
                                        feature.set_Value(index, dt);
                                    }
                                    break;

                                case esriFieldType.esriFieldTypeDouble:
                                    double db;
                                    if (double.TryParse(value, out db))
                                    {
                                        feature.set_Value(index, db);
                                    }
                                    break;

                                case esriFieldType.esriFieldTypeInteger:
                                case esriFieldType.esriFieldTypeSmallInteger:
                                    int i;
                                    if (int.TryParse(value, out i))
                                    {
                                        feature.set_Value(index, i);
                                    }
                                    break;

                                case esriFieldType.esriFieldTypeSingle:
                                    float f;
                                    if (float.TryParse(value, out f))
                                    {
                                        feature.set_Value(index, f);
                                    }
                                    break;

                                case esriFieldType.esriFieldTypeString:
                                    feature.set_Value(index, value);
                                    break;

                                default:
                                    throw new NotSupportedException(string.Format("不支持此类型的字段({0}):{1}", layerName, fld.Type));
                                }
                            }
                        }
                    }
                    fcw.WriteFeature(feature);
                }
                edit.StopEditOperation();
                edit.StopEditing(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ShutdownLicense();
            }
        }
Exemple #13
0
        public void creatLine(AxMapControl axMapControl1, string dataFile, IPoint pPointCen, IEnvelope iBound)
        {
            //开启编辑状态
            IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(dataFile, 0) as IFeatureWorkspace;
            IWorkspaceEdit    pWorkspaceEdit    = pFeatureWorkspace as IWorkspaceEdit;

            pWorkspaceEdit.StartEditing(false);
            pWorkspaceEdit.StartEditOperation();
            //获取线图层
            IFeatureLayer      pFeatureLayerLine = axMapControl1.Map.get_Layer(5) as IFeatureLayer;
            IFeatureClass      pFeatureClassLine = pFeatureLayerLine.FeatureClass;
            IFeatureClassWrite fwriteLine        = pFeatureClassLine as IFeatureClassWrite;


            //获取地级市数据点,包含两部分:市政府和区县政府
            IFeatureLayer pFeatureLayer1 = null;  //市政府图层

            pFeatureLayer1 = axMapControl1.Map.get_Layer(1) as IFeatureLayer;
            IFeatureClass pFeatureClass1 = pFeatureLayer1.FeatureClass;

            for (int i = 1; i < 15; i++)
            {
                IFeature         pFeature1 = pFeatureClass1.GetFeature(i);
                string           name1     = Convert.ToString(pFeature1.get_Value(3)); //获取地级市名
                IPointCollection pColl1    = pFeature1.Shape as IPointCollection;
                IPoint           pPoint1   = pColl1.get_Point(pColl1.PointCount - 1);
                //判断这个地级市是否在显示范围内
                if (pPoint1.X > iBound.XMin && pPoint1.X < iBound.XMax && pPoint1.Y > iBound.YMin && pPoint1.Y < iBound.YMax)
                {
                    IFeature pFeatureLine = pFeatureClassLine.CreateFeature();
                    //构建新的线要素
                    IPolyline new_line = new PolylineClass();
                    new_line.SpatialReference = pPointCen.SpatialReference;
                    new_line.FromPoint        = pPointCen;
                    new_line.ToPoint          = pPoint1;
                    pFeatureLine.Shape        = new_line;
                    //设置属性值
                    pFeatureLine.set_Value(4, Convert.ToInt32(new_line.Length * 100));
                    pFeatureLine.set_Value(3, name1);
                    fwriteLine.WriteFeature(pFeatureLine);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureLine);
                    pFeatureLine = null;
                }
            }
            IFeatureLayer pFeatureLayer2 = null;  //区县政府图层

            pFeatureLayer2 = axMapControl1.Map.get_Layer(2) as IFeatureLayer;
            IFeatureClass pFeatureClass2 = pFeatureLayer2.FeatureClass;
            //获取属性值
            IFields pFields2 = pFeatureClass2.Fields;

            for (int i = 1; i < 51; i++)
            {
                IFeature         pFeature2 = pFeatureClass2.GetFeature(i);
                string           name2     = Convert.ToString(pFeature2.get_Value(4)); //获取地级市名
                IPointCollection pColl2    = pFeature2.Shape as IPointCollection;
                IPoint           pPoint2   = pColl2.get_Point(pColl2.PointCount - 1);
                //判断这个地级市是否在显示范围内
                if (pPoint2.X > iBound.XMin && pPoint2.X < iBound.XMax && pPoint2.Y > iBound.YMin && pPoint2.Y < iBound.YMax)
                {
                    IFeature pFeatureLine = pFeatureClassLine.CreateFeature();
                    //构建新的线要素
                    IPolyline new_line = new PolylineClass();
                    new_line.SpatialReference = pPointCen.SpatialReference;
                    new_line.FromPoint        = pPointCen;
                    new_line.ToPoint          = pPoint2;
                    pFeatureLine.Shape        = new_line;
                    //设置属性值
                    pFeatureLine.set_Value(4, Convert.ToInt32(new_line.Length * 100));
                    pFeatureLine.set_Value(3, name2);
                    fwriteLine.WriteFeature(pFeatureLine);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureLine);
                    pFeatureLine = null;
                }
            }
            pWorkspaceEdit.StopEditOperation();
            pWorkspaceEdit.StopEditing(true);
        }
        void axMapControl_main_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            // c. 在地图上点击,选择一个监测站点,并显示该监测站点的属性信息 第②步
            #region ...
            if (e.button == 1 && m_isIdentify)
            {
                IEnvelope pClickEnv = new EnvelopeClass()
                {
                    XMin = e.mapX - 0.01,
                    YMin = e.mapY - 0.01,
                    XMax = e.mapX + 0.01,
                    YMax = e.mapY + 0.01
                };
                IFeatureLayer  pFeatureLayer  = AeUtils.GetFeatureLayerByName(m_pMapC2.Map, "监测站");
                IFeatureCursor pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false);
                IFeature       pFeature       = pFeatureCursor.NextFeature();
                while (pFeature != null)
                {
                    IEnvelope pTargetEnv = pFeature.Extent;
                    if (pTargetEnv.XMax < pClickEnv.XMax && pTargetEnv.XMin > pClickEnv.XMin &&
                        pTargetEnv.YMax < pClickEnv.YMax && pTargetEnv.YMin > pClickEnv.YMin)
                    {
                        break;
                    }
                    pFeature = pFeatureCursor.NextFeature();
                }
                m_pMapC2.Map.ClearSelection();
                m_pMapC2.Map.SelectFeature(pFeatureLayer, pFeature);
                m_pMapC2.Refresh();
                if (pFeature != null)
                {
                    showInfo(pFeature);
                }
            }
            #endregion
            // d. 在监测站点列表中选择一个监测站点后,在地图上高亮显示,缩放至该监测站点,并显示该监测站点的属性信息 第②步
            #region ...
            if (e.button == 1 && m_isDraw)
            {
                IFeatureLayer pFeatureLayer = AeUtils.GetFeatureLayerByName(m_pMapC2.Map, "监测站");

                IGeometry pGeometry = m_pMapC2.TrackPolygon();
                IElement  pElement  = new PolygonElementClass()
                {
                    Geometry = pGeometry
                };
                IFillShapeElement pFillShapeElement = pElement as IFillShapeElement;
                pFillShapeElement.Symbol = new SimpleFillSymbolClass()
                {
                    Color   = AeUtils.GetRgbColor(0, 0, 0, 0),
                    Outline = new SimpleLineSymbolClass()
                    {
                        Color = AeUtils.GetRgbColor(255, 0, 0),
                        Width = 1
                    }
                };
                IGraphicsContainer pGraphicsContainer = m_pMapC2.Map as IGraphicsContainer;
                pGraphicsContainer.DeleteAllElements();
                pGraphicsContainer.AddElement(pFillShapeElement as IElement, 0);
                m_pMapC2.Refresh(esriViewDrawPhase.esriViewGraphics);


                AeUtils.GetFeatureLayerByName(m_pMapC2.Map, "北京区县界").Selectable = false;

                m_pMapC2.Map.SelectByShape(pGeometry, null, false);
                m_pMapC2.Refresh(esriViewDrawPhase.esriViewGeoSelection);
                MessageBox.Show(String.Format("当前已选中{0}个监测站", m_pMapC2.Map.SelectionCount));
            }
            #endregion
            // j. 在监测站点图层添加一个新站点
            #region ...
            if (e.button == 1 && m_isAddpoint)
            {
                IFeatureLayer pFeatureLayer = AeUtils.GetFeatureLayerByName(m_pMapC2.Map, "监测站");
                IPoint        pPoint        = new PointClass()
                {
                    X = e.mapX,
                    Y = e.mapY,
                    SpatialReference = m_pMapC2.SpatialReference
                };
                IFeatureClassWrite pWrite = pFeatureLayer.FeatureClass as IFeatureClassWrite;
                IWorkspaceEdit     pEdit  = (pFeatureLayer.FeatureClass as IDataset).Workspace as IWorkspaceEdit;
                pEdit.StartEditing(true);
                pEdit.StartEditOperation();
                IFeature pFeature = pFeatureLayer.FeatureClass.CreateFeature();
                pFeature.Shape = pPoint;
                FormSetName formSetName = new FormSetName();
                formSetName.ShowDialog();
                pFeature.set_Value(pFeatureLayer.FeatureClass.Fields.FindField("Name"), formSetName.name);
                pFeature.Store();
                pWrite.WriteFeature(pFeature);
                pEdit.StopEditOperation();
                pEdit.StopEditing(true);
                m_pMapC2.Refresh();
            }
            #endregion
            if (e.button == 4)
            {
                m_pMapC2.MousePointer = esriControlsMousePointer.esriPointerPanning;
                m_pMapC2.Pan();
                m_pMapC2.MousePointer = esriControlsMousePointer.esriPointerPan;
            }
        }
Exemple #15
0
        //确定键
        private void buttonOK_Click(object sender, EventArgs e)
        {
            double dL = 0.0, dB = 0.0, dZJ = 0.0, dTransAngle = 0.0;
            bool   bL          = double.TryParse(textBoxLong.Text, out dL);            //经度
            bool   bB          = double.TryParse(textBoxLat.Text, out dB);             //纬度
            bool   bZJ         = double.TryParse(textBoxLevel.Text, out dZJ);          //震级
            bool   bTransAngle = double.TryParse(txtTransAngle.Text, out dTransAngle); //旋转角

            time = textBoxTime.Text;

            //开启编辑状态
            IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(dataFile, 0) as IFeatureWorkspace;
            IWorkspaceEdit    pWorkspaceEdit    = pFeatureWorkspace as IWorkspaceEdit;

            pWorkspaceEdit.StartEditing(false);
            pWorkspaceEdit.StartEditOperation();
            //插入震中点数据
            IFeatureClass      pFeatureClassPoint = pFeatureLayerPoint.FeatureClass;
            IFeatureClassWrite fwritePoint        = pFeatureClassPoint as IFeatureClassWrite;
            IFeature           pFeaturePoint      = pFeatureClassPoint.CreateFeature();
            IPointCollection   pointCollection    = new MultipointClass();
            IPoint             pPoint             = new PointClass();
            IGeoDataset        pGeoDataset        = pFeatureClassPoint as IGeoDataset;
            //记录空间投影信息
            ISpatialReference spatialReference = pGeoDataset.SpatialReference;

            //输入经纬度
            pPoint.PutCoords(dL, dB);
            pPoint.SpatialReference = spatialReference;
            pointCollection.AddPoint(pPoint, ref _missing, ref _missing);
            pFeaturePoint.Shape = pointCollection as IGeometry;
            //设置“标注”属性值
            pFeaturePoint.set_Value(3, time);
            fwritePoint.WriteFeature(pFeaturePoint);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaturePoint);
            //记录屏幕显示区域
            IEnvelope pEnvelope = null;

            //生成地震烈度椭圆
            //当都输入值的时候,生成椭圆
            if (bL && bB && bZJ && bTransAngle)
            {
                IGraphicsContainer graphicsContainer = _MainPageLayoutControl.ActiveView.FocusMap as IGraphicsContainer;
                string             sElementName      = "zjEllipticArc";
                DelectElementByName(graphicsContainer, sElementName);
                List <EllipticArcPro> pListEllipticArcPro = CalculatEllipticArc(pPoint, dZJ, dTransAngle);
                int tot    = pListEllipticArcPro.Count;
                int iCount = 1;
                foreach (EllipticArcPro pEllipticArcPro in pListEllipticArcPro)
                {
                    IEllipticArc pEll = new EllipticArcClass();
                    if (tot == 3)
                    {
                        pEll.PutCoordsByAngle(pEllipticArcPro.ellipseStd, pEllipticArcPro.CenterPoint, pEllipticArcPro.FromAngle, pEllipticArcPro.CentralAngle, pEllipticArcPro.rotationAngle, pEllipticArcPro.semiMajor / 100000, pEllipticArcPro.minorMajorRatio);
                    }
                    else
                    {
                        pEll.PutCoordsByAngle(pEllipticArcPro.ellipseStd, pEllipticArcPro.CenterPoint, pEllipticArcPro.FromAngle, pEllipticArcPro.CentralAngle, pEllipticArcPro.rotationAngle, pEllipticArcPro.semiMajor / 100000, pEllipticArcPro.minorMajorRatio);
                    }

                    IGeometry pGeo = EllipticArcTransPolygon(pEll);
                    pGeo.SpatialReference = spatialReference;
                    IPolygon pPloy = pGeo as IPolygon;
                    if (iCount == 1) //第一个烈度图层
                    {
                        IFeatureClass      pFeatureClass8LD = pFeatureLayer8LD.FeatureClass;
                        IFeatureClassWrite fwrite8LD        = pFeatureClass8LD as IFeatureClassWrite;
                        IFeature           pFeature8LD      = pFeatureClass8LD.CreateFeature();
                        pFeature8LD.Shape = pPloy;
                        fwrite8LD.WriteFeature(pFeature8LD);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature8LD);
                        pFeature8LD = null;
                        if (dZJ > 5.3)
                        {
                            iCount++;
                        }
                        //更新显示区域
                        IActiveView pAV = _MainPageLayoutControl.ActiveView.FocusMap as IActiveView;
                        pEnvelope = pPloy.Envelope;
                        pEnvelope.Expand(1.8, 1.8, true);
                        pAV.Extent = pEnvelope;
                        pAV.Refresh();
                    }
                    else if (iCount == 2)
                    {
                        IFeatureClass      pFeatureClass7LD = pFeatureLayer7LD.FeatureClass;
                        IFeatureClassWrite fwrite7LD        = pFeatureClass7LD as IFeatureClassWrite;
                        IFeature           pFeature7LD      = pFeatureClass7LD.CreateFeature();
                        pFeature7LD.Shape = pPloy;
                        fwrite7LD.WriteFeature(pFeature7LD);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature7LD);
                        pFeature7LD = null;
                        if (tot == 3)
                        {
                            iCount++;
                        }
                    }
                    else if (iCount == 3)
                    {
                        IFeatureClass      pFeatureClass6LD = pFeatureLayer6LD.FeatureClass;
                        IFeatureClassWrite fwrite6LD        = pFeatureClass6LD as IFeatureClassWrite;
                        IFeature           pFeature6LD      = pFeatureClass6LD.CreateFeature();
                        pFeature6LD.Shape = pPloy;
                        fwrite6LD.WriteFeature(pFeature6LD);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature6LD);
                        pFeature6LD = null;
                        iCount++;
                    }
                }
            }
            pFeaturePoint = null;
            pWorkspaceEdit.StopEditOperation();
            pWorkspaceEdit.StopEditing(true);
            this.Hide();
            setFormIPoint(pPoint, textBoxLevel.Text, pEnvelope);
            //修改标题
            IElement     pElementTitle     = _MainPageLayoutControl.FindElementByName("Title");
            ITextElement pTextElementTitle = pElementTitle as ITextElement;
            string       sXZQName          = GetXZQName(pPoint);
            string       sText             = sXZQName + "M" + textBoxLevel.Text + "级地震震区水库分布图";

            pTextElementTitle.Text = sText;

            MessageBox.Show("操作成功!", "提示");
        }