예제 #1
0
        //<CSCM>
        //********************************************************************************
        //** 函 数 名: GetCursorByFieldAndValue
        //** 版    权: CopyRight (C)
        //** 创 建 人: 杨旭斌
        //** 功能描述: 通过某字段的值获得与该字段对应的要素,比如通过图幅号获得某个图幅,
        //             该函数返回一个光标,用户从光标中取需要的要素,如果是多个字段,则调用 GetFeatCursor 即可
        //** 创建日期:
        //** 修 改 人:
        //** 修改日期:
        //** 修改时间: 20070817
        //** 参数列表: sValue (String)
        //         sFieldName (String)
        //         sFieldNameLeftgBrace (String)
        //         sFieldNameRightBrace (String)
        //         pFeatCls (IFeatureClass)
        //** 版    本:1.0
        //*********************************************************************************
        //</CSCM>
        public static IFeatureCursor GetCursorByFieldAndValue(string sValue, string sFieldName, ref IFeatureClass pFeatCls, bool bIsOID)
        {
            //bIsOID = false;

            IFeatureCursor functionReturnValue = default(IFeatureCursor);
            IQueryFilter   pQueryFilter        = default(IQueryFilter);
            IFeatureCursor pFeatCursor         = default(IFeatureCursor);
            string         sSQL        = null;
            string         sOIDName    = null;
            int            lFieldIndex = 0;
            IField         pField      = default(IField);

            // ERROR: Not supported in C#: OnErrorStatement
            try
            {
                if (bIsOID == true)
                {
                    sOIDName = pFeatCls.OIDFieldName;
                    sSQL     = sOIDName + "=" + sValue;
                }
                else
                {
                    lFieldIndex = pFeatCls.Fields.FindField(sFieldName);
                    pField      = pFeatCls.Fields.get_Field(lFieldIndex);
                    if (pField.Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString)
                    {
                        sSQL = sFieldName + "='" + sValue + "'";
                    }
                    else if ((int)pField.Type < 4 | (int)pField.Type == 6)
                    {
                        sSQL = sFieldName + "=" + sValue;
                    }
                    else
                    {
                        functionReturnValue = null;
                        return(functionReturnValue);
                    }
                }
                pQueryFilter             = new ESRI.ArcGIS.Geodatabase.QueryFilter();
                pQueryFilter.WhereClause = sSQL;
                pFeatCursor         = pFeatCls.Search(pQueryFilter, false);
                functionReturnValue = pFeatCursor;
                return(functionReturnValue);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                if (ex.ErrorCode == -2147216117)
                {
                    MessageBoxEx.Show("失去了与SDE服务器的连接,提取失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }
                functionReturnValue = null;
                return(functionReturnValue);
            }
        }
예제 #2
0
        public static double DefaultIndexGrid(ref ESRI.ArcGIS.Geodatabase.IFeatureClass InFC)
        {
            int lngNumFeat;
            int lngSampleSize;

            ESRI.ArcGIS.Geodatabase.IFields pFields;
            ESRI.ArcGIS.Geodatabase.IField  pField;
            string strFIDName;
            string strWhereClause;

            //int lngCurrFID;
            ESRI.ArcGIS.Geodatabase.IFeature       pFeat;
            ESRI.ArcGIS.Geodatabase.IFeatureCursor pFeatCursor;
            ESRI.ArcGIS.Geometry.IEnvelope         pFeatEnv;
            ESRI.ArcGIS.Geodatabase.IQueryFilter   pQueryFilter;
            List <int> pNewCol = new List <int>();
            int        lngKMax;
            double     dblMaxDelta;

            dblMaxDelta = 0;
            double dblMinDelta;

            dblMinDelta = 1000000000000;
            double dblSquareness;

            dblSquareness = 1;
            const short SampleSize = 1;
            const short Factor     = 1;

            object[] ColInfo = new object[1];
            object[] c0      = new object[4];
            c0[0]      = "minext";
            c0[1]      = System.Convert.ToInt16(5);
            c0[2]      = System.Convert.ToInt16(-1);
            c0[3]      = false;
            ColInfo[0] = c0;
            lngNumFeat = InFC.FeatureCount(null) - 1;
            if (lngNumFeat <= 0)
            {
                return(1000);
            }
            if (InFC.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint | InFC.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
            {
                return(DefaultIndexGridPoint(ref InFC));
            }
            lngSampleSize = lngNumFeat * SampleSize;
            if (lngSampleSize > 1000)
            {
                lngSampleSize = 1000;
            }
            pFields = InFC.Fields;
            // GET the OBJECTID field
            pField = pFields.get_Field(0);
            for (int m = 0; m < pFields.FieldCount; m++)
            {
                if (pFields.get_Field(m).Name == InFC.OIDFieldName)
                {
                    pField = pFields.get_Field(m);
                    break;
                }
            }

            strFIDName = pField.Name;
            for (int i = 1; i <= lngNumFeat; i += System.Convert.ToInt32(lngNumFeat / lngSampleSize))
            {
                pNewCol.Add(i);
            }
            for (int j = 0; j <= pNewCol.Count - 1; j += 250)
            {
                lngKMax        = Min(pNewCol.Count - j, 250);
                strWhereClause = strFIDName + " IN(";
                for (int k = 0; k < lngKMax; k++)
                {
                    strWhereClause = strWhereClause + System.Convert.ToString(pNewCol[(j + k)]) + ",";
                }
                //strWhereClause = Mid(strWhereClause, 1, strWhereClause.Length - 1) + ")";
                strWhereClause           = strWhereClause.Substring(0, strWhereClause.Length - 1) + ")";
                pQueryFilter             = new ESRI.ArcGIS.Geodatabase.QueryFilter();
                pQueryFilter.WhereClause = strWhereClause;
                pFeatCursor = InFC.Search(pQueryFilter, true);
                pFeat       = pFeatCursor.NextFeature();
                while (!(pFeat == null))
                {
                    pFeatEnv = pFeat.Extent;
                    if (!pFeatEnv.IsEmpty)
                    {
                        dblMaxDelta = Max(dblMaxDelta, Max((pFeatEnv.Width), (pFeatEnv.Height)));
                        dblMinDelta = Min(dblMinDelta, Min((pFeatEnv.Width), (pFeatEnv.Height)));
                        if (dblMinDelta != 0)
                        {
                            dblSquareness = dblSquareness + ((Min((pFeatEnv.Width), (pFeatEnv.Height)) / (Max((pFeatEnv.Width), (pFeatEnv.Height)))));
                        }
                        else
                        {
                            dblSquareness = dblSquareness + 0.0001;
                        }
                    }
                    pFeat = pFeatCursor.NextFeature();
                }
            }
            if (((dblSquareness / lngSampleSize) > 0.5))
            {
                return((dblMinDelta + ((dblMaxDelta - dblMinDelta) / 2)) * Factor);
            }
            else
            {
                return((dblMaxDelta / 2) * Factor);
            }
        }