首页 / 浏览问题 / 组件GIS / 问题详情
组件开发属性转点
102EXP 2018年03月22日
您好,组件开发时属性转二维点用哪个函数实现?

1个回答

您好,这个首先从属性读取坐标信息(经纬度信息X,Y),然后直接用点对象的构造函数GeoPoint 构造函数 (Double, Double)来传入X,Y的坐标,构造点对象,如果你需要把点加进数据集,可以创建一个类型是Point的Datasetvector,然后获取它的Recordset,使用Recordset.Addnew方法即可将点对象加进点数据集。
5,985EXP 2018年03月22日
您这种思路只是构建了点图层或者点矢量数据集,那么怎么把Excel中的其它属性赋给该点图层或者矢量数据集呢?
用addnew的第二个重载方法,需要注意的是,使用该方法需要先给数据集建好对应的字段。
dvTable = datasource.Datasets["HS_POINT_HS_POINT"] as DatasetVector;

            //创建点数据集,Dataset强制转换为了DatasetVector
            DatasetVector dvPoint = (DatasetVector)this.createDataset("Point2D", DatasetType.Point, datasource);

            //属性信息
            Recordset recordsetPoint = dvPoint.GetRecordset(false, CursorType.Dynamic);//三维点的属性

            //Recordset recordsetTable = dvTable.Query("SmID==2", CursorType.Static);//属相表的属性
            Recordset recordsetTable = dvTable.GetRecordset(false, CursorType.Static);//属相表的属性

 

 if (dvPoint == null)
            {
                MessageBox.Show("创建数据集失败");
                return;
            }
            else
            {
                ////创建文本字段
                FieldInfos fieldInfos = dvTable.FieldInfos;
                foreach (FieldInfo fieldInfo in fieldInfos)
                {
                    //排除自动生成的字段
                    if (!fieldInfo.Name.ToString().Contains("Sm"))
                    {
                        FieldInfo tempfieldInfo = new FieldInfo(fieldInfo.Name, fieldInfo.Type);
                        tempfieldInfo.MaxLength = fieldInfo.MaxLength;
                        dvPoint.FieldInfos.Add(tempfieldInfo);
                    }
                }
            }

            Recordset.BatchEditor editor = recordsetPoint.Batch;
            editor.MaxRecordCount = 50;
            editor.Begin();
            recordsetPoint.MoveFirst();
            recordsetTable.MoveFirst();

        
            //判断当前记录的位置是否在记录集中的最后一条记录的后面,如果是,返回Ture,否则返回false。
            while (!recordsetTable.IsEOF)
            {
                recordsetPoint.Edit();
                //object[] ob = recordsetTable.GetValues();
                Dictionary<int, Feature> dic = recordsetTable.GetAllFeatures();
                //TODO:遍历字典,然后在循环中新建点
                foreach (Feature pFeature in dic.Values)
                {
               

                    Dictionary<string, object> values = new Dictionary<string, object>();
                    foreach (FieldInfo fieldInfo in recordsetTable.GetFieldInfos())
                    {
                        string fieldInfoName = fieldInfo.Name.ToString();
                        if (!fieldInfoName.Contains("Sm"))
                        {

                            if (pFeature.GetValue(fieldInfoName) != null)
                            {
                                if (!values.ContainsKey(fieldInfoName))
                                {
                                    values.Add(fieldInfoName, pFeature.GetValue(fieldInfoName));
                                }
                                //recordsetPoint.SetFieldValue(fieldInfoName, pFeature.GetValue(fieldInfoName));
                            }

                        }
                    }

                    Point2D point2D = new Point2D();
                    //point2D.X = pFeature.GetDouble("X");
                    //point2D.Y = pFeature.GetDouble("Y");
                    point2D.X = recordsetTable.GetDouble("X");
                    point2D.Y = recordsetTable.GetDouble("Y");
                    GeoPoint geoPoint2D = new GeoPoint(point2D);
                    //recordsetPoint.AddNew(geoPoint2D, values);
                    recordsetPoint.AddNew(geoPoint2D);
                    //dvPoint.Append(recordsetTable);
                    recordsetPoint.Update();
                   
                    //recordsetPoint.MoveNext();
                }

                recordsetTable.MoveNext();
            }
            editor.Update();
            recordsetPoint.Close();
            recordsetTable.Close();

我的思路是先把Excel属性表读取成DataVector类型,然后遍历其字段信息并在新建的二维点图层中新建对应的字段;然后遍历其每一条记录的x和y坐标,生成二维点,然后把其它属性信息放到values字典中,现在用AddNew的两个重载方法都只能生成二位点,不能把存入values字典中的其它字段信息加进去,请问是什么问题呢?

如果你用AddNew的第二个方法完成了,能否发给我一份demo?我的邮箱是571716604@qq.com。
...