Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }