예제 #1
0
        public IFeature GetTestFeatures(ConnectionJSObject connObj, FeatureClassJSObject fcObj, FilterWhereJSObject fwObj, out string outMsg)
        {
            IFeature result = null;

            outMsg = string.Empty;
            try
            {
                if (fcObj != null)
                {
                    OpenSDE(connObj);

                    if (pWorkspace != null)
                    {
                        IFeatureClass featureClass = null;
                        //指定表名是否存在
                        if (pWorkspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, fcObj.name))
                        {
                            featureClass = pFeatureWorkspace.OpenFeatureClass(fcObj.name);

                            //查找地块
                            IQueryFilter pQueryFilter = new QueryFilterClass();
                            pQueryFilter.WhereClause = fwObj.filter;
                            IFeatureCursor pFeatureCursor = featureClass.Search(pQueryFilter, false);
                            result = pFeatureCursor.NextFeature();
                        }
                        else
                        {
                            outMsg = string.Format("数据源中不存在表名[{0}]。", fcObj.name);
                        }
                    }
                }
                else
                {
                    outMsg = string.Format("操作表参数错误!");
                }
            }
            catch (Exception ex)
            {
                outMsg = ex.Message;
            }
            finally
            {
                CloseSDE();
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// 删除Features
        /// </summary>
        /// <param name="connObj">连接对象</param>
        /// <param name="fcObj">表对象</param>
        /// <param name="fwObj">查询条件</param>
        /// <param name="outMsg">返回必要信息</param>
        /// <returns></returns>
        public List <FeatureObject> GetFeatures(ConnectionJSObject connObj, FeatureClassJSObject fcObj, FilterWhereJSObject fwObj, out string outMsg)
        {
            List <FeatureObject> result = new List <FeatureObject>();

            outMsg = string.Empty;
            try
            {
                if (fcObj != null)
                {
                    OpenSDE(connObj);

                    if (pWorkspace != null)
                    {
                        IFeatureClass featureClass = null;
                        //指定表名是否存在
                        if (pWorkspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, fcObj.name))
                        {
                            featureClass = pFeatureWorkspace.OpenFeatureClass(fcObj.name);

                            //查找地块
                            IQueryFilter pQueryFilter = new QueryFilterClass();
                            pQueryFilter.WhereClause = fwObj.filter;
                            IFeatureCursor pFeatureCursor = featureClass.Update(pQueryFilter, false);
                            IFeature       feature        = pFeatureCursor.NextFeature();
                            while (feature != null)
                            {
                                //TODO:解析
                                FeatureObject            fo    = new FeatureObject();
                                List <AttributeJSObject> attrs = new List <AttributeJSObject>();

                                for (int i = 0; i < featureClass.Fields.FieldCount; i++)
                                {
                                    IField field = featureClass.Fields.get_Field(i);
                                    if (field != null && field.Editable && field.Type != esriFieldType.esriFieldTypeGeometry)
                                    {
                                        AttributeJSObject ajso = new AttributeJSObject();
                                        ajso.name  = field.Name;
                                        ajso.value = feature.get_Value(i);
                                        attrs.Add(ajso);
                                    }
                                }
                                fo.attributes = attrs;
                                fo.geometry   = feature.ShapeCopy;

                                result.Add(fo);

                                feature = pFeatureCursor.NextFeature();
                            }
                        }
                        else
                        {
                            outMsg = string.Format("数据源中不存在表名[{0}]。", fcObj.name);
                        }
                    }
                }
                else
                {
                    outMsg = string.Format("操作表参数错误!");
                }
            }
            catch (Exception ex)
            {
                outMsg = ex.Message;
            }
            finally
            {
                CloseSDE();
            }

            return(result);
        }
예제 #3
0
        /// <summary>
        /// 删除Features
        /// </summary>
        /// <param name="connObj">连接对象</param>
        /// <param name="fcObj">表对象</param>
        /// <param name="fwObj">删除条件</param>
        /// <param name="count">返回影响行数</param>
        /// <param name="outMsg">返回必要信息</param>
        /// <returns></returns>
        public bool DeleteFeatures(ConnectionJSObject connObj, FeatureClassJSObject fcObj, FilterWhereJSObject fwObj, out int count, out string outMsg)
        {
            bool result = false;

            count  = 0;
            outMsg = string.Empty;
            try
            {
                if (fcObj != null)
                {
                    OpenSDE(connObj);

                    if (pWorkspace != null)
                    {
                        IFeatureClass featureClass = null;
                        //指定表名是否存在
                        if (pWorkspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, fcObj.name))
                        {
                            featureClass = pFeatureWorkspace.OpenFeatureClass(fcObj.name);

                            bool isVersion = CheckVersionEdit(featureClass);
                            if (isVersion)
                            {
                                pWorkspaceEdit.StartEditing(true);
                            }
                            if (isVersion)
                            {
                                pWorkspaceEdit.StartEditOperation();
                            }
                            //查找地块
                            IQueryFilter pQueryFilter = new QueryFilterClass();
                            pQueryFilter.WhereClause = fwObj.filter;
                            IFeatureCursor pFeatureCursor = featureClass.Update(pQueryFilter, false);
                            IFeature       feature        = pFeatureCursor.NextFeature();

                            while (feature != null)
                            {
                                feature.Delete();
                                feature = pFeatureCursor.NextFeature();
                                count++;
                            }

                            if (isVersion)
                            {
                                pWorkspaceEdit.StopEditOperation();
                            }

                            result = true;
                        }
                        else
                        {
                            outMsg = string.Format("数据源中不存在表名[{0}]。", fcObj.name);
                        }
                    }
                }
                else
                {
                    outMsg = string.Format("操作表参数错误!");
                }
            }
            catch (Exception ex)
            {
                result = false;
                outMsg = ex.Message;
            }
            finally
            {
                CloseSDE();
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// 保存Features
        /// </summary>
        /// <param name="connObj">连接对象</param>
        /// <param name="fcObj">表对象</param>
        /// <param name="featureList">几何对象</param>
        /// <param name="count">返回影响行数</param>
        /// <param name="outMsg">返回必要信息</param>
        /// <returns></returns>
        public bool SaveFeatures(ConnectionJSObject connObj, FeatureClassJSObject fcObj, List <FeatureObject> featureList, out int count, out string outMsg)
        {
            bool result = false;

            count  = 0;
            outMsg = string.Empty;
            try
            {
                if (fcObj != null)
                {
                    OpenSDE(connObj);

                    if (pWorkspace != null)
                    {
                        IFeatureClass featureClass = null;
                        //指定表名是否存在
                        if (pWorkspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, fcObj.name))
                        {
                            featureClass = pFeatureWorkspace.OpenFeatureClass(fcObj.name);

                            bool isVersion = CheckVersionEdit(featureClass);
                            if (isVersion)
                            {
                                pWorkspaceEdit.StartEditing(true);
                            }
                            if (isVersion)
                            {
                                pWorkspaceEdit.StartEditOperation();
                            }

                            //解析几何数据
                            foreach (FeatureObject fo in featureList)
                            {
                                IFeature pFeature;
                                if (fo.filterWhere == null || string.IsNullOrEmpty(fo.filterWhere.filter))//没有过滤条件,默认为新增
                                {
                                    pFeature = featureClass.CreateFeature();
                                }
                                else
                                {
                                    //有过滤条件,如果能找到,默认为修改,否则默认为新增,并且默认情况下只修改第一条符合条件的数据,如果有多条,不提示。

                                    //查找地块
                                    IQueryFilter pQueryFilter = new QueryFilterClass();
                                    pQueryFilter.WhereClause = fo.filterWhere.filter;
                                    IFeatureCursor pFeatureCursor = featureClass.Update(pQueryFilter, false);

                                    pFeature = pFeatureCursor.NextFeature();
                                }


                                if (pFeature != null)
                                {
                                    pFeature.Shape = fo.geometry;

                                    foreach (AttributeJSObject aObj in fo.attributes)
                                    {
                                        int index = featureClass.Fields.FindField(aObj.name);
                                        if (index != -1)
                                        {
                                            IField f = featureClass.Fields.get_Field(index);
                                            if (f.Editable)
                                            {
                                                pFeature.set_Value(index, aObj.value);
                                            }
                                        }
                                    }

                                    //保存
                                    pFeature.Store();
                                    count++;
                                }
                            }

                            if (isVersion)
                            {
                                pWorkspaceEdit.StopEditOperation();
                            }

                            result = true;
                        }
                        else
                        {
                            outMsg = string.Format("数据源中不存在表名[{0}]。", fcObj.name);
                        }
                    }
                }
                else
                {
                    outMsg = string.Format("操作表参数错误!");
                }
            }
            catch (Exception ex)
            {
                result = false;
                outMsg = ex.Message;
            }
            finally
            {
                CloseSDE();
            }

            return(result);
        }